Skip to content
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

Merged
merged 4 commits into from
Apr 28, 2023
Merged

Adding example #740

merged 4 commits into from
Apr 28, 2023

Conversation

sirandreww
Copy link
Contributor

No description provided.

@sirandreww
Copy link
Contributor Author

this is meant to solve:
Model saving in struct requires different type. #727
Get size of tensor #729

Copy link
Owner

@coreylowman coreylowman left a 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.

Comment on lines 125 to 130
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])
}
Copy link
Owner

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 😀

Suggested change
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())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant!

Comment on lines 29 to 33
type Mlp = (
(Linear<2, 32>, ReLU),
(Linear<32, 32>, ReLU),
(Linear<32, 1>, Sigmoid),
);
Copy link
Owner

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?

Suggested change
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;

Copy link
Contributor Author

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 ?

@sirandreww sirandreww requested a review from coreylowman April 28, 2023 09:44
@coreylowman
Copy link
Owner

Thanks for the contribution!! 🔥

@coreylowman coreylowman merged commit 50f7522 into coreylowman:main Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get size of tensor Model saving in struct requires different type.
2 participants