Repository navigation
[Common] Allow column-wise output in the gated FP8 TMA cast (fixes FP8 gated activations on SM 12.0) - #3929
[Common] Allow column-wise output in the gated FP8 TMA cast (fixes FP8 gated activations on SM 12.0)#3929rlaope wants to merge 2 commits into
Conversation
cast_gated_tma rejected outputs that also request column-wise data, but the delayed-scaling dispatcher already fills column-wise data with a transpose of the row-wise output after either kernel runs. On SM 12.0, which needs both usages because it has no non-TN FP8 GEMM, every delayed-scaling gated activation with an FP8 output hit this assertion. Require row-wise data instead, which is what the kernel writes. Signed-off-by: rlaope <105429536+rlaope@users.noreply.github.com>
Request row-wise and column-wise data from a delayed-scaling FP8 quantizer for each gated activation and its backward, and check that the column-wise data is the transpose of the row-wise data. Signed-off-by: rlaope <105429536+rlaope@users.noreply.github.com>
[Medium impact] The change affects delayed-scaling FP8 gated activation calls that use the TMA cast. Fix the new test’s missing-transpose error on SM 10.0 before merging. Findings
SummaryAllows
Reviews (1) · Last reviewed commit: "[PyTorch] Test gated FP8 activations wit..." · Reviewed by Greptile |
| (dact(dy, x, make_quantizer()), dact(dy, x, None)), | ||
| ): | ||
| rowwise = out.dequantize(dtype=torch.float32) | ||
| columnwise = out._transpose.view(torch.float8_e4m3fn).to(torch.float32) * out._scale_inv |
There was a problem hiding this comment.
out._transpose is None on SM 10.0, so .view(...) raises AttributeError even when the activation works. Float8Quantizer::create_tensor omits the transpose when nvte_is_non_tn_fp8_gemm_supported() is true, which includes SM 10.0. The test only skips devices without FP8 support, so all ten new cases fail there.
Check the column-wise buffer only when the device needs a separate transpose, or explicitly supply both buffers to test this path on every device.
Description
On SM 12.0, every delayed-scaling FP8 gated activation (SwiGLU, GeGLU, ReGLU, QGeGLU, SReGLU, clamped SwiGLU) whose output is quantized fails in forward and backward with:
SM 12.0 has no non-TN FP8 GEMM (
is_non_tn_fp8_gemm_supported()is false), so the FP8 output quantizer asks for both row-wise and column-wise data. The dispatcher (cast/dispatch/gated.cuh) pickscast_gated_tmabecauseis_supported_by_CC_100()is true for SM 12.0, and BF16/FP16 fit in shared memory since #3600. The dispatcher already fills column-wise data after either kernel with a transpose of the row-wise output, which the non-TMAcast_gated_fwd/cast_gated_bwdpath relies on. The assertion incast_gated_tmais the only thing that blocks it. SM 10.0 does not hit this because it does not request column-wise data there.This PR replaces the assertion with a check that row-wise data, which the kernel writes, is allocated. It does not change any kernel.
Related: #3299 / #3600 fixed the FP32 shared-memory overflow in the same kernel. #2833 (open) disables the gated TMA kernels on SM 12.0 entirely. This change keeps the TMA kernel on SM 12.0 and touches only the assertion. If #2833 lands first, this PR still covers any other device without non-TN FP8 GEMMs that passes the shared-memory check.
Type of change
Changes
common/cast/fp8/gated_fp8.cuh:cast_gated_tmarequires row-wise output data instead of rejecting column-wise data. The dispatcher's existing transpose fills the column-wise data.tests/pytorch/test_fusible_ops.py: newtest_gated_activation_fp8_columnwise_output. It requests row-wise and column-wise data from aFloat8Quantizerfor each gated activation and its backward (FP32 and BF16 input), compares the row-wise result with the unquantized op, and checks that the column-wise data equals the transpose of the row-wise data. It runs on any FP8-capable GPU.Testing
Hardware: RTX PRO 6000 Blackwell Max-Q (SM 12.0, 99 KB shared memory per block), driver 590.48.01. Build:
mainat a6393d0,NVTE_FRAMEWORK=pytorch NVTE_CUDA_ARCHS=120, CUDA 13.0.88, torch 2.14.1+cu130, cuDNN 9.24. The A/B swaps onlylibtransformer_engine.so(main build vs patched build) under the same Python tree.pytest -n 2 tests/pytorch/test_fusible_ops.py tests/pytorch/test_sanity.py tests/pytorch/test_recipe.py:All 84 failures on main are this assertion:
TestBasicOps::test_activation(36),TestSequentialModules::test_layernorm_mlp(24),TestBasicOps::test_clamped_swiglu(16),TestBasicOps::test_swiglu(8), all withfp8_delayed_scaling. Each also fails when run alone.New test: main 10 failed (same assertion), this PR 10 passed.
End-to-end check:
te_ops.Sequential(Linear, SwiGLU/GEGLU/ReGLU, Linear)underDelayedScaling, 3 steps, BF16 and FP32. On main it raises the assertion. With this PR, output and gradient errors against the unquantized model matchFloat8CurrentScalingon the same model, for example SwiGLU BF16 at y 0.0645 vs 0.0644 and dx 0.0913 vs 0.0916.Not run: multi-GPU tests and other architectures. I have no SM 10.0 card. On SM 10.0 the change matters only when column-wise data is requested, and that case used to raise this same assertion.
Checklist: