Skip to content

fix(autograd): accumulate gradients for leaf tensor backward - #275

Open
superme1one wants to merge 1 commit into
InfiniTensor:masterfrom
superme1one:codex/fix-leaf-backward
Open

superme1one wants to merge 1 commit into
InfiniTensor:masterfrom
superme1one:codex/fix-leaf-backward

Conversation

@superme1one

@superme1one superme1one commented Nov 16, 2026 •

Copy link
Copy Markdown

Calling Backward() directly on a leaf tensor with requires_grad=true currently leaves its gradient null. Route the leaf through AccumulateGrad, retaining the existing implicit/explicit gradient validation and accumulation hooks. The fresh accumulator keeps this backward call independent of forward consumers that have already been created from the leaf.

Fixes #272.

Regression coverage includes implicit scalar gradients, repeated explicit vector-gradient accumulation, backward on a leaf with a live forward consumer, and invalid implicit/explicit gradient shapes. The new cases fail against the unmodified master implementation.

Validation on Linux x86_64, CPU Release, Clang 18.1.8/GCC 13.4.0 libstdc++, CMake 3.31.6, with CUDA/NCCL/OpenMP disabled:

The new tests use the existing device-parameterized tensor suite. Runtime validation in this submission was CPU-only.

Upstream CI currently requires maintainer approval before jobs can run; the three successful fork workflow results above use the same workflow definitions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tensor::Backward silently ignores leaf tensors that require gradients

1 participant