← Back to Pull requests

Support Triton training ops on ROCm, and JSD Triton kernels on CUDA #9177

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 27, 2026 04:36 UTC
Author

Changes

1. Triton training ops on ROCm

  • Gates removed: fused RMSNorm, fused RoPE, the AutoEP fused token ops, chunked cross-entropy and the

  • vocab-parallel ops no longer gate on torch.version.hip.
    - combine_impl="fused_weighted_sum" and row_weighting_impl="fused" no longer raise on ROCm.
    - The vocab-parallel ops follow Triton availability on ROCm instead of deepspeed.HAS_TRITON. That flag is
    False on ROCm only to keep the Triton inference kernels off.
  • Subchannel quantization formats: CUDA_Accelerator.supported_subchannel_quantization_formats() on ROCm returns

  • per architecture:
    - gfx942 (MI300X): int8; OCP FP8 is only emulated there.
    - gfx950 (MI350X): int8, e4m3 and e5m2.
    - Other architectures: nothing, so they fall back to PyTorch.
  • Grouped GEMM: torch._grouped_mm stays the default on AMD. The Triton grouped GEMM is correct there but not

  • uniformly faster on MI300X; the comment now says so.
  • Tests: the ROCm skip in test_fused_rms_norm.py is removed.

  • Docs: autoep.rst no longer says that fused RMSNorm and RoPE run eager on ROCm, or that fused row weighting

  • is rejected there.

    2. JSD and the other vocab-parallel Triton kernels on every CUDA GPU

  • The vocab-parallel Triton kernels (JSD, log-probability, entropy and KL) run whenever Triton is available and the

  • logits are on a CUDA or ROCm GPU. JSD also uses them on Intel XPU.
  • Before, they also required accelerator.is_triton_supported(), which on CUDA means sm80+, and

  • deepspeed.HAS_TRITON. JSD additionally ran on XPU when the Intel Triton backend was active.
  • So nothing changes on A100 or H100. GPUs older than sm80 now get the Triton kernels instead of eager row chunks;

  • validated on sm75 below.

    3. Fused RMSNorm on wider rows

  • The widest supported normalized dimension goes from 2,048 to 32,768. That covers, for example, Qwen3-235B-A22B

  • (4,096) and DeepSeek-V3 (7,168). replace_rms_norm leaves wider norms on eager.
  • Rows wider than 2,048 launch 8 warps instead of 4. More warps would not help: 8 warps can already use nearly all

  • of an SM's registers, and 16 warps were no faster at 32,768 wide.

    Cleanup

    4. Module moves

  • deepspeed/runtime/chunked_cross_entropy.py becomes deepspeed/ops/triton_ops/chunked_cross_entropy.py.

  • deepspeed/sequence/vocab_parallel_ops.py becomes deepspeed/ops/triton_ops/vocab_parallel_ops.py.

  • Imports in the docs (autoep.rst, autotp-training.md) and the tests are updated.
  • 5. Input checks and API cleanup

  • Fused RMSNorm: assert_supported(hidden, weight) no longer takes eps. Removed checks:

  • - a duplicated Triton-availability check
    - weight dtype and device checks, already implied by hidden's checks plus the same-dtype and same-device checks
    - checks for degenerate shapes (zero width, a scalar input)
    - the 1-D weight and float eps checks, which replace_rms_norm already enforces at install
  • Fused RoPE: removed the tensor-type checks, the repeated per-tensor CUDA check, head_dim > 0 and the q/k

  • batch-size match. The last two cases now run and match eager exactly.
  • AutoEP fused row weighting: non-contiguous rows are copied instead of rejected. Strided weights are accepted,

  • since the kernels read them by stride. The 2-D rows check is gone, because the layer always passes 2-D rows.
    The docs list is updated.
  • Chunked cross-entropy: the backend is chosen automatically: Triton for CUDA logits when Triton is available,

  • PyTorch otherwise.
    - The backend parameter is gone from chunked_cross_entropy, ChunkedCausalLMLoss and
    install_chunked_causal_lm_loss.
    - triton_backend_available() is removed; it duplicated is_triton_available().

    6. Tests

  • test_fused_rms_norm.py goes from 122 to 65 tests by removing repeated coverage:

  • - shapes that take the same kernel path
    - a second dtype for tests that don't depend on dtype
    - CPU copies of CUDA tests
    - tests of development-only details
  • The fused RMSNorm accuracy tolerances now hold on other GPUs. The kernels round exactly as eager does, but each

  • row's FP32 scale can differ in its last bits, which occasionally rounds a value to its neighbor. Near-zero
    results then sit many ULPs apart. At every width:
    - weight gradients may differ by up to two rounding steps of the column's largest product;
    - input gradients may differ by 1e-7 absolute, a floor that applied only to rows up to 128 wide before.

  • The chunked cross-entropy tests select a backend by the logits' device. The named-backend test is removed.

  • The token-ops guard test no longer asserts the removed contiguity check.
  • 7. AGENTS.md

    New project rules on defensive programming, common-case design, architecture-specific code, code placement and test
    purpose, plus local verification.

    Validation

    ROCm: MI300X and MI350X

  • Hardware: 1x AMD Instinct MI300X (gfx942) and, in a separate run, 1x MI350X (gfx950).

  • Software: torch 2.13.0+rocm10.0.0, Triton 3.8.0, transformers 5.24.1, Python 3.12, Ubuntu 24.04 container.
  • | Op (test files) | Master, MI300X | With the patch, MI300X and MI350X |
    |---|---|---|
    | Fused RMSNorm (118 tests at the time) | 61 passed, 57 skipped | 117 passed, 1 skipped (two GPUs) |
    | Fused RoPE | 0 passed, 34 skipped | 32 passed, 2 skipped (two GPUs) |
    | AutoEP fused token ops, with test_autoep_fused_parity.py | 0 passed, 86 skipped | 64 passed, 22 skipped (two to four GPUs) |
    | Chunked cross-entropy | 31 passed, 18 skipped, 1 failed | 49 passed, 1 failed (pre-existing, below) |
    | Vocab-parallel ops | 67 passed, 46 skipped | 100 passed, 13 skipped (two GPUs); all 33 Triton tests pass, JSD's 11 included |
    | Subchannel quantization | 32 passed, 29 skipped | 56 passed, 5 skipped (two GPUs) with all formats offered |
    | Fused SwiGLU, with test_autoep_expert_activation.py | 288 passed, 16 skipped | unchanged |
    | AutoEP permute_rows | 27 passed | unchanged |
    | Triton grouped GEMM | 77 passed, 1 skipped | unchanged |

  • Pre-existing failure: test_collection_leaves_cuda_initialization_fork_safe fails on ROCm on master too. On

  • ROCm PyTorch the module-level torch.cuda.device_count() initializes the GPU runtime, so a forked child cannot use
    the GPU. It is unrelated to Triton.
  • Subchannel formats:

  • - gfx942 lists only int8. Triton emulates OCP FP8 in FP16 there, with no FP8 matrix cores, making the FP8 GEMMs
    1.4-6.9x slower than BF16. The row-scaled FP8 tile also needs 96 KB of shared memory against MI300X's 64 KB,
    so it fails with OutOfResources at realistic shapes.
    - gfx950 runs e4m3 and e5m2 on native FP8 matrix cores, so it lists all three formats.
    - Subchannel quantization is opt-in and slower than plain bf16 end to end on both GPUs. Its fused kernels are
    3.9-6.4x faster than the PyTorch reference fallback that an unlisted format gets.
    - The subchannel test file runs its GPU tests only when e4m3 is offered. So the INT8-only setting on MI300X is
    covered by the run with all formats offered, not by a default run.

    JSD Triton kernels on CUDA: a standalone script, run on the T1000.

  • Accuracy:

  • - Inputs: 33 rows; vocab sizes 7, 4,097 and 151,936; beta 0.1, 0.5 and 0.9; fp32, bf16 and fp16 logits.
    - In every case but one, Triton's output and gradient errors are within 2× of eager's. The exception is bf16 with
    near-identical distributions, vocab 7, beta 0.1: Triton's output error is 2.06× eager's.
    - That case is limited by fp32 cancellation in both paths. The absolute error is 6.5e-8 on a JSD of 1.35e-4, and
    the gradient errors are identical. In other near-identical cases Triton is slightly more accurate than eager.
  • Exact answers (vocab 151,936, fp32 and bf16), all pass:

  • - disjoint supports give H(beta) with zero gradient
    - identical inputs give 0
    - an all -inf row gives NaN with zero gradient
  • Non-contiguous input: bf16 logits[:, :-1] with vocab 151,936 is read in place, with output error 6.5e-7.

  • Speed and memory: forward plus backward, bf16, 1,024 tokens × vocab 151,936, beta 0.5, median of 5 runs.
  • | Path | Time | Peak memory |
    |---|---|---|
    | Triton | 20.7 ms | 594 MiB (the gradients themselves) |
    | Eager | 486.4 ms | 1,232 MiB |

    Triton is 23.5× faster and uses about half the peak memory.

    Fused RMSNorm with 8 warps, measured on the T1000 in bf16:

  • Results match eager in bf16 and fp16 from 2,049 to 32,768 wide.

  • Rows up to 16,384 wide run at 132-143 GB/s without register spills.

  • At 32,768 the forward runs at 115 GB/s and the input gradient, which spills a few registers, at 112 GB/s.

  • 16 warps gave 121 and 103 GB/s, so that tier was dropped.

    Fused RMSNorm tolerances, checked on the T1000 with the real kernels and with an exact PyTorch copy of the
    weight-gradient arithmetic:

  • Over 200 seeds for each accuracy shape and dtype, the old rules failed 1-3 seeds in 6 of 16 cases. The new rules

  • pass all 3,200 runs.
  • With each row's FP32 scale shifted by up to ±4 ULPs, as another GPU's summation order would, the old

  • weight-gradient rule failed 10-71% of the time in 5 of 16 cases. The new rule never failed.
  • Both rules catch the same injected bugs: a zeroed or scaled column, a dropped row, and a 0.8% error everywhere.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: delock Review duration: 6569m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9177"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%