Skip to content

Tensor.backward accumulates gradients across calls #46

Description

@github-actions

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions