Repository navigation
[PyTorch] Fix NVFP4 metadata in compiled Linear operations - #3628
Merged
Merged
Conversation
Describe columnwise FP4 buffers with the flattened 2D shape used by native quantization. Cover 3D and 4D inputs, singleton dimensions, RHT variants, buffer metadata, and compiled forward/backward with CUDA graphs. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
7 of 9 tasks
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Preserve the actual scale layout across custom-op boundaries and describe Bias backward output with the native fused-quantization layout. Keep the columnwise storage warning outside tracing. Cover compiled ops.Linear gradients with compact and swizzled scales, including disabled RHT fusion and CUDA Graphs. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Exercise current and block FP8, MXFP8, and NVFP4 variants in the existing fresh-process test. Keep scale-layout defaults in create_metadata instead of duplicating them in TensorSpec initialization. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
pggPL
marked this pull request as ready for review
October 12, 2026 15:31
Contributor
[Medium impact] The changes appear safe to merge; no actionable new defects were found. SummaryThis PR aligns compiled NVFP4 metadata with native outputs for Linear operations with bias and non-matrix inputs.
The latest changes flatten the columnwise shape helper and test a size-one middle dimension. No new actionable issues were found. Tests were not run during this review. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[NVFP4 quantizer settings] --> B[Shared alignment rules]
B --> C[Native output scale layout]
B --> D[Fake output scale layout]
D --> E[TensorSpec metadata]
C --> F[Compiled GEMM]
E --> F
Reviews (12) · Last reviewed commit: "Fix NVFP4 columnwise shapes in the share..." · Reviewed by Greptile |
Skip TE autocast for unquantized inputs and give the eager reference its own model so quantizer usage changes do not invalidate compiled graphs. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Expose native alignment requirements through a metadata-only binding. Keep symbolic shape checks and environment reads visible to Dynamo, and cover dynamic batches and configuration changes through the Bias custom op. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Collaborator
Author
|
/te-ci pytorch L0 |
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Collaborator
Author
|
/te-ci pytorch |
ptrendx
approved these changes
Oct 19, 2026
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.
Fix NVFP4 torch.compile failures for non-matrix Linear inputs and incorrect gradients from Linear operations with bias. Native Bias backward can produce compact scales while its fake output describes GEMM-swizzled scales, causing compiled GEMM to interpret the reconstructed tensor incorrectly.
Native execution and fake metadata now share alignment requirements through NVFP4Quantizer. C++ reads the RHT-fusion environment flag only when needed; Python reads it explicitly so Dynamo can guard changes. TensorSpec preserves the actual scale layout, and NVFP4 metadata matches native packed columnwise buffers and row-scaled amax shapes. Columnwise-only shape warnings are skipped during tracing.
Bias backward uses a small shared fake helper. Follow-up normalization and activation operations should use the same fused-output metadata helper.
Regression coverage stays in test_torch_compile.py, including dynamic shapes, environment changes, quantizer configurations and CUDA Graphs. Focused checks on SM89 passed: 98 tests passed and 44 skipped, including hardware-dependent NVFP4 cases. The C++ extension build and binding checks, pre-commit and changed-source pylint also passed. Validation of the final NVFP4 test matrix on SM100 remains pending; PyTorch L0 CI is requested separately.
Fixes #3626.