torchfix
torchfix copied to clipboard
Use torch.*_like()
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?
https://github.com/threestudio-project/threestudio/blob/main/threestudio/models/background/solid_color_background.py#L37-L39