Experimental Triton GEMM backend for TE PyTorch (BF16/FP16/FP32/FP8/MXFP8) #667
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #667"
general
weight: 0.35
aris134
Summary
Adds a Triton-based GEMM backend for the PyTorch bindings as an alternative to the default hipBLASLt path. Opt-in via
NVTE_USE_GEMM_TRITON=1; the C++/hipBLASLt path remains the default and is unchanged when the flag is unset.The backend is exercised end-to-end through TE's
Linear,LayerNormLinear, andgeneral_gemm()entry points, so anything that dispatches throughgeneral_gemmtransparently picks up the Triton kernels when the flag is on.Motivation. Give TE a Python-side GEMM path we can iterate on for AMD-specific work — MXFP8, MoE-style grouped shapes, autotune experiments, gfx950 kernel tuning — without going through the hipBLASLt release cadence. Not yet a perf replacement for hipBLASLt; BF16 in particular is slower today.
Precision support
| Format | Status | Kernel |
|---|---|---|
| FP32 | Supported |
matmul_kernel|| FP16 | Supported |
matmul_kernel|| BF16 | Supported |
matmul_kernel(perf below hipBLASLt) || Regular FP8 (E4M3 × E4M3, E5M2 × E5M2) | Supported |
matmul_kernelwithINPUT_FP8=True|| Mixed FP8 (E4M3 × E5M2 — HYBRID recipes' bwd) | Gated on PyTorch 2.14.0.dev20260626+ | Triton compiler bug (triton-lang/triton#9567) |
| MXFP8 (block-scaled, 32 elems/block, E8M0 scales) | Supported (torch ≥ 2.10) |
mxfp8_matmul_kernelviatl.dot_scaled()|| NVFP4 / other
QuantizedTensorStorage| Refused with clear ValueError | — |Epilogues:
DEFAULT,BIAS,BGRADB(bias gradient). Fused FP8 output quantization is applied by calling the caller-provided quantizer on the fp32 accumulator output — the kernel'sOUTPUT_FP8path withc_scale + c_amaxis present but not wired through the wrapper yet (follow-up perf work).Architecture
Key files (matches the
triton_kernels/gmm/subpackage layout):transformer_engine/pytorch/triton_kernels/gemm/-
gemm_kernels.py— the two@triton.jitkernels:matmul_kernel,mxfp8_matmul_kernel-
gemm_wrapper.py— Python wrappers (matmul,mxfp8_matmul) and TE-shaped entry points (te_gemm_triton,te_generic_gemm_triton)-
gemm_common.py— dtype conversions, shape helpers,Float8TensorWrapper,MXFP8TensorWrapper-
__init__.py— re-exports the public APItransformer_engine/pytorch/quantization.py— recipe-support gate that refuses HYBRID underNVTE_USE_GEMM_TRITON=1(until torch 2.14)Testing
Three dedicated Triton GEMM test files under
tests/pytorch/triton_kernels/, matching the sibling test layout (test_cast.py,test_cast_mxfp8.py,test_grouped_gemm.py,test_norms.py, ...):| File | Purpose |
|---|---|
|
tests/pytorch/triton_kernels/test_gemm.py|general_gemm()under Triton — equivalence vs.torch.matmuland vs. C++ backend, across regular / FP8 / mixed-FP8 / MXFP8, all layouts, plus a batched-fp8 multidim case ||
tests/pytorch/triton_kernels/test_gemm_kernel.py| Low-levelte_gemm_triton()kernel correctness across dtype × shape × layout × bias × grad (1056 parametrizations of onetest_correctnessfn) ||
tests/pytorch/triton_kernels/test_gemm_mxfp8.py| MXFP8 wrapper sanity + one direct-kernel-with-simulated-data case |Plus a repo-wide pytest hook (
tests/pytorch/conftest.py) that converts the three backend-refusal ValueErrors (HYBRID, mixed FP8, unsupportedQuantizedTensorStorage) intopytest.skip. Self-retiring — when the runtime gates are relaxed (e.g. torch ≥ 2.14 lands, NVFP4 kernel gets implemented), the marker text disappears from the error and the hook stops firing without code changes.Eight grouped-GEMM equivalence tests in
test_numerics.py(comparing a grouped GEMM to a sequence of individual GEMMs atrtol=0, atol=0) get a_skip_grouped_under_gemm_tritonmarker: underNVTE_USE_GEMM_TRITON=1the two sides no longer share a backend, so bit-exact equivalence is broken by design. Comment on upstream's assertion literally says# cuBLAS implementation should be bit-wise match.CI wiring
ci/pytorch.sh(invoked from.github/workflows/rocm-ci.ymlon push todev/release_v2._rocmand on workflow_dispatch):"triton" label — direct Triton GEMM tests, level 1 (runs at every CI level):
"gemm-triton" label — TE integration sweep with the Triton backend:
Results on gfx950 / PyTorch 2.10
Direct Triton GEMM suites:
| Suite | Result |
|---|---|
|
triton_kernels/test_gemm.py| 212 passed / 72 skipped (mixed-FP8 gated) ||
triton_kernels/test_gemm_kernel.py| 450 passed / 606 skipped (mixed-FP8 gated) ||
triton_kernels/test_gemm_mxfp8.py| 4 passed ||
test_float8_current_scaling_exact.pyunder Triton | 5 passed / 2 skipped |Full
test_numerics.pyunderNVTE_USE_GEMM_TRITON=1: 0 failed / 1058 passed / 2644 skipped / 28 xfailed in ~6 min.Known limitations
main; first ships in PyTorch2.14.0.dev20260626+nightlies (verified against pytorch/pytorch release-branch Triton pins). Refused with a clear ValueError until torch ≥ 2.14 is detected.unset NVTE_USE_GEMM_TRITONfor NVFP4 recipes.OUTPUT_FP8path (c_scale + c_amaxin-kernel) is present but not yet wired. Follow-up.GroupedLinear,test_grouped_gemm, ...) fall through to hipBLASLt / CUTLASS / AITER Triton grouped kernels as before.Notable correctness fixes surfaced during the v2.15 rebase
matmul_kernelandmxfp8_matmul_kernel— fixes SIGABRT under Triton autotune benchmarking when(M-1) stride > 2^31. Concrete repro:test_fp8_current_scaling_linear_large_numel_e4m3[bs33-fp32], M=143616, K=15360 → 2.2G.te_generic_gemm_triton(previously the wrapper silently dropped α / β / accumulate).restore_value=['c_ptr']on the mxfp8 autotuner soACCUMULATE=Truebenchmark iterations don't multi-copy the result.Float8TensorWrapperbatched-columnwise permutation rewritten to matchfp8_transpose's actual output layout (old formula silently scrambled batch dims for ndim ≥ 3).e4m3fnon gfx950 vse4m3fnuzon gfx942) so0x7F/0xFFbytes are not NaN encodings under OCP e4m3fn.ci/pytorch.shpytest_runbug workaround —"$TEST_DIR/$@"only prefixes the first positional arg, so passing two file paths silently collected 0 items on the second. Split into two calls.Test plan
pip install -e . --no-build-isolationbuilds cleanly on gfx950test_numerics.pyunderNVTE_USE_GEMM_TRITON=1completes with 0 failuresci/pytorch.shsmoke run exercises the new CI wiring end-to-endBuild and Test Branchon pushOUTPUT_FP8kernel path wired throughte_generic_gemm_triton🤖 Generated with Claude Code