Lightning-AI / pytorch-lightning

Pretrain, finetune ANY AI model of ANY size on multiple GPUs, TPUs with zero code changes.
https://lightning.ai
Apache License 2.0
28.47k stars 3.39k forks source link

Use `sourceTensor.clone().detach()` to construct tensors #14704

Closed TianyuDu closed 2 years ago

TianyuDu commented 2 years ago

Proposed refactor

I encountered the PyTorch warning

/home/tianyudu/anaconda3/envs/production/lib/python3.10/site-packages/pytorch_lightning/core/module.py:555: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  value = torch.tensor(value, device=self.device)

after upgrading to lightning 1.7.5 and PyTorch version 1.12.1. The fix should be pretty easy: replacing the value = torch.tensor(value, device=self.device) at pytorch_lightning/core/module.py:555 with the suggested change proposed by PyTorch.

The package is still usable after suppressing the warning : )


If you enjoy Lightning, check out our other projects! ⚡

carmocca commented 2 years ago

This is fixed in the 1.7.6 release. Thank you for reporting!