File: leanpass/tensor.py
The backward method adds the supplied gradient to any existing self.grad and never clears intermediate node gradients before a new backward pass. This leads to unintended gradient accumulation when backward is called multiple times without an explicit zero_grad. The method should reset self.grad (and optionally all ancestors' grads) at the start of the backward pass, mirroring the behavior of frameworks like PyTorch.
Filed automatically by ai-issue-scan.
File:
leanpass/tensor.pyThe
backwardmethod adds the supplied gradient to any existingself.gradand never clears intermediate node gradients before a new backward pass. This leads to unintended gradient accumulation whenbackwardis called multiple times without an explicitzero_grad. The method should resetself.grad(and optionally all ancestors' grads) at the start of the backward pass, mirroring the behavior of frameworks like PyTorch.Filed automatically by ai-issue-scan.