Repository navigation
Conversation
When torch.__trace has a handler (TORCH_TRACE, or pytest's log capture, which attaches to non-propagating loggers since pytest 9.2), AOTAutograd formats its forward metadata with repr() of the fake outputs. NVFP4Tensor and MXFP8Tensor reprs dequantize their data, which adds guards such as Eq(s0, 128) and specializes dims marked dynamic, so compiling an op that returns these tensors raises ConstraintViolationError. Return the metadata-only repr for fake or meta data, as Float8Tensor already does, and add a regression test that installs a trace handler. Signed-off-by: rlaope <105429536+rlaope@users.noreply.github.com>
rlaope
marked this pull request as ready for review
November 27, 2026 05:41
Contributor
[Medium impact] The PR appears safe to merge. SummaryKeeps
No actionable issues found. Tests were not run during this review. Reviews (1) · Last reviewed commit: "[PyTorch] Keep NVFP4 and MXFP8 tensor re..." · Reviewed by Greptile |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
NVFP4Tensor.__repr__andMXFP8Tensor.__repr__dequantize their data. Duringtorch.compile, AOTAutograd formats its forward metadata withrepr()of the fake outputs whenever the structured trace logger (torch.__trace) has a handler. Under tracing that dequantize adds shape guards (Eq(s0, 128)from_FromNVFP4Func.forward). Dims marked dynamic get specialized and compilation fails:Without
mark_dynamicit costs one recompile per input shape instead (4 graphs for 4 row counts instead of 2).The trace logger gets a handler from:
TORCH_TRACE=<dir>(tlparse), with plain Python and no pytest.torch.__traceis one of them. That is whytest_te_ops_bias_nvfp4_layout[rht|2d|row-scaled]fails under pytest 9.2 and passes under the pinned pytest 8.4.2.Float8Tensoralready returns the metadata-only repr for fake or meta_scale_invfor the same reason (#3053). This PR applies the same check to NVFP4 and MXFP8, using the data buffer. Eagerrepr()is unchanged.Type of change
Changes
NVFP4Tensor.__repr__andMXFP8Tensor.__repr__: returnsafe_quantized_reprwhen the data buffer is fake or meta (the same exact-class checkFloat8Tensor.__repr__uses).test_torch_compile.py:test_te_ops_bias_quantized_dynamic_with_trace_log[mxfp8|nvfp4]compiles the Bias backward custom op with an NVFP4/MXFP8 quantizer, aNullHandlerontorch.__traceand both dims marked dynamic. It runs 2 shapes and checks bitwise equality againsttex.bgrad_quantizeand that only one graph is compiled. The test does not depend on the pytest version.Validation
RTX PRO 6000 Blackwell Max-Q (SM 12.0), driver 590.48.01, torch 2.14.1+cu130, cuDNN 9.24, TE built from
main0c4a13f (NVTE_CUDA_ARCHS=120). The patch is Python-only, so both arms use the samelibtransformer_engine.so.python -m pytest -p no:randomly tests/pytorch/test_torch_compile.py:qa/L0_pytorch_unittest)test_te_ops_bias_nvfp4_layout[rht|2d|row-scaled]), 487 passed, 50 skipped, 1 xpassed, 40 errorsThe new test adds one pass (
nvfp4) and one skip (mxfp8). The failure sets differ only in the three layout tests. The 40 teardown errors (alltest_te_ops_activation_mlp_compile,AttributeError: 'cuBLASModule' object has no attribute 'allow_tf32') under pytest 9.2 are unrelated to this PR. They come from a pytest 9.2.0 regression inmonkeypatch.setattrundo for objects with__getattr__(torch.backends.cuda.matmul), tracked in pytest-dev/pytest#15402 with a revert in pytest-dev/pytest#15403.New test alone, main vs this PR (pytest 8.4.2): main
nvfp4FAILED (ConstraintViolationError), this PR passed. Themxfp8case is skipped on SM 12.0 (is_mxfp8_available()is False there), so it ran only on the NVFP4 path here. The MXFP8 repr change was checked with a standalone script that calls the same custom op withTORCH_TRACEset: main raised ConstraintViolationError and this PR passed. Float8 current scaling and blockwise were unaffected on main.Not run: other architectures (the change has no architecture-specific branch) and the full L0 suite.
Checklist: