pytorch-labs / torchfix

TorchFix - a linter for PyTorch-using code with autofix support
Other
98 stars 16 forks source link

Use torch.*_like() #62

Open adsharma opened 3 months ago

adsharma commented 3 months ago
b = torch.zeros_like(a)

should be preferred over

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

to avoid copies.

kit1980 commented 3 months ago

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 commented 3 months ago

https://github.com/threestudio-project/threestudio/blob/main/threestudio/models/background/solid_color_background.py#L37-L39