Repository navigation
[Engine] Inkling 2: simpler decode kernel for cached experts - #284
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
…s a warp a row With MmvqSlots::lanes / MmvqIds::lanes set (Inkling 2 only, already set by Inkling2::load_geometry()), launch_slots() now takes native_mmvq_slots_lanes_kernel for native_mmvq.cu's formats IQ4_NL, Q8_0, Q2_0, MXFP4, Q4_0, Q2_K, Q4_K and IQ4_XS. Q5_0, Q3_K, Q5_K and Q6_K were slower with it (RTX 2070, 8 experts: Q3_K 2304 -> 2304 131 -> 181 us, Q5_K 94 -> 112, Q6_K 119 -> 152, Q5_0 1152 -> 2304 53 -> 59) and keep the block kernel (kSlotsLanesFaster). That is both native_mmvq_slots() (the host's list of cached experts) and native_mmvq_ids() (the card's picks, the path taken when a layer's routed experts are all in VRAM). Before, only IQ3_S and IQ3_XXS had a lanes kernel; these formats ran native_mmvq_slots_kernel, a block of 4 warps a row. A warp takes a row. Lane l does the work of the block's threads l, 32 + l, 64 + l and 96 + l, each into its own sum, and adds them in the order the block adds its warps' partials, then the same warp_sum: the same terms in the same order, so the same bits. No shared memory, no barrier, and no thread idle where the block's threads do not divide a row (an expert's 2304 and 1152 IQ4_NL values are 72 and 36 blocks for the block's 64 thread pairs). CUDA only; HIP launches are unchanged. Ported from our earlier engine in PR simplexai-labs#200 (commit a4fa510, "kernels: the cached experts' slots launches a warp a row, opt-in"), adapted to main's launch_slots(). poly_slots_lanes_test checks the lanes launch (host list and card picks) against the launch without lanes, to the bit, for 12 formats, 1 to 32 experts, n_in from one block to 4096 and row counts that leave a block's last warps empty; canaries after each slot's outputs catch rows left unwritten and writes past a slot. 0 of 660 checks fail on an RTX 2070 (sm_75) and an RTX 3060 (sm_86), with and without STRATA_SLOTS_WARP=1; compute-sanitizer memcheck clean. 8 experts per launch, RTX 2070: IQ4_NL 2304 -> 2304 118.2 -> 106.1 us, 1152 -> 2304 54.0 -> 51.2; Q8_0 1152 -> 2304 85.3 -> 62.7; Q2_0 1152 -> 2304 47.1 -> 38.5. RTX 2070 Super, decode after a 302-token prompt (--prompt-int8 setting), mean of 3 runs: IQ4_NL 43.0 -> 44.0 tok/s, UD-Q2_K_XL 46.2 -> 46.5. Greedy tokens and top-20 SAME as main with frozen experts (IQ4_NL, UD-Q2_K_XL; graphs and no graphs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
force-pushed
the
port/mmvq-lanes
branch
from
November 23, 2026 22:23
b428c59 to
e7de73c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
During decode, Inkling 2 multiplies the token by each cached expert with
native_mmvq_slots_kernel. That kernel uses 4 warps for each output row, adds their partial sums through shared memory, and leaves threads idle when a row's blocks do not divide evenly over the block's 64 thread pairs (an expert row of 2304 or 1152 IQ4_NL values is 72 or 36 blocks). Inkling 2 already asks for a lighter kernel (MmvqSlots::lanes), but only IQ3_S and IQ3_XXS had one.This PR adds that lighter kernel for IQ4_NL, Q8_0, Q2_0, MXFP4, Q4_0, Q2_K, Q4_K and IQ4_XS: a single warp computes each row, with no shared memory and no barrier. It adds the same terms in the same order, so the output is the same bits. It is CUDA only, there is no new flag, and HIP is unchanged. Decode on an RTX 2070 Super is +2.4% on IQ4_NL and +0.7% on UD-Q2_K_XL.
Decode tok/s, RTX 2070 Super 8 GB (Ryzen 5 3600XT), 302-token prompt + 256 tokens, mean of 3 interleaved runs:
Both sides ran with
--prompt-int8andSTRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1 STRATA_INK_PRESTAGE=1. The prompt does not use these kernels; its tok/s is in the details below as a control.Each run (tok/s)
Decode tok/s. Rounds in the order main/PR, PR/main, main/PR; each process serves one warm-up request first.
Prompt tok/s, the same runs (control):
An earlier run with the same setup, except that main ran first in every round:
Kernel times: 8 experts in one launch (µs, lower is better)
RTX 2070 8 GB (sm_75, not Super),
poly_slots_lanes_test --bench: 8 experts per launch, n_out 2304, best of 5 replays of a graph of 200 launches, four sets of weights in turn, measured before the per-format gate was added. "main" is the same launch withoutlanes. The formats marked "kept off" are slower with the new kernel, so this PR keeps the block kernel for them.Noise check: after the gate, the "kept off" formats run the same kernel in both columns, and the second column still reads 0.2–9.6% slower. So this bench's "lanes kernel" column, which is measured second, leans slow by up to about that much.
Related discussion
Split out of #200 at the maintainer's request (one optimization per PR). The kernel is #200's
native_mmvq_slots_lanes_kernel(commit a4fa510), adapted to main'slaunch_slots().Approach
slots.lanesis set,launch_slots()usesnative_mmvq_slots_lanes_kernel: 4 rows per block, one warp per row. This covers both the host's list of cached experts (native_mmvq_slots) and the card's own expert picks (native_mmvq_ids, used when all of a layer's routed experts are in VRAM).warp_sum. Each term is the sameF::apply(F::load(...)), in the same order, so the bits are the same.kSlotsLanesFasterkeeps the block kernel for them. Inkling 2's files do not use these formats for their experts.lanes(Engine::lane_slots_), so other models are unchanged. Under HIP,#if !defined(__HIPCC__)keeps the old launches.poly_slots_lanes_test.Validation
Passed:
poly_slots_lanes_test: 0 failures of 660 checks, both by default and withSTRATA_SLOTS_WARP=1.poly_iq3_lanes_test: ok.STRATA_GPU_EXPERTS=1900for UD-Q2_K_XL,850for IQ4_NL): SAME in 8 of 8 comparisons.strata-poly --tokens @ids302 --max-new 64 --top-probs 20, greedy,STRATA_FREEZE_EXPERTS=1. Token ids and top-20 lines are SAME for IQ4_NL and UD-Q2_K_XL, with default settings and with the settings above, with and without CUDA graphs (8 of 8 comparisons). This engine binary was built before the format gate. The gate only changes Q5_0 / Q3_K / Q5_K / Q6_K launches, which these files do not use: their experts are IQ4_NL + Q8_0, and Q2_0 / IQ1_S / IQ2_* / NVFP4 / MXFP4.poly_slots_lanes_test(new):ok: 0 failures of 660 checkson an RTX 2070 8 GB (sm_75) and an RTX 3060 (sm_86), both by default and withSTRATA_SLOTS_WARP=1(the warp kernel as the old path). Each slot's outputs are followed by canaries: every row must be written and no pad value touched. compute-sanitizer memcheck of--quick: 0 errors on both cards. After the format gate (commit b428c59), on the RTX 2070: 0 failures of 660 checks again.poly_iq3_lanes_test: ok, 0 failures (RTX 2070).CMAKE_CUDA_ARCHITECTURES="75;86;120"(on d2ecae2:"75;86"), targetsstrata-poly,poly_slots_lanes_test,poly_iq3_lanes_test.Failed:
Not run:
#if !defined(__HIPCC__), so HIP code is unchanged.Limits
native_mmvq()(poly: Inkling 2 Mini (inkling2 / inkling2_loop) #200 sent it through the slots path as well). That is not part of this PR.mmvq_slots_kernel's NVFP4 grid from poly: Inkling 2 Mini (inkling2 / inkling2_loop) #200 is a separate change.🤖 Generated with Claude Code