Skip to content

Commit 5ae46ce

Browse files
fix: use raise instead of assert for the ONNX+softcap guard
python -O / PYTHONOPTIMIZE strips assert statements, which would silently reopen the ONNX export softcap-drop bug the previous commit fixed (ONNX mode would again force-select UnfusedDotProductAttention with softcap silently omitted, with no error). Switch to an explicit if/raise ValueError, which survives optimized execution. Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5917f0d commit 5ae46ce

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎transformer_engine/pytorch/attention/dot_product_attention/dot_product_attention.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,10 +2044,13 @@ def forward(
20442044
# softcap is not supported by UnfusedDotProductAttention, which is the backend ONNX
20452045
# export unconditionally force-selects further down (bypassing get_attention_backend's
20462046
# softcap-aware filter). Fail loudly rather than silently export a model that omits
2047-
# softcapping.
2048-
assert (
2049-
softcap == 0.0 or not is_in_onnx_export_mode()
2050-
), "Attention logit softcapping (softcap != 0.0) is not supported with ONNX export!"
2047+
# softcapping. Uses an explicit raise (not assert) so the check survives python -O /
2048+
# PYTHONOPTIMIZE, which strips asserts and would otherwise silently re-open this gap.
2049+
if softcap != 0.0 and is_in_onnx_export_mode():
2050+
raise ValueError(
2051+
"Attention logit softcapping (softcap != 0.0) is not supported with "
2052+
"ONNX export!"
2053+
)
20512054

20522055
# Validate experimental Flex Attention API inputs that backend selection
20532056
# cannot represent.

0 commit comments

Comments
 (0)