Skip to content

[Common] Dispatch non-FP8 gated activation forward to vectorized pointwise kernel - #4038

Open
wanglei875 wants to merge 1 commit into
NVIDIA:mainfrom
wanglei875:perf/gated-fwd-non-fp8-pointwise
Open

wanglei875 wants to merge 1 commit into
NVIDIA:mainfrom
wanglei875:perf/gated-fwd-non-fp8-pointwise

Conversation

@wanglei875

Copy link
Copy Markdown

Description

In quantize_gated_fwd_helper (transformer_engine/common/cast/dispatch/gated.cuh), the NVTE_DELAYED_TENSOR_SCALING case currently dispatches SM 10.0+ gated forward calls with cols % 32 == 0 to the FP8 TMA kernel (cast_fp8_gated_kernel) regardless of output dtype—even when the output is unquantized BF16/FP16/FP32.

As reported in #3968, routing unquantized BF16 gated SwiGLU forward through the FP8 TMA kernel incurs TMA descriptor creation, 65.7 KB dynamic shared memory per block, and lower effective memory bandwidth (~4.0–4.3 TB/s on GB200 vs ~5.6–5.8 TB/s for a plain vectorized pointwise kernel).

This PR restricts use_tma_kernels in quantize_gated_fwd_helper to is_fp8_dtype(output->dtype()) so that unquantized BF16/FP16/FP32 gated forward calls dispatch directly to the existing vectorized pointwise kernel (fp8::cast_gated_fwd / GatedActivationKernelLauncher), which uses wide vectorized loads/stores with zero dynamic shared memory and compiles out FP8 scaling via if constexpr (is_fp8<OutputType>::value).

Backward (quantize_gated_bwd_helper) is left unchanged since #3968 notes dSwiGLU backward is unaffected.

Addresses #3968

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

  • Guard use_tma_kernels in quantize_gated_fwd_helper (transformer_engine/common/cast/dispatch/gated.cuh) with is_fp8_dtype(output->dtype()) so non-FP8 outputs use the vectorized pointwise cast_gated_fwd path on SM 10.0+.

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

Copilot AI balanced review requested due to automatic review settings December 5, 2026 08:09

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] This PR appears safe to merge.

Summary

Restricts the gated forward TMA kernel to FP8 outputs.

  • Only FP8 gated outputs can take the TMA route.

Reviews (1) · Last reviewed commit: "[Common] Dispatch non-FP8 gated activati..." · Reviewed by Greptile

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants