Skip to content

[Common] Allow column-wise output in the gated FP8 TMA cast (fixes FP8 gated activations on SM 12.0) - #3929

Open
rlaope wants to merge 2 commits into
NVIDIA:mainfrom
rlaope:sm120-gated-tma-columnwise
Open

rlaope wants to merge 2 commits into
NVIDIA:mainfrom
rlaope:sm120-gated-tma-columnwise

Conversation

@rlaope

@rlaope rlaope commented Nov 24, 2026

Copy link
Copy Markdown

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:

transformer_engine/common/cast/fp8/gated_fp8.cuh:336 in function cast_gated_tma:
Assertion failed: !output->has_columnwise_data(). Only rowwise cast supported in this function.

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) picks cast_gated_tma because is_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-TMA cast_gated_fwd/cast_gated_bwd path relies on. The assertion in cast_gated_tma is 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

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • common/cast/fp8/gated_fp8.cuh: cast_gated_tma requires 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: new test_gated_activation_fp8_columnwise_output. It requests row-wise and column-wise data from a Float8Quantizer for 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: main at a6393d0, NVTE_FRAMEWORK=pytorch NVTE_CUDA_ARCHS=120, CUDA 13.0.88, torch 2.14.1+cu130, cuDNN 9.24. The A/B swaps only libtransformer_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:

result
main 84 failed, 17193 passed, 32965 skipped
this PR (fix commit only) 17277 passed, 32965 skipped

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 with fp8_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) under DelayedScaling, 3 steps, BF16 and FP32. On main it raises the assertion. With this PR, output and gradient errors against the unquantized model match Float8CurrentScaling on 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:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Nov 24, 2026
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Tests fail on SM 10.0 ▶

Summary

Allows cast_gated_tma to accept outputs with both layouts while still requiring row-wise data.

  • FP8 gated activations can now return both row-wise and column-wise output.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Tests fail on SM 10.0

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.

This branch has not been deployed

No deployments
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.

1 participant