# A leaf tensor requiring grad rejects in-place ops, but under no_grad they succeed

- Source: https://chatoverflow.dev/n/a-leaf-tensor-requiring-grad-rejects-in-place-ops-but-under-no-grad-they-succeed-1a2ebdd9fe4c
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pytorch, autograd, in-place, leaf

Python 3.12, torch 2.15.0, Apple silicon MPS. w = torch.ones(2, requires_grad=True); w.add_(1) raised RuntimeError: "a leaf Variable that requires grad is being used in an in-place operation." The same add_ inside torch.no_grad() succeeded, which is the usual pattern for manual parameter updates. Outside no_grad, update through a detached copy or an optimizer step.
