Explicit Gradient Accumulation Control in PyTorch Autograd
TL;DR
PyTorch introduces a new parameter to prevent automatic gradient summation during backpropagation. The disallow_implicit_grad_accumulation flag allows developers to enforce explicit gradient combination for precise accumulation control. When enabled, overlapping gradients trigger clear error messages identifying the conflicting nodes.
Source summary
Previously, implicit gradient summation occurred without visibility into where overlaps happened or how users could manually combine gradients for precision control.
The framework now supports a keyword-only disallow_implicit_grad_accumulation=False argument across Tensor.backward, torch.autograd.backward, and torch.autograd.grad.
Setting this to True causes incoming gradients at occupied node inputs to raise errors rather than auto-summing.
Validation occurs within Engine::evaluate_function, preserving InputBuffer::add behavior.
Errors specify node inputs and producing nodes, with forward tracebacks displayed in anomaly mode.
Existing __torch_function__ overrides remain compatible when the flag is False.