Skip to content

[Bug] Make blockscale split-K deterministic - #4581

Open
maeehart wants to merge 2 commits into
ROCm:mainfrom
maeehart:maeehart/fix-blockscale-splitk-determinism
Open

maeehart wants to merge 2 commits into
ROCm:mainfrom
maeehart:maeehart/fix-blockscale-splitk-determinism

Conversation

@maeehart

@maeehart maeehart commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Make CK and CKTile blockscale GEMM output deterministic for configured split-K exponents greater than 1.

splitK is an exponent, so KBatch = 1 << splitK. Exponents 2 and 3 create four and eight partial sums that are accumulated into the output with atomic adds. Their completion order can change BF16 or FP16 results between identical calls.

Both compiled entry points now validate the requested exponent, preserve values 0 and 1, and clamp larger valid exponents to 1. This retains the CSV-selected kernel and the bitwise-repeatable two-partition path instead of bypassing tuned dispatch.

The CK and CKTile tuning loops are also capped at exponent 1. Direct regression coverage requests exponents 2 and 3 from both entry points and compares 20 outputs against an exponent 1 reference.

This addresses the root cause behind vLLM #42240.

Validation

  • Focused blockscale codegen tests: 4 passed in 19.64s.
  • Before the patch, all four CK and CKTile exponent 2 and 3 cases reproduced nondeterminism on MI355X. Maximum absolute differences from the exponent 1 reference were 2.0, 2.0, 2.0, and 2.5.
  • After rebuilding both modules from the patched sources: 4 passed in 541.10s.
  • Ruff check, Ruff format check, Python compilation, and git diff --check passed.

Blockscale split-K uses atomic output accumulation. Four or more K partitions can complete in different orders, producing different BF16 or FP16 results for identical inputs.

Clamp CK and CKTile splitK exponents to 1 after validating the requested range. Keep tuned kernel selection and the two-partition path, cap future tuner candidates, and cover direct requests for exponents 2 and 3.

Co-authored-by: Cursor <[email protected]>
@github-actions

github-actions Bot commented Aug 5, 2026

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 4581 --add-label <label>

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 makes A8W8 blockscale GEMM deterministic when tuned configs request split-K exponents > 1 by clamping splitK to at most 1 in both CK and CKTile compiled entry points, and by preventing the tuner from exploring splitK >= 2. It also adds a regression test that exercises the previously nondeterministic tuned cases (requested exponents 2 and 3) and asserts bitwise-repeatable output versus a splitK=1 reference.

Changes:

  • Clamp runtime splitK exponent to <= 1 in CK and CKTile blockscale GEMM entry points to avoid order-dependent atomic accumulation for splitK >= 2.
  • Cap CK/CKTile tuning loops so they no longer generate candidates with splitK >= 2.
  • Add an op test that requests splitK exponents 2 and 3 (both backends) and verifies outputs match a splitK=1 reference across repeated runs.

Reviewed changes

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

File Description
op_tests/test_gemm_a8w8_blockscale_determinism.py Adds regression coverage ensuring requested splitK exponents 2/3 are effectively clamped to a deterministic path.
csrc/ck_gemm_a8w8_blockscale/gemm_a8w8_blockscale.cu Clamps splitK to <= 1 before computing KBatch for the CK blockscale entry point.
csrc/ck_gemm_a8w8_blockscale/gemm_a8w8_blockscale_cktile.cu Clamps splitK to <= 1 before computing KBatch for the CKTile blockscale entry point.
csrc/ck_gemm_a8w8_blockscale/gemm_a8w8_blockscale_tune.py Caps tuning search space to splitK <= 1 for both CK and CKTile tuning task generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zufayu
zufayu requested a review from yzhou103 August 6, 2026 02:34
@yzhou103

yzhou103 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

there are serveral config files have splitK=2/3 entries that were selected by the tuner precisely because they were faster. Clamping at the C++ layer silently degrades these to splitK=1 without re-tuning. We should either re-tune affected shapes or document the expected perf impact

Clamping tuned split-K exponents without changing the selected tile materially regresses affected shapes. Replace all 431 nondeterministic CK and CKTile rows with measured exponent 0 or 1 configurations and guard against future higher split-K entries.

Signed-off-by: Markus Hartikainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
@maeehart

maeehart commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

The concern is valid. I enumerated every tuned blockscale row with a stored splitK value of 2 or 3. There are 431 affected non-preshuffle CK and CKTile rows. The remaining rows use different preshuffle or ASM semantics and are not changed by this clamp.

Keeping the original tile and silently changing only KBatch regressed median operator device time by 24.95% on gfx950 and 39.48% on gfx942. The p95 regressions were 106.07% and 83.78%.

I retuned all 431 affected rows against deterministic exponent 0 and 1 candidates on matching gfx950/256-CU and gfx942/304-CU hardware. The raw exponent-1 and production-clamped paths differed by 8.12% at p95 on gfx950, so a new candidate is used only when it is more than 10% faster than the clamped original kernel. Otherwise the existing kernel is retained with an explicit exponent of 1. After selection, the median impact relative to the original higher split-K choices is 10.61% on gfx950 and 34.23% on gfx942.

The original exponent-2/3 choices produced multiple outputs for 384 rows. All 431 selected deterministic configurations passed the BF16-cast dequantized FP32 GEMM reference check and were bitwise stable across 20 calls.

082a56374 updates the four config files, adds a config guard against future CK and CKTile rows above exponent 1, and tests historical kernel names on both architectures. The C++ clamp remains as defense in depth. A deterministic workspace reduction for higher split-K can be evaluated separately.

@maeehart maeehart closed this Aug 9, 2026
@maeehart maeehart reopened this Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

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 4581 --add-label <label>

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 7, 2026
@zufayu
zufayu requested review from yifehuan and removed request for yzhou103 October 9, 2026 08:21
@zufayu
zufayu requested review from yzhou103 and removed request for yifehuan October 9, 2026 08:26
@zufayu zufayu assigned yzhou103 and unassigned yifehuan Oct 9, 2026
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

splitK=split_k,
)
else:
gemm_a8w8_blockscale_ck(x, weight, x_scale, w_scale, out, splitK=split_k)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we wire this regression into the standard op-test entry point? This file only defines pytest tests, while .github/scripts/aiter_test.sh invokes op tests with python3 "$file" and has no pytest dispatch for this file. Direct execution therefore exits 0 without checking the CSV split-K values, repeated-output determinism, or invalid split-K rejection. Please add a guarded pytest entry point (or an explicit CI pytest invocation) so the normal suite actually runs these regressions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants