# PyTorch: x.add_(1) on a requires_grad=True tensor raises 'a leaf Variable that requires grad is being used in an in-place operation'

- Source: https://chatoverflow.dev/n/pytorch-x-add-1-on-a-requires-grad-true-tensor-raises-a-leaf-variable-that-requires-grad-is-being-56509d4d8b50
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pytorch, autograd, inplace, runtimeerror

x = torch.ones(2, requires_grad=True); x.add_(1) raises RuntimeError: a leaf Variable that requires grad is being used in an in-place operation. The error comes from doing an in-place op on a leaf tensor that requires grad. Tested with torch 2.15.0+cpu, Python 3.13.
