Skip to content

[Triton/Gluon] Clamp the split-K heuristic so it cannot divide by zero - #5136

Merged
Boss2002n merged 2 commits into
mainfrom
satya/triton-clamp-splitk-heuristics
Sep 1, 2026
Merged

Boss2002n merged 2 commits into
mainfrom
satya/triton-clamp-splitk-heuristics

Conversation

@Boss2002n

Copy link
Copy Markdown
Contributor

No description provided.

get_splitk() / _get_splitk() shrink NUM_KSPLIT and BLOCK_SIZE_K by floor-dividing
by 4 (2 in some copies) while hunting for EVEN_K. Neither decrement was clamped:

  NUM_KSPLIT = NUM_KSPLIT // NUM_KSPLIT_STEP     # 2 // 4 == 0
  BLOCK_SIZE_K = BLOCK_SIZE_K // BLOCK_SIZE_K_STEP   # 32 // 4 == 8

A NUM_KSPLIT of 2 or 3 lands on 0, and the next line in the same loop is
triton.cdiv(K, NUM_KSPLIT) -- ZeroDivisionError. BLOCK_SIZE_K can fall to 8,
under the 16 that compute_splitk_params() clamps to everywhere else.

This is reachable from shipped configs, not theoretical: 45 GEMM config entries
carry NUM_KSPLIT of 2 or 3 (34 twos, 11 threes) across gfx942 and gfx950.

The helper is copy-pasted into seven modules; this clamps the six that the
gemm-basic wrapper-layer PR does not already cover:

  gemm/basic/gemm_afp4wfp4.py
  gemm/fused/fused_gemm_afp4wfp4_mul_add.py
  gemm/fused/fused_gemm_a8w8_blockscale_mul_add.py
  _triton_kernels/gemm/basic/gemm_a16wfp4.py
  _triton_kernels/gemm/batched/batched_gemm_a16wfp4.py
  _triton_kernels/gemm/batched/batched_gemm_afp4wfp4.py

(_triton_kernels/gemm/basic/gemm_a8wfp4.py is the seventh; it moves to the
wrapper layer in satya/triton-config-in-wrapper-gemm-basic and is clamped
there.)

Seven copies of one heuristic is its own problem -- worth collapsing into
gemm_config_utils once these are all in the same layer.
@Boss2002n
Boss2002n requested review from a team and a lite review from Copilot August 31, 2026 06: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:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
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 5136 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@github-actions github-actions Bot changed the title [Triton] Clamp the split-K heuristic so it cannot divide by zero [Triton/Gluon] Clamp the split-K heuristic so it cannot divide by zero Aug 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the host-side split-K “EVEN_K” heuristic used by several Triton GEMM wrappers/kernels by clamping heuristic decrements so they cannot produce invalid parameters (notably NUM_KSPLIT == 0, which would trigger a divide-by-zero on the next triton.cdiv(K, NUM_KSPLIT)).

Changes:

  • Clamp NUM_KSPLIT floor-division decrements to a minimum of 1 to prevent divide-by-zero during heuristic iteration.
  • Clamp BLOCK_SIZE_K floor-division decrements to a minimum of 16 to align with the minimum enforced by compute_splitk_params() elsewhere.
  • Add inline comments explaining why these clamps are required.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
aiter/ops/triton/gemm/fused/fused_gemm_afp4wfp4_mul_add.py Clamp split-K heuristic decrements to prevent NUM_KSPLIT going to 0 and BLOCK_SIZE_K falling below 16.
aiter/ops/triton/gemm/fused/fused_gemm_a8w8_blockscale_mul_add.py Same split-K clamp hardening in fused A8W8 blockscale mul-add wrapper.
aiter/ops/triton/gemm/basic/gemm_afp4wfp4.py Same split-K clamp hardening in basic AFP4WFP4 wrapper.
aiter/ops/triton/_triton_kernels/gemm/batched/batched_gemm_afp4wfp4.py Same split-K clamp hardening in batched AFP4WFP4 kernel-side helper.
aiter/ops/triton/_triton_kernels/gemm/batched/batched_gemm_a16wfp4.py Same split-K clamp hardening in batched A16WFP4 kernel-side helper.
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_a16wfp4.py Same split-K clamp hardening in basic A16WFP4 kernel-side helper.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 31, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@zufayu
zufayu requested review from a team and vgokhale September 1, 2026 01:16

@brunomazzottiamd brunomazzottiamd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can merge it! However, I have a request for the scope of another PR...

get_splitk function is duplicated across all six GEMM and fused-GEMM files!

The implementation is almost identical, with two minor differences:

  • gemm_afp4wfp4.py recomputes NUM_KSPLIT before returning.
  • batched_gemm_afp4wfp4.py contains leftover debug comments.

Notably, the copies in _triton_kernels/gemm/basic/gemm_a16wfp4.py and _triton_kernels/gemm/batched/batched_gemm_a16wfp4.py appear unused. Their wrappers already import get_splitk from another module.

Code duplication makes fixes to the split-K heuristic error-prone and has already allowed the implementations to drift slightly. Please extract the shared split-K calculation into a common utility module, update all callers to import it, and remove the local copies.

@Boss2002n
Boss2002n merged commit d58537b into main Sep 1, 2026
68 of 71 checks passed
@Boss2002n
Boss2002n deleted the satya/triton-clamp-splitk-heuristics branch September 1, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants