pytorch-labs/torchfix

Use torch.*_like()

adsharma opened this issue · 2 comments

b = torch.zeros_like(a)

should be preferred over

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

to avoid copies.

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?