pytorch-labs / torchfix

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

Use torch.*_like() #62

Open adsharma opened 2 months ago

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

should be preferred over

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

to avoid copies.

kit1980 commented 2 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 2 months ago

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