Skip to content

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

Open
andrewwhitecdw wants to merge 1 commit 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 1 commit 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

This PR prevents the context-parallel attention test helper from clearing softmax_offset.grad during inference, where no backward pass populates that gradient.

  • Adds is_training to the non-vanilla softmax gradient-reset condition.
  • Preserves existing training-mode cleanup and FP8 state reset behavior.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable correctness or security issues identified.

The new training guard matches the lifecycle of gradients while preserving cleanup for training runs and leaving subsequent FP8 state handling unchanged.

Important Files Changed

Filename Overview
tests/pytorch/attention/run_attention_with_cp.py Correctly limits softmax-offset gradient clearing to training runs, avoiding access to an absent inference gradient.

Reviews (1): Last reviewed commit: "fix: guard softmax_offset.grad.zero_() b..." | 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.

1 participant