Skip to content

perf(ds41): batch-invariant verify keeps the MoE kernel where it matches decode - #815

Merged
davide221 merged 1 commit into
mainfrom
fix/ds41-verify-mmid-one-launch
Oct 6, 2026
Merged

davide221 merged 1 commit into
mainfrom
fix/ds41-verify-mmid-one-launch

Conversation

@davide221

@davide221 davide221 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#813 cost DS4.1 about 10% of code decode on an R9700 + Ryzen AI Max+ PRO 495 (--profile ds41-gorgon). The cause is batch-invariant verify: it ran every drafted token through the single-token MMVQ path, one launch per token. That also replaced the multi-token MoE kernel, and its gfx1151 expert prefetch, for formats where the MoE kernel already matches decode bit for bit.

This PR keeps the exactness and gets the speed back. Code decode goes from 44.8 to 49.0-49.4 tok/s, and the output text is byte-identical.

Changes

  1. The MoE kernel stays where it matches decode. The MoE kernel computes each (token, row) exactly like the generic single-column kernel with one wave per row: same per-lane K walk, one warp reduction. mmvq_moe_matches_single_column keeps it in batch-invariant mode when the decode launch is that kernel and the batch fits the MoE kernel's per-type width. In practice that covers:
    • ROCmFP2 and MXFP4 on both GPUs;
    • Q2_K and Q8_0 on the gfx1151 table.
  2. Everything else gets the single-token kernel in one launch. That means multi-wave tables, the gfx1151 fixed-K ROCmFP kernels, the FP4 unroll, and the multi-row IQ2/IQ3 kernels on AMD. The tokens become the sample dimension of the single-token launch, and each block reads its own token's expert ids (ids_tokenwise_samples, which the kernel already had). This one launch replaces one launch per token. Expert-bias fusions keep the per-token loop, because the kernel offsets biases by sample.
  3. Shared predicates. mmvq_rocmfp2_fixed_k / mmvq_rocmfp3_fixed_k now hold the gfx1151 fixed-K shapes, used by both the dispatcher and the new check, so the two can't drift apart.
  4. Test coverage. test_ds41_mmid_width_invariance gains ROCmFP2 (type 107, the ROCMFP2S experts) as a contract format. It is registered with ctest at 5 tokens, the DSpark verify width, and runs in the ROCm GPU job on both runners.

Measurements

R9700 32 GB (PCIe Gen3 x4) + Ryzen AI Max+ PRO 495 192 GB, --profile ds41-gorgon, ROCMFP2S, Q2_K-expert DSpark drafter, greedy, two fresh servers per build:

main (ab97ed2) #811 head this PR
Code decode (36 tokens, 256 out) 44.7-44.9 tok/s 49.5 49.0-49.4
2K decode (2,027 tokens, 256 out) 30.6-31.0 tok/s 32.5 32.5-32.6
Output text (md5 of code / 2K) 6e212c26 / 0c821d46 same same

LUCE_DS4_TP_HEAD4_TAIL2=1 (#813's other default change, the route order) made no difference: 44.7 vs 44.9.

Validation

Check Result
test_ds41_mmid_width_invariance 5 64 on gfx1201 and gfx1151 every contract case identical in batch-invariant mode (IQ2_XXS, IQ2_XS, IQ3_XXS, Q2_K, MXFP4, ROCmFP2, plus the dense products)
Same test without batch invariance, 5 tokens MoE kernel identical for ROCmFP2 and MXFP4 on both GPUs; IQ formats differ (max 0.04-0.2), and Q2_K and Q8_0 differ slightly on gfx1201. These are the cases that now take the single-token kernel.
End-to-end outputs, two servers byte-identical to main and to the #811 head
Build, HIP gfx1151;gfx1201 pass

🤖 Generated with Claude Code

Review in cubic

…hes decode

#813 made batch-invariant MUL_MAT_ID (the DS4.1 DSpark verify) run every token
through the single-token MMVQ path, one launch per token, so verify would match
decode bit for bit. That also replaced the multi-token MoE kernel (and its
gfx1151 expert prefetch) for formats where the MoE kernel already matched
decode, and cost 10% of code decode on an R9700 + Ryzen AI Max+ PRO 495 with
--profile ds41-gorgon (49.5 -> 44.8 tok/s, identical text).

The MoE kernel computes each (token, row) like the generic single-column kernel
with one wave per row: same per-lane K walk, one warp reduction. Batch-invariant
MUL_MAT_ID now keeps it when the decode launch is that kernel and the batch fits
the MoE kernel's per-type width (mmvq_moe_matches_single_column): ROCmFP2,
MXFP4, and on the gfx1151 table Q2_K and Q8_0. Multi-wave tables and the
specialized single-column launches (gfx1151 fixed-K ROCmFP, the FP4 unroll, the
multi-row IQ kernels on AMD) still take the single-token kernel, now in one
launch: the tokens become the sample dimension and each block reads its token's
expert ids (ids_tokenwise_samples). Expert-bias fusions keep the per-token loop,
since the kernel offsets biases by sample.

test_ds41_mmid_width_invariance gains ROCmFP2 (type 107) as a contract format,
is registered with ctest at five tokens (the DSpark verify width) and runs in the
ROCm GPU job.

Measured (R9700 + Ryzen AI Max+ PRO 495, ds41-gorgon, ROCMFP2S, two fresh
servers each): code decode 44.7-44.9 -> 49.0-49.4 tok/s, 2K decode 30.6-31.0 ->
32.5-32.6, outputs byte-identical. test_ds41_mmid_width_invariance 5 64: every
contract case identical in batch-invariant mode on gfx1201 and gfx1151.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@davide221
davide221 merged commit e6f643d into main Oct 6, 2026
14 of 15 checks passed
davide221 added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 7, 2026
@davide221
davide221 deleted the fix/ds41-verify-mmid-one-launch branch October 12, 2026 07:37
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.

1 participant