Skip to content

feat(gemm_a8w8_blockscale_bpreshuffle): route decode-M DeepSeek shapes to triton#4202

Merged
valarLip merged 1 commit into
mainfrom
triton-route-a8w8-blockscale-bpreshuffle
Jul 12, 2026
Merged

feat(gemm_a8w8_blockscale_bpreshuffle): route decode-M DeepSeek shapes to triton#4202
valarLip merged 1 commit into
mainfrom
triton-route-a8w8-blockscale-bpreshuffle

Conversation

@valarLip

Copy link
Copy Markdown
Collaborator

Summary

Add a libtype == "triton" dispatch branch to gemm_a8w8_blockscale_bpreshuffle
so the tuned CSV can route a given (M, N, K) to the triton preshuffle kernel,
and route the decode-M DeepSeek FP8 blockscale attention projections to triton
where it is measurably faster and not less accurate than the current asm/ck
kernels on gfx950 (MI35x).

What changed

  • Dispatch (aiter/ops/gemm_op_a8w8.py): new libtype == "triton" case.

    • Handled before the Y output buffer is allocated (triton allocates its own
      output) — no wasted m×n alloc on the triton path.
    • backend is taken from the CSV kernelName only when it is triton/gluon;
      anything else falls back to auto-detect instead of tripping triton's internal
      assert backend in ('triton','gluon').
  • Tuned configs (aiter/ops/triton/configs/gemm/*.json): per-shape gfx950
    triton configs for N=2048/16384/65536/8192, K∈{7168,1536}. The pre-existing
    N=2048 file is merged (kept its M_LEQ_256/any large-M buckets).

  • Routing CSVs: libtype=triton only on the M segments that win:

    shape (N,K) routed M note
    wqkv_a (2048,7168) 1,2,8,16,32,80 KSPLIT=4 deep-K split
    wq_b tp1 (65536,1536) 1,2,4,8
    wq_b tp4 (16384,1536) 1,4,8,16 ~1.4×, was untuned ck
    wq_b tp8 (8192,1536) 2,80,96,112,144 M=2 1.74× (was asm+memset)

    Large-M / compute-bound and the remaining tp8 M stay on asm/ck. The N=8192 rows
    live in the shared dsv3 file (V3/V4 same shape), so V3 benefits too.

How the M segments were chosen

Every M row of these shapes in the CSVs was measured with aiter's run_perftest
(same process, asm/ck vs triton) against a torch fp32 reference. A row is routed
to triton only if triton is valid (err < 0.05), ≥3% faster in steady state,
and not less accurate than asm/ck. No row was faster-but-less-accurate — in
the flipped rows triton's err is 0 while asm/ck carry fp8 rounding (~0.003–0.01).

Verification

  • Steady-state A/B (10 reps, warmup dropped): all flipped rows 1.09–1.74× faster
    (largest: 16384 ~1.4×, 8192 M=2 1.74×).
  • op_tests/test_gemm_a8w8_blockscale.py re-run on the V4 shapes: unified API
    routes to triton for the flipped M, all err == 0, and beats raw asm on every
    measured point.

Test plan

  • python op_tests/test_gemm_a8w8_blockscale.py -nk 2048,7168 8192,1536 16384,1536 65536,1536 -m 1 2 4 8 16 32 96 128 --ck_preshuffle 1
  • Confirm dispatch routes as expected via AITER_LOG_TUNED_CONFIG=1.

🤖 Generated with Claude Code

…s to triton

Add a `libtype == "triton"` dispatch branch to gemm_a8w8_blockscale_bpreshuffle
so the tuned CSV can route a shape/M to the triton preshuffle kernel. The branch
is handled before the Y output buffer is allocated (triton allocates its own
output), and the backend hint from kernelName is guarded to {triton,gluon}
(anything else -> auto-detect) so a stray kernelName can't crash the kernel.

Install per-shape tuned triton configs (gfx950) for the DeepSeek FP8 blockscale
attention projections and route only the M segments where triton is measurably
faster AND not less accurate than the current asm/ck kernels (steady-state
run_perftest, >=3% margin, err not worse):

  wqkv_a  N=2048  K=7168 : M=1,2,8,16,32,80        (KSPLIT=4, deep-K split)
  wq_b    N=65536 K=1536 : M=1,2,4,8               (tp1)
  wq_b    N=16384 K=1536 : M=1,4,8,16   ~1.4x      (tp4, was untuned ck)
  wq_b    N=8192  K=1536 : M=2,80,96,112,144       (tp8; M=2 1.74x, was asm+memset)

Large-M / compute-bound and the remaining tp8 M stay on asm/ck (triton loses).
N=8192 rows live in the shared dsv3 file (V3/V4 same shape), so V3 benefits too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@valarLip
valarLip requested a review from a team July 12, 2026 07:12
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4202 --add-label <label>

@valarLip
valarLip merged commit 95abba4 into main Jul 12, 2026
91 of 93 checks passed
@valarLip
valarLip deleted the triton-route-a8w8-blockscale-bpreshuffle branch July 12, 2026 16:15
valarLip added a commit that referenced this pull request Jul 16, 2026
…ing for DeepSeek MLA decode-M (#4264)

Re-measure a8w8 blockscale B-preshuffle triton routing cache-rotated (the #4202
tuning used a no-arg lambda that defeated perftest arg-rotation -> hot-cache
optimistic + suboptimal configs), and validate end-to-end via the op-test.

- op-test: add run_triton + triton columns; drop -m choices allowlist; fail-loud
- wqkv_a (N=2048,K=7168): fix #4202 hot-cache regression (BM4/8,KSPLIT4 -> BM16,
  KSPLIT8,stages3); route M in {1,2,4,8,16,32,48,64,80,128}, all err=0
- wo_b (N=7168): new routing tp1 K=16384 M<=64, tp4 K=4096 M<=32 (+new JSON);
  tp8 K=2048 unchanged (triton loses on shallow K)
- tuned CSVs: unify bw column to TB/s (asm/ck/cktile rows were GB/s)
- wq_b unchanged: #4202 routing verified correct cold-cache
@bingxche

bingxche commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Hi @valarLip , could you please take a look at this issue #4323? Thanks!

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