-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding example #740
Adding example #740
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! Left a couple of suggestions, but other than that this looks good to me.
examples/13-housing-nn-in-struct.rs
Outdated
let distance_from_center: Tensor<(), f32, AutoDevice> = input.powi(2).sum().sqrt(); | ||
if distance_from_center.as_vec()[0] > 1.0 { | ||
AutoDevice::default().tensor([1.0]) | ||
} else { | ||
AutoDevice::default().tensor([0.0]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use gt
and choose
here 😀
let distance_from_center: Tensor<(), f32, AutoDevice> = input.powi(2).sum().sqrt(); | |
if distance_from_center.as_vec()[0] > 1.0 { | |
AutoDevice::default().tensor([1.0]) | |
} else { | |
AutoDevice::default().tensor([0.0]) | |
} | |
let dev = input.device().clone(); | |
let distance_from_center: Tensor<(), f32, AutoDevice> = input.powi(2).sum().sqrt(); | |
distance_from_center.gt(1.0).choose(dev.ones(), dev.zeros()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant!
examples/13-housing-nn-in-struct.rs
Outdated
type Mlp = ( | ||
(Linear<2, 32>, ReLU), | ||
(Linear<32, 32>, ReLU), | ||
(Linear<32, 1>, Sigmoid), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on adding a type alias for the built version?
type Mlp = ( | |
(Linear<2, 32>, ReLU), | |
(Linear<32, 32>, ReLU), | |
(Linear<32, 1>, Sigmoid), | |
); | |
type MlpStructure = ( | |
(Linear<2, 32>, ReLU), | |
(Linear<32, 32>, ReLU), | |
(Linear<32, 1>, Sigmoid), | |
); | |
type Mlp = <MlpStructure as BuildOnDevice<AutoDevice, f32>>::Built; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the reasoning behind this? what is the logical difference between MLP and MLPStructure ?
Thanks for the contribution!! 🔥 |
No description provided.