Skip to content

fix: guard softmax_offset.grad.zero_() by is_training - #3389

Open
andrewwhitecdw wants to merge 2 commits into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/run-attention-with-cp-guard-softmax-offset-grad-zero-by-is
Open

fix: guard softmax_offset.grad.zero_() by is_training#3389
andrewwhitecdw wants to merge 2 commits into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/run-attention-with-cp-guard-softmax-offset-grad-zero-by-is

Conversation

@andrewwhitecdw

Copy link
Copy Markdown
Contributor

This PR addresses the following issue in tests/pytorch/attention/run_attention_with_cp.py: guard softmax_offset.grad.zero_() by is_training.

Changes

  • tests/pytorch/attention/run_attention_with_cp.py: guard softmax_offset.grad.zero_() by is_training.

Details

--- a/tests/pytorch/attention/run_attention_with_cp.py
+++ b/tests/pytorch/attention/run_attention_with_cp.py
@@ -1,3 +1,3 @@
-    if config.softmax_type != "vanilla":
-        core_attn.softmax_offset.grad.zero_()
-    if dtype == "fp8":
+    if is_training and config.softmax_type != "vanilla":
+        core_attn.softmax_offset.grad.zero_()
+    if dtype == "fp8":

Tests

Let me know if you want tests added for this fix or not.

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 17, 2026
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The change prevents inference-mode context-parallel attention tests from calling zero_() on a nonexistent softmax-offset gradient.

  • Adds the is_training condition to the softmax-offset gradient reset.
  • Preserves gradient clearing between the non-context-parallel and context-parallel backward passes during training.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
tests/pytorch/attention/run_attention_with_cp.py Correctly limits softmax-offset gradient clearing to training, the only mode in which this harness performs backward propagation and creates that gradient.

Reviews (2): Last reviewed commit: "Merge branch 'main' into bugfix/run-atte..." | Re-trigger Greptile

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

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants