Skip to content

fix: fp8 scaling_mode is not validated before use - #3366

Closed
andrewwhitecdw wants to merge 0 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/run-attention-with-cp-fp8-scaling-mode-is-not-validated
Closed

fix: fp8 scaling_mode is not validated before use#3366
andrewwhitecdw wants to merge 0 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/run-attention-with-cp-fp8-scaling-mode-is-not-validated

Conversation

@andrewwhitecdw

Copy link
Copy Markdown
Contributor

This PR addresses the following issue in tests/pytorch/attention/run_attention_with_cp.py: fp8 scaling_mode is not validated before use.

Changes

  • tests/pytorch/attention/run_attention_with_cp.py: fp8 scaling_mode is not validated before use.

Details

--- a/tests/pytorch/attention/run_attention_with_cp.py
+++ b/tests/pytorch/attention/run_attention_with_cp.py
@@ -1,3 +1,9 @@
-    is_training = is_training == "True"
-
-    # set up environment variables and config
+    is_training = is_training == "True"
+
+    # Validate FP8 scaling mode before any conditional use so that an
+    # unsupported value fails fast with a clear message instead of
+    # leaving fp8_recipe / quantizers undefined.
+    if dtype == "fp8" and scaling_mode not in ("delayed", "current", "mxfp8"):
+        raise ValueError(f"Unsupported scaling_mode for FP8: {scaling_mode!r}")
+
+    # set up environment variables and config

Tests

  • tests/pytorch/attention/test_attention_with_cp_validation.py
--- /dev/null
+++ tests/pytorch/attention/test_attention_with_cp_validation.py
@@ -0,0 +1,9 @@
+import pytest
+
+from run_attention_with_cp import run_dpa_with_cp
+
+
+def test_run_dpa_with_cp_rejects_invalid_fp8_scaling_mode():
+    """An unsupported FP8 scaling mode must raise a clear ValueError."""
+    with pytest.raises(ValueError, match="Unsupported scaling_mode for FP8"):
+        run_dpa_with_cp(dtype="fp8", scaling_mode="unsupported")

@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 13, 2026
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds early validation for FP8 scaling modes in the context-parallel attention test helper.

  • Accepts the three scaling modes already supported by downstream recipe and quantizer branches.
  • Raises a clear ValueError for unsupported FP8 scaling modes before undefined state is used.

Confidence Score: 5/5

The PR appears safe to merge, with the new validation matching the helper’s existing supported scaling modes.

Existing callers and downstream recipe and quantizer branches consistently use only delayed, current, and mxfp8, so the added check prevents invalid state without rejecting a supported configuration.

Important Files Changed

Filename Overview
tests/pytorch/attention/run_attention_with_cp.py Adds fail-fast FP8 scaling-mode validation whose allowlist matches existing callers and downstream implementations.

Reviews (1): Last reviewed commit: "fix: fp8 scaling_mode is not validated b..." | Re-trigger Greptile

# unsupported value fails fast with a clear message instead of
# leaving fp8_recipe / quantizers undefined.
if dtype == "fp8" and scaling_mode not in ("delayed", "current", "mxfp8"):
raise ValueError(f"Unsupported scaling_mode for FP8: {scaling_mode!r}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This path is unreachable in our test infra so the check here is probably unnecessary:
dtype == "fp8" in only tested in test_cp_with_fused_attention, and it's guarded here.

@andrewwhitecdw
andrewwhitecdw force-pushed the codequality/run-attention-with-cp-fp8-scaling-mode-is-not-validated branch from 864475d to 2d80391 Compare August 13, 2026 16:47
@andrewwhitecdw

Copy link
Copy Markdown
Contributor Author

Closing this PR. @cyanguwa is right — the fp8 path is only exercised by test_cp_with_fused_attention, where scaling_mode is already parametrized to valid values and guarded (test_attention_with_cp.py:600-603), so the validation check was unreachable. Thanks for the review!

@andrewwhitecdw
andrewwhitecdw deleted the codequality/run-attention-with-cp-fp8-scaling-mode-is-not-validated branch August 13, 2026 16:49
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