Skip to content

fix: load fused-SWA batch_id_per_token as int32, not int64 - #3793

Merged
valarLip merged 1 commit into
mainfrom
fix/flydsl-qknorm-swa-batch-id-int32
Jun 18, 2026
Merged

valarLip merged 1 commit into
mainfrom
fix/flydsl-qknorm-swa-batch-id-int32

Conversation

@valarLip

Copy link
Copy Markdown
Collaborator

Summary

The fused decode SWA scatter added in #3776 hardcoded an int64 buffer_load for batch_id_per_token. But the V4 decode producers are not uniformly int64 — the MTP-draft decode path reuses the int32 cu_seqlens_q slice as the per-token batch id. Feeding that int32 tensor tripped the wrapper's batch_id_per_token must be 1-D int64 check, so DeepSeek-V4-Pro MTP decode raised a TypeError before the first token → server never came up → the accuracy job timed out.

Fix

batch_id values are bounded by the batch size (≪ 2³¹), so int32 is always sufficient. Standardize on int32:

  • kernel loads batch_id at i32 width (drops the now-unneeded trunci)
  • wrapper validates int32; the not-kv_write dummy is int32
  • smoke test builds an int32 batch_id

No behavior change for the int64-free fast path; this only widens/realigns the SWA-scatter dtype contract.

The matching ATOM change (metadata buffer + sglang/vllm bridges → int32) is in ROCm/ATOM#1272.

Test plan

  • test_flydsl_qk_norm_rope_quant_kv_write (int32 batch_id) — bit-exact PASS
  • Cross-check vs the real swa_write, 24 configs (bs×mtp×pad) — all max_diff=0
  • End-to-end: DeepSeek-V4-Pro MTP3 GSM8K 3-shot → flexible-extract 0.9477 / strict 0.9484 (CI threshold 0.94); decode drained cleanly, no TypeError

The fused decode SWA scatter (added in #3776) hardcoded an int64
buffer_load for batch_id_per_token. The V4 decode producers are not
uniformly int64 though: the MTP-draft path reuses the int32
cu_seqlens_q slice as the per-token batch id. Feeding that int32 tensor
tripped the wrapper's "batch_id_per_token must be 1-D int64" check, so
DeepSeek-V4-Pro MTP decode raised a TypeError before the first token —
the server never came up and the accuracy job timed out.

batch_id values are bounded by the batch size, far below 2^31, so int32
is always sufficient. Standardize on int32: the kernel loads batch_id at
i32 width (dropping the trunc), the wrapper validates int32, the dummy
is int32, and the smoke test now builds an int32 batch_id.

Validated end-to-end: DeepSeek-V4-Pro MTP3 GSM8K (3-shot) flexible
0.9477 / strict 0.9484, above the 0.94 CI threshold; decode drained
cleanly with no TypeError.
@valarLip
valarLip requested review from a team and Copilot June 18, 2026 06:01
@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 3793 --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 updates the fused FlyDSL decode SWA scatter path in flydsl_qk_norm_rope_quant to treat batch_id_per_token as int32 (including kernel load width, Python-side validation, and test construction), fixing failures when callers provide an int32 batch-id tensor (e.g., MTP draft decode paths).

Changes:

  • Switch batch_id_per_token from int64→int32 in the FlyDSL kernel interface and load logic (removing the now-unneeded truncation).
  • Update the Python wrapper’s dtype validation and dummy argument allocation to int32.
  • Update the kv-write smoke/unit test to build an int32 batch_id_per_token.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
aiter/ops/flydsl/kernels/qk_norm_rope_quant.py Changes SWA-scatter batch-id dtype contract to int32 in both kernel and wrapper validation/dummies.
op_tests/test_flydsl_qk_norm_rope_quant.py Adjusts the kv-write test to provide int32 batch_id_per_token.

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

Comment on lines 1098 to +1101
if state_slot_mapping.dim() != 1 or state_slot_mapping.dtype != torch.int32:
raise TypeError("state_slot_mapping must be 1-D int32")
if batch_id_per_token.dim() != 1 or batch_id_per_token.dtype != torch.int64:
raise TypeError("batch_id_per_token must be 1-D int64")
if batch_id_per_token.dim() != 1 or batch_id_per_token.dtype != torch.int32:
raise TypeError("batch_id_per_token must be 1-D int32")
@valarLip
valarLip merged commit 8cfa77e into main Jun 18, 2026
20 checks passed
@valarLip
valarLip deleted the fix/flydsl-qknorm-swa-batch-id-int32 branch June 18, 2026 06:05
valarLip added a commit to ROCm/ATOM that referenced this pull request Jun 18, 2026
The fused decode SWA scatter loads batch_id_per_token at int32 width
(see ROCm/aiter#3793). The producers were int64, which raised
"batch_id_per_token must be 1-D int64" on the V4-Pro MTP decode path
(server failed to start -> accuracy job timed out).

Make all batch_id_per_token producers int32:
- v4_batch_id_per_token CpuGpuBuffer (model_runner path) int64 -> int32
- batch_id numpy sources (per-fwd + MTP draft) int64 -> int32
- sglang / vllm plugin bridge batch_id buffers + numpy sources -> int32

int32 indices are accepted by torch advanced-indexing (indexer meta) and
by the triton kernels (tl.load is dtype-agnostic); the explicit
.to(torch.int64) casts in csa_translate_pack / sglang remain and tolerate
int32 input. batch_id values are bounded by batch size, far below 2^31.

Validated end-to-end: DeepSeek-V4-Pro MTP3 GSM8K (3-shot) flexible
0.9477 / strict 0.9484, above the 0.94 CI threshold; decode drained
cleanly with no TypeError.
valarLip added a commit to ROCm/ATOM that referenced this pull request Jun 18, 2026
…1272)

* feat: fuse V4 decode SWA cache-write into qk_norm_rope_maybe_quant

Thread the SWA ring scatter through the qk_norm+rope bridge so the V4
decode path no longer launches a standalone swa_write per layer. When
swa_kv is provided, the post-norm/rope KV row is written into
swa_kv[slot, pos % cache_size, :] (slot = state_slot_mapping[
batch_id_per_token[t]]) inside the same kernel:

- flydsl path: fuses the scatter into the qk_norm launch (no extra
  kernel, no [T, D] KV HBM round-trip), via the new swa_kv /
  state_slot_mapping / batch_id_per_token args on flydsl_qk_norm_rope_quant.
- Triton fallback: emits the existing swa_write as a separate launch
  (driven by swa_cu_seqlens_q + state_slot_mapping) so both backends have
  identical side effects.

deepseek_v4.py decode deletes its standalone swa_write call and passes
the SWA args through the bridge instead; prefill is unchanged (still
writes its in-chunk SWA tail via swa_write after sparse_attn). BF16 only.

Requires the matching aiter change (ROCm/aiter#3776) for the flydsl
fused-scatter kernel support.

* ci: drop GLM-5-FP8 from benchmark matrix to stay under 256 cells

The nightly atom-benchmark grid had grown to 264 fully-expanded matrix
cells, exceeding GitHub Actions' hard limit of 256 configurations per
job. Remove the GLM-5-FP8 benchmark variant (superseded by GLM-5.2-FP8,
which is retained) and its workflow_dispatch checkbox (keeping it in sync
with the catalog prefixes). Matrix now resolves to 250 cells.

Accuracy validation (models_accuracy.json) and the dashboard color map
are left unchanged — GLM-5-FP8 stays covered there.

* fix: standardize V4 batch_id_per_token on int32 for fused SWA scatter

The fused decode SWA scatter loads batch_id_per_token at int32 width
(see ROCm/aiter#3793). The producers were int64, which raised
"batch_id_per_token must be 1-D int64" on the V4-Pro MTP decode path
(server failed to start -> accuracy job timed out).

Make all batch_id_per_token producers int32:
- v4_batch_id_per_token CpuGpuBuffer (model_runner path) int64 -> int32
- batch_id numpy sources (per-fwd + MTP draft) int64 -> int32
- sglang / vllm plugin bridge batch_id buffers + numpy sources -> int32

int32 indices are accepted by torch advanced-indexing (indexer meta) and
by the triton kernels (tl.load is dtype-agnostic); the explicit
.to(torch.int64) casts in csa_translate_pack / sglang remain and tolerate
int32 input. batch_id values are bounded by batch size, far below 2^31.

Validated end-to-end: DeepSeek-V4-Pro MTP3 GSM8K (3-shot) flexible
0.9477 / strict 0.9484, above the 0.94 CI threshold; decode drained
cleanly with no TypeError.
valarLip pushed a commit that referenced this pull request Jun 19, 2026
#3804)

* [FlyDSL] Port compress_attn kernels to gfx1250 (wave32)

Port CSA and HCA fused_compress_attn kernels from wave64 (CDNA) to
wave32 (RDNA4/gfx1250). Key changes: BLOCK_THREADS=32, VEC=16 for
D=512, generalized load/store paths for >dwordx4, shuffle width=32,
FP8 linear layout (no preshuffle), and extract_strided_slice API fix.
Adds gfx1250 dispatch routing in existing entry points and a dedicated
test file.

Co-Authored-By: Claude Opus 4 <[email protected]>

* [FlyDSL] Port qk_norm_rope_quant to gfx1250 (wave32)

Wave32 variant of the fused RMSNorm + GPT-J RoPE + FP8 quant kernel for
RDNA4/gfx1250. BLOCK_THREADS=32, VEC=16 for D=512, generalized load/store
paths (2x dwordx4 split for VEC>8), FP8 packing via VEC/4 dwords, and
butterfly shuffle width=32. BF16 mode verified on cmodel (H=16/64/128).

Co-Authored-By: Claude Opus 4 <[email protected]>

* [FlyDSL] Apply ruff format and lint fixes to gfx1250 kernels

Co-Authored-By: Claude Opus 4 <[email protected]>

* [FlyDSL] Fix black formatting for CI

Co-Authored-By: Claude Opus 4 <[email protected]>

* trigger CI re-run

Co-Authored-By: Claude Opus 4 <[email protected]>

* [FlyDSL] Port fused SWA kv_write scatter to gfx1250 qk_norm_rope_quant

Add the fused SWA cache-write path (batch_id_per_token as int32 per
upstream PR #3793) to the gfx1250 wave32 variant so the kernel can
scatter post-norm/rope KV rows into swa_kv[slot, pos%cache, :] in the
same launch, and fix the gfx1250 dispatch to forward the new params.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude Opus 4 <[email protected]>
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