Repository navigation
Add BF16 grouped sReLU fusion with explicit numerical modes - #3937
Open
ZeYang1025 wants to merge 6 commits into
Open
ZeYang1025 wants to merge 6 commits into
ZeYang1025 wants to merge 6 commits into
Conversation
Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com>
4 of 7 tasks
Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com>
Use the existing _unused convention for intentionally ignored keyword arguments so pylint recognizes them. Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com>
ZeYang1025
marked this pull request as ready for review
November 24, 2026 22:03
Contributor
Confidence Score: 5/5
[Medium impact] The changes since the previous review appear safe to merge. SummaryAdds BF16 grouped squared-ReLU fusion with explicit activation-input and tanh modes, saved or recomputed FC2 inputs, and deterministic probability gradients.
Reviews (3) · Last reviewed commit: "Skip the BF16 sReLU pre-activation store..." · Reviewed by Greptile |
cuDNN Frontend's BF16 sReLU accurate mode now evaluates libdevice tanhf, the function eager PyTorch uses for FP32 torch.tanh on CUDA. Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Package metadata can name a stale public nvidia-cutlass-dsl while an internal DSL distribution provides the imported cutlass (as in the Nemotron Ultra images), which made the fusion fall back to the unfused path. Ask cuDNN Frontend's gate (cutedsl_requirement_error) and keep the metadata check only for frontends without it. Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A forward that runs without autograd, such as the no-grad pass of a recomputed expert MLP, never reads the pre-activation. When cuDNN Frontend's BF16 sReLU wrapper accepts generate_c, pass generate_c=False there, so the kernel neither allocates nor stores it. Older frontends keep the previous call. Signed-off-by: Ze Yang <142831877+ZeYang1025@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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", andactivation_recompute_in_mlp=False: FC2 wgrad consumes the actual forward FC2 input. Both activation-input modes, both tanh implementations, and save/recompute are supported. Withsavedplus recomputation, FC2 input is bitwise identical to forward under the same tanh configuration. Withaccplus 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
NVTE_ALLOW_NONDETERMINISTIC_ALGO=0or PyTorch deterministic algorithms are enabled; atomic otherwise.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
GB200 (SM100) and GB300 (SM103) validation on 2026-11-24 used TE revision
26cdc7807df304e0b91985ab81d425d89a011ebe, MCoree57410176cb54de70071745f443f0d7c441d8bc3, and cuDNN Frontendf73ade8a8f33300687d38d80823f8ea676515efe. Source revisions and Python/native import provenance were checked on both platforms. Reruns reused each platform's fresh cuDNN/TE build after verifying unchanged native sources and build settings. 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 on each platform, with zero skips in these suites:
TestGroupedMLPBf16SReLU: 89 tests, including the full numerical matrix, saved/recomputed FC2-input semantics, dProb policy, delayed/main-grad wgrad, empty experts and CUDA graphs.TestGroupedMLPBf16FusedOpplusTestGroupedMLPDeterminism: 59 tests.7d0d5046f4013ad5789beb4744eef97b94f7eb0e: 1 test per revision.The remaining
tests/pytorch/test_grouped_mlp.pyregression completed on each platform with 1,387 passed, 3,896 skipped, 0 failures/errors (5,283 collected cases, excluding the three separately tested BF16 sReLU/GLU/determinism classes). All 18 skip-reason categories exist in pinned main and cover unsupported or inapplicable quantization/dtype/layout/bias combinations and duplicate coverage. These skipped cases are not counted as passes. Both regression jobs exited 0.The earlier native failure was caused by the harness's deprecated global
NVTE_CUTEDSL_FUSED_GROUPED_MLP=1flag forcing 256-token alignment on an ordinary 128-token GroupedLinear case. Removing that flag resolved both isolated probes and the broader regression; fused callers retain their explicit alignment.Earlier runs on both platforms at TE
7522c2eb7ea94491c1b2da6f4163beebae5f0e50also passed 30 standalone scaled sReLU/tanh-sReLU activation cases, license and diff checks. Revision26cdc7807df304e0b91985ab81d425d89a011ebeadds only equivalent dictionary literals to those earlier runs; local pinned Black and AST equivalence checks passed.Follow-up
929fe65f44c78ab1179c77d359484b6a3ae1bafdfixes the remainingW0613by naming intentionally ignored activation forward keyword arguments_unused, following adjacent ops. The full Python lint launcher (PYTHON_ONLY=1 TE_PATH=<checkout> bash qa/L0_pytorch_lint/test.sh) passes locally with exit 0, using Python 3.12.15 and the repository-pinned pylint 4.1.3. Changed-file pre-commit also passes. An AST comparison confirms the only code change is that unused local parameter name; GPU suites were not repeated after this lint-only commit.Validation limits:
Focused GPU validation is complete on both platforms. The PR remains a draft for human review; full repository CI remains outstanding.
Update (2026-12-03): accurate-tanh wording and DSL gate
88a81fbf(docs only):bf16_tanh_mode="accurate"is now described as the CUDA math library's FP32tanhf, the function eager PyTorch uses for FP32torch.tanhon CUDA. cuDNN Frontend's accurate mode switched to it in feat(gemm): add BF16 grouped sReLU forward cudnn-frontend#2885.f99ae0c7: the fusion's capability check asks cuDNN Frontend'scutedsl_requirement_error, which reports the CuTe DSL whose files are actually loaded. It keeps the package-metadata check only for frontends without that function. In images where stale publicnvidia-cutlass-dsl4.6.0 metadata sits over the internal DSL that provides the importedcutlass(the Nemotron Ultra images), the old check made the fusion fall back to the unfused path without notice. The loaded-DSL attribution needs cuDNN Frontend with feat(gemm): add BF16 grouped sReLU forward cudnn-frontend#2885 at2cd73412or later.f99ae0c7with the feat(gemm): add BF16 grouped dSReLU backward cudnn-frontend#2886 headd43e68d2(after its develop merge) on GB300/SM103, in the Nemotron Ultra image with its internal CuTe DSL (the gate reportsnvidia-cutlass-dsl-internal0.3.0):TestGroupedMLPBf16SReLU,TestGroupedMLPBf16FusedOpandTestGroupedMLPDeterminism148 passed; MCore BF16 sReLU mode and config tests (-k "srelu or bf16_srelu") 67 passed; two-rank deterministic replay 16 + 16 passed; no skips. TE was built from929fe65fin that image, with the two changed Python files copied over it. The pinned Black 24.4.2 with the repository's flags passes on both files. GB200/SM100 and the broadertest_grouped_mlp.pyregression were not rerun for this update.Update (2026-12-04): skip the pre-activation store without autograd
ea56e483: when the BF16 sReLU forward runs without autograd (for example the no-grad pass of a recomputed expert MLP), TE passesgenerate_c=Falseto cuDNN Frontend's wrapper (NVIDIA/cudnn-frontend#2885), so the kernel neither allocates nor stores the pre-activation. Frontends without the option keep the previous call. New testtest_forward_without_grad_skips_preactivation. With FE #2886 at8673c274on GB300 (Ultra image, internal CuTe DSL):TestGroupedMLPBf16SReLU,TestGroupedMLPBf16FusedOpandTestGroupedMLPDeterminism149 passed, no skips. The forward kernel without the store is 3.5-3.8% faster at Ultra expert shapes.Type of change
Checklist