Skip to content

Remove dummy weight gradients from fused accumulation - #3759

Open
vthumbe1503 wants to merge 7 commits into
NVIDIA:mainfrom
vthumbe1503:remove-dummy-wgrad-te
Open

vthumbe1503 wants to merge 7 commits into
NVIDIA:mainfrom
vthumbe1503:remove-dummy-wgrad-te

Conversation

@vthumbe1503

@vthumbe1503 vthumbe1503 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Remove dummy weight-gradient tensors from Transformer Engine's fused weight-gradient accumulation path. When the real gradient has been accumulated into main_grad, return None to autograd instead of allocating or reusing an unused dummy. This removes the dummy cache, zero-tensor handling, and extra gradient addition needed by tied embeddings.

This is paired with Megatron-LM #4680, which updates Megatron's gradient hooks and consumers for the None contract. PyTorch 2.6+ runs the accumulator hook on the parameter's device worker thread.

Type of change

  • Code refactoring
  • Bug fix (non-breaking change which fixes an issue)

Changes

  • Return None for fused weight gradients already written to main_grad across linear, grouped linear, fused ops, and distributed-weight paths.
  • Remove the dummy-gradient cache and its test helpers; update CUDA graph and grouped-operation expectations.
  • Preserve distributed-weight finalize behavior when it returns None for a group.

Checklist

  • The functionality is complete
  • I have added or updated tests for the None gradient contract
  • Focused unit and integration tests passed with these changes

This PR is a draft for author review before maintainer review.

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
timmoon10
timmoon10 previously approved these changes Oct 28, 2026

@timmoon10 timmoon10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dummy wgrads were an ugly hack. It'll be really nice getting rid of it all now that we don't need it.

Comment thread tests/pytorch/test_sanity.py Resolved
Track participating parameters with temporary warmup hooks rather than treating every None gradient as an unused parameter. Retain fused-wgrad autograd edges without dummy gradients or a replay wrapper, while excluding unused and frozen parameters.

Cover fused and unfused accumulation, ordered capture, input gradients, shared weights, and repeated replay.

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
vthumbe1503 and others added 2 commits November 30, 2026 11:24
Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
Signed-off-by: vthumbe1503 <vthumbe@nvidia.com>
Merge tested main 8afe7c8 while retaining the None-gradient fused-accumulation contract. Preserve upstream userbuffer validation and delayed-wgrad graph behavior, update BatchedLinear, and align sharded/expert-parallel tests with main_grad accumulation.

Validate on Ptyche GB200 with focused TE and Megatron correctness tests, distributed CUDA-graph checks, tied-embedding DDP, and matched main/Megatron-only/combined GPT, GTP, FSDP and DeepSeek V3 runs. Full CI and long-horizon convergence remain outside this validation.

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
@vthumbe1503
vthumbe1503 marked this pull request as ready for review December 1, 2026 07:44
@vthumbe1503
vthumbe1503 requested a review from ksivaman as a code owner December 1, 2026 07:44
@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The latest changes appear safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge.

Summary

The PR returns None after fused weight gradients are written to main_grad, removing unused dummy tensors.

  • Fused weight gradients leave .grad unset after main_grad is updated.
  • Distributed-weight finalization can leave each parameter's .grad unset.
  • CUDA graph warmup keeps used parameters when their gradients are None.

Reviews (2) · Last reviewed commit: "Remove unused main_grad argument from gr..." · Reviewed by Greptile

Drop the obsolete dummy-gradient argument and stop passing it from the eager and graph-safe backward paths. Resolve pylint W0613 without suppressing the check.

Validate with the full PyTorch Python lint launcher using pylint 4.1.3, Black, and 120 BF16 grouped-linear gradient-accumulation cases in the existing Ptyche build.

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants