Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qa/L0_pytorch_unittest/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ NVTE_FLASH_ATTN=0 NVTE_CPU_OFFLOAD_V1=1 python3 -m pytest --tb=auto --junitxml=$
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_hybrid_quantization.xml $TE_PATH/tests/pytorch/test_hybrid_quantization.py || test_fail "test_hybrid_quantization.py"
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_identity_quantizer.xml $TE_PATH/tests/pytorch/test_identity_quantizer.py || test_fail "test_identity_quantizer.py"
NVTE_ALLOW_UNSAFE_PICKLE_EXTRA_STATE=1 python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_attention.xml $TE_PATH/tests/pytorch/attention/test_attention.py || test_fail "test_attention.py"
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_softmax_offset_inference.xml $TE_PATH/tests/pytorch/attention/test_softmax_offset_inference.py || test_fail "test_softmax_offset_inference.py"
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_flex_attention.xml $TE_PATH/tests/pytorch/attention/test_flex_attention.py || test_fail "test_flex_attention.py"
NVTE_ALLOW_UNSAFE_PICKLE_EXTRA_STATE=1 NVTE_ALLOW_NONDETERMINISTIC_ALGO=0 python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_attention_deterministic.xml $TE_PATH/tests/pytorch/attention/test_attention.py || test_fail "NVTE_ALLOW_NONDETERMINISTIC_ALGO=0 test_attention.py"
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_linear_mxfp8_attention.xml $TE_PATH/tests/pytorch/attention/test_linear_mxfp8_attention.py || test_fail "test_linear_mxfp8_attention.py"
Expand Down
3 changes: 1 addition & 2 deletions tests/pytorch/attention/run_attention_with_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def run_dpa_with_cp(
torch.cuda.Stream(),
cp_comm_type,
)
if config.softmax_type != "vanilla":
if is_training and config.softmax_type != "vanilla":
core_attn.softmax_offset.grad.zero_()
if dtype == "fp8":
core_attn.fp8_initialized = False
Expand Down Expand Up @@ -690,7 +690,6 @@ def run_dpa_with_cp(
)
else:
out = out.index_select(0, seq_idx_q).contiguous()
out_ = out_

atol, rtol, rmse_tol = get_tols(config, dtype)
tensors_cp = [out_, dq_, dk_, dv_, dbias_, d_softmax_offset_, max_logit_]
Expand Down
22 changes: 22 additions & 0 deletions tests/pytorch/attention/test_softmax_offset_inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

import pytest
import torch
from transformer_engine.pytorch import DotProductAttention
Comment thread
greptile-apps[bot] marked this conversation as resolved.


@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available")
def test_softmax_offset_grad_none_in_eval():
Comment on lines +10 to +11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Regression test omitted from CI

The QA jobs enumerate test files explicitly, but none includes this new test, so CI silently skips the intended inference regression coverage.

Knowledge Base Used: Tests and QA

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

"""Regression test: eval mode leaves softmax_offset.grad as None.

The context-parallel test helper previously crashed here by calling
core_attn.softmax_offset.grad.zero_() unconditionally for non-vanilla
softmax. In eval mode requires_grad is False and no backward has run,
so .grad must stay None.
"""
core_attn = (
DotProductAttention(8, (64, 64), num_gqa_groups=4, softmax_type="learnable").cuda().eval()
)
assert not core_attn.softmax_offset.requires_grad

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Eval assertion fails on CUDA

When this test runs on a CUDA-enabled worker, eval() leaves the registered softmax_offset parameter with requires_grad=True, so this assertion fails before the test can validate that inference leaves its gradient unset.

Suggested change
assert not core_attn.softmax_offset.requires_grad
assert core_attn.softmax_offset.grad is None

Knowledge Base Used: Tests and QA