Repository navigation
fix: update on complete gradient accumulation boundaries - #316
Open
Liuchenbing-2026 wants to merge 1 commit into
Open
Liuchenbing-2026 wants to merge 1 commit into
Liuchenbing-2026 wants to merge 1 commit into
Conversation
Contributor
Author
|
@tastelikefeet could you please review this focused gradient-accumulation fix? The same five regressions fail three cases on current main and pass all five on this head. They call the actual Transformers backward/step/zero_grad core methods with real CPU autograd and AdamW, checking accumulation 1/2/4 against complete batches at 1e-12 tolerance. The final published files were verified byte-for-byte against the rerun snapshot. Commands and validation limits are in the description. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
With gradient accumulation set to 4, Transformers backward increments the micro-step counter before checking the boundary, but the shared predicate tests
(cur_step - 1) % 4. The first optimizer update therefore occurs at micro-step 5 rather than 4, and eight micro-batches produce only one update rather than two.Check the completed positive step count directly. Add a numerical regression calling the real Transformers backward, optimizer step and zero-grad core methods, with a small local wrapper fixture and real PyTorch autograd/AdamW. It checks accumulation factors 1, 2 and 4 against complete-batch updates, continuation of the counter and unchanged single-step behavior. RPC dispatch and distributed training are outside this test.
AI assistance was used for implementation and testing.
Experiment results
Compared the same tests on main
9953ea1ebbbdbe59c3831702157d3c147ca0ee26and the fixed implementation:The baseline failures are incorrect update boundaries for accumulation 2/4 and continuation to the next complete boundary. Fixed parameters match the full-batch reference at
rtol=atol=1e-12in float64.All pre-commit hooks passed; the test file also passed manual isort/yapf/flake8 checks because repository hooks exclude tests. Environment: Linux/aarch64, Python 3.12.13, Torch 2.10.0, CPU tensors only. This rerun does not claim NPU throughput, full-model quality or multi-rank acceptance.