Skip to content

Add BF16 grouped sReLU fusion with explicit numerical modes - #3937

Draft
ZeYang1025 wants to merge 2 commits into
NVIDIA:mainfrom
ZeYang1025:codex/bf16-srelu-fusion
Draft

ZeYang1025 wants to merge 2 commits into
NVIDIA:mainfrom
ZeYang1025:codex/bf16-srelu-fusion

Conversation

@ZeYang1025

@ZeYang1025 ZeYang1025 commented Nov 24, 2026 •

Copy link
Copy Markdown

Description

Add the BF16 grouped MLP path for weighted squared ReLU and tanh-clamped squared ReLU on SM100/SM103, using the cuDNN Frontend sReLU forward/backward wrappers.

The default is bf16_act_input="acc", bf16_tanh_mode="approx", and activation_recompute_in_mlp=False: FC2 wgrad consumes the actual forward FC2 input. Both activation-input modes, both tanh implementations, and save/recompute are supported. With saved plus recomputation, FC2 input is bitwise identical to forward under the same tanh configuration. With acc plus recomputation, backward reconstructs from the saved BF16 pre-activation and may change FC2 wgrad; the implementation does not change the selected input mode. This guarantee concerns FC2 input only, not whole-MLP or training equivalence to unfused BF16.

Changes

  • Share BF16 grouped MLP orchestration with the existing GLU path and add unary forward/backward adapters. Keep GLU's existing behavior and restrictions.
  • Support dense and per-expert BF16 weights, empty experts/ranks, main-grad accumulation, delayed wgrad, and CUDA graph capture through the shared path. Unary fusion requires no bias and the existing aligned-dimension/token contracts.
  • Pass TE's live determinism policy explicitly to dSReLU: deterministic dProb when NVTE_ALLOW_NONDETERMINISTIC_ALGO=0 or PyTorch deterministic algorithms are enabled; atomic otherwise.
  • Add the 32 numerical combinations in both weight layouts, independent numerical references, exact FC2-input/wgrad-source checks, reduction-policy replay, empty batches, delayed wgrad and graph tests.
  • Document defaults, numerical boundaries, capability checks, and fallback scope.

Depends on NVIDIA/cudnn-frontend#2884, NVIDIA/cudnn-frontend#2885 and NVIDIA/cudnn-frontend#2886, CuTe DSL >=4.8.0, and the existing canonical BF16 grouped GEMM/wgrad APIs. Capability detection checks the new wrapper options as well as the existing GEMM markers.

Downstream integration: NVIDIA/Megatron-LM#9756.

Validation

GB300 (SM103) validation on 2026-11-24 used TE 7522c2eb7ea94491c1b2da6f4163beebae5f0e50, MCore e57410176cb54de70071745f443f0d7c441d8bc3, and cuDNN Frontend f73ade8a8f33300687d38d80823f8ea676515efe. Python/native import provenance was checked after fresh cuDNN/TE builds. Environment: PyTorch 2.12.0a0 (NGC 26.04), CUDA 13.2, cuDNN 9.25, CuTe DSL 4.8.1, TVM FFI 0.1.12.

Passed, with zero skips:

  • TestGroupedMLPBf16SReLU: 89 tests, including the full numerical matrix, saved/recomputed FC2-input semantics, dProb policy, delayed/main-grad wgrad, empty experts and CUDA graphs.
  • TestGroupedMLPBf16FusedOp plus TestGroupedMLPDeterminism: 59 tests.
  • Standalone scaled sReLU/tanh-sReLU activation regressions: 30 tests.
  • Downstream MCore BF16 mode integration: 32 tests.
  • License and diff checks. Local changed-file pre-commit checks passed on the original implementation.

Outstanding validation:

  • The remaining grouped-MLP file hit CUDA Error: unspecified launch failure in native launch_grouped_gemm_setup, first at TestGroupedLinearOp::test_wgrad_storage_and_hooks[False-False-1]. The next 5,281 cases errored during RNG/CUDA setup. This is not a passing regression run; an isolated PR/base comparison is pending.
  • Full PyTorch lint reported two new use-dict-literal findings, fixed in follow-up commit 26cdc7807df304e0b91985ab81d425d89a011ebe, plus an unused-argument warning in an unchanged activation method. The follow-up passes the pinned Black check and AST equivalence check; its GPU/lint rerun and baseline lint comparison are pending.
  • Downstream two-rank replay did not collect because the launcher set NVTE_ALLOW_NONDETERMINISTIC_ALGO=1. The launcher now sets 0 specifically for replay; no replay pass is claimed yet.
  • GB200 and the complete PyTorch L0 suite remain pending.

The PR remains a draft pending the remaining validation and human review.

Type of change

  • New feature
  • Documentation change
  • Code refactoring

Checklist

  • Read the contributing guidelines
  • Added relevant tests and documentation
  • New and existing GPU tests pass locally
  • Human author has reviewed the complete diff before marking ready

Signed-off-by: Ze Yang <142831877+ZeYang1025@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
Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com>

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