Lightning-AI / Lightning-AI/pytorch-lightning

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [68]] is at version 3; expected version 2 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

Open
#19,853 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug fabric repro needed ver: 2.2.x waiting on author
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Bug description

Traceback (most recent call last):
File "main_train.py", line 61, in
main(cfg)
File "main_train.py", line 50, in main
trainer.fit()
File "/mnt/inais/data1/syp/wgan/fabric/decalib/trainer.py", line 373, in fit
self.fabric.backward(all_loss)
File "/root/miniconda3/envs/DECA_2/lib/python3.7/site-packages/lightning/fabric/fabric.py", line 359, in backward
self._precision.backward(tensor, module, *args, **kwargs)
File "/root/miniconda3/envs/DECA_2/lib/python3.7/site-packages/lightning/fabric/plugins/precision/precision.py", line 73, in backward
tensor.backward(*args, **kwargs)
File "/root/miniconda3/envs/DECA_2/lib/python3.7/site-packages/torch/_tensor.py", line 396, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "/root/miniconda3/envs/DECA_2/lib/python3.7/site-packages/torch/autograd/__init__.py", line 175, in backward
allow_unreachable=True, accumulate_grad=True) # Calls into the C++ engine to run the backward pass
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [68]] is at version 3; expected version 2 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
I encountered this problem during operation, how should I solve it?

### What version are you seeing the problem on?

master

### How to reproduce the bug

_No response_

### Error messages and logs

```
# Error messages and logs here please
```

### Environment

Current environment

```
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
```

### More info

_No response_

cc @justusschock @lantiga

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the traceback entry points in main_train.py and trainer.py, especially the call to fabric.backward(all_loss). Reproduce the failure with a complete environment and test case, then use PyTorch anomaly detection to identify the in-place operation; the issue needs a confirmed cause and regression coverage before it is done.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.