Repository navigation
Conversation
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>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…to quantizer_gemm_ready_outputs Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> # Conflicts: # transformer_engine/pytorch/csrc/common.h # transformer_engine/pytorch/csrc/extensions/cast.cpp # transformer_engine/pytorch/csrc/extensions/pybind.cpp # transformer_engine/pytorch/csrc/quantizer.cpp
timmoon10
left a comment
There was a problem hiding this comment.
Good catch, it definitely is hacky that we sometimes ignore optimize_for_gemm. I'm skeptical about the changes to the C++ infrastructure since QuantizationWorkspace's design is rather ad hoc.
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>
Add FUSED_NORM_QUANT_UNSWIZZLED to layernorm_fwd and handle compact scale views and swizzling in the existing Impl switches of both normalization functions instead of a separate optional path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
for more information, see https://pre-commit.ci
Convert a reused GEMM output with the quantizer where the output tensor is constructed instead of after the GEMM. Limit compact scale views and batched swizzling to the grouped NVFP4 split-quantize kernel; other multi-tensor paths swizzle per tensor in quantize(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Quantize NVFP4 outputs whose kernel cannot write GEMM-swizzled scales into compact scratch views and swizzle them with one kernel in multi_tensor_quantize and split_quantize, while outputs with in-kernel swizzling are written directly. Declare the internal swizzle helpers in util.h next to the existing ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
for more information, see https://pre-commit.ci
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
My agent says:
|
[Medium impact] The change reaches native quantization, normalization, and GEMM output workflows in PyTorch. The PR appears safe to merge, with a non-blocking test gap around no-op replay. Findings
SummaryNative quantized outputs now honor
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Quantized output] --> B{Kernel writes requested layout?}
B -->|Yes| C[Write directly into output]
B -->|No| D[Redirect scale pointers to scratch]
D --> E[Kernel writes data and compact scales]
E --> F[Restore output scale pointers]
F --> G[Swizzle scratch scales into output buffers]
Reviews (1) · Last reviewed commit: "Drop NVFP4 shape-gate tests for GEMM-rea..." · Reviewed by Greptile |
| quantizer.optimize_for_gemm = False | ||
| expected = run().dequantize() | ||
| quantizer.optimize_for_gemm = optimize_for_gemm | ||
| actual = run() | ||
| assert actual._with_gemm_swizzled_scales == optimize_for_gemm | ||
| torch.testing.assert_close(actual.dequantize(), expected, atol=0, rtol=0) | ||
| if operation in ("layernorm", "rmsnorm"): | ||
| assert run(actual) is actual | ||
| assert actual._with_gemm_swizzled_scales == optimize_for_gemm | ||
| torch.testing.assert_close(actual.dequantize(), expected, atol=0, rtol=0) |
There was a problem hiding this comment.
Swizzled no-op replay lacks coverage
The new tests never pass noop_flag, and test_skip_quantization_with_noop_flag leaves optimize_for_gemm disabled. That leaves the new preserve_scales branch untested, so a regression could change cached scales during a step that should leave them untouched.
Extend the no-op replay test with optimize_for_gemm=True for NVFP4 outputs. Check that data, scales, and their addresses stay unchanged when the captured graph skips quantization.
Description
Some native operations return compact MXFP8 or NVFP4 scales even when their quantizer has
optimize_for_gemm=True. Callers and fake implementations must then predict the selected kernel's output layout.Honor the requested GEMM scale layout at the native operation boundary. When a kernel can only emit compact scales, it writes directly into the output with the output's scale pointers temporarily redirected to scratch buffers, and the scales are then swizzled into the output's own buffers. Output buffers are never reallocated, so their addresses stay stable. Kernels that already emit GEMM-swizzled scales skip the conversion.
Type of change
Changes
redirect_scales_to_scratch/restore_and_swizzle_scales(single- and multi-tensor) for kernels that only emit compact scales. They touch only the scale pointers and the swizzle flag, so the output tensor itself is used by the kernel.noop_flag, the previous scales are unswizzled into the scratch buffers first, so a GPU no-op leaves the output unchanged.Impl::FUSED_NORM_QUANT_UNSWIZZLEDfor cuDNN MXFP8 LayerNorm/RMSNorm withoptimize_for_gemm, using the redirect within the existing intermediate-output switch. Keep 2D MXFP8 normalization on the compatible unfused path.inplace_swizzle_scale_for_gemmcalls, which replaced the scale buffers of the output.fake_bgradto derive the layout directly from the quantizer and remove the unused layout-query binding.Checklist: