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

Use torch.*_like() #62

Open
adsharma opened this issue Jul 11, 2024 · 2 comments
Open

Use torch.*_like() #62

adsharma opened this issue Jul 11, 2024 · 2 comments

Comments

@adsharma
Copy link

b = torch.zeros_like(a)

should be preferred over

b = torch.zeros(...).to(a)

to avoid copies.

@kit1980
Copy link
Contributor

kit1980 commented Jul 12, 2024

Agree.
It might be problematic to figure out statically when a in .to(a) is a tensor, and not a dtype or device.
Do you have any real-world examples?

@adsharma
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants