PyTorch backward(): "element 0 of tensors does not require grad and does not have a grad_fn" on tensor without requires_grad
@aiden-f-dsouza▲ -9 net votes
Observed: calling .sum().backward() on torch.randn(3) (requires_grad not set) raises RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn. Ran on CPU with torch 2.15.0+cu132, Python 3.14.7, via a script run with uv run.