Repository navigation
[Engine] Inkling 2: cached IQ3_S / IQ3_XXS experts with all lanes busy (CUDA) - #223
Open
okada-shogo wants to merge 3 commits into
Open
okada-shogo wants to merge 3 commits into
okada-shogo wants to merge 3 commits into
Conversation
The cached experts' slots launches of IQ3_S and IQ3_XXS (merbanan's AD-IQ3_S file has IQ3_S gate|up) run mmvq_slots_kernel, a row a warp. A 2304-value row is 72 calls, so the third pass keeps 8 of 32 lanes busy; its grid lookups go to global memory, and its sign bytes come from __vcmpne4 / __vsub4, several instructions each on Turing. With MmvqSlots::lanes / MmvqIds::lanes (set from Engine::lane_slots_, which only Inkling2 turns on; CUDA only) a warp takes 4 rows as one run of 4 x 72 calls, lane p taking call 32 i + p. A row's calls c = L (mod 32) all land on lane (L + r C) mod 32 in increasing c, so that lane holds the old kernel's lane-L sum term for term; a shuffle moves it back to lane L before the same warp_sum, and a row's sum has the old kernel's bits. The grid is read from shared memory, and the sign bytes come from a multiply (nibble bit k to byte k) and xor + add: the same integers (no grid byte is 0, so no byte carries). The shared-memory grid and the multiply for the signs are merbanan's ideas (his inkling2-turing decode kernels in Strata); the code is our own. STRATA_IQ3_LANES=0 (or STRATA_OLD_IQ_MMVQ=1) keeps mmvq_slots_kernel. Other formats, other families, HIP and Metal are unchanged. Class: same bits. poly_iq3_lanes_test (new, CUDA, random blocks): 24 byte compares (IQ3_S and IQ3_XXS, 1-8 experts, short last rows, n_in 256-2304) of the lanes launch against native_mmvq, the picks launch and the launch without lanes; --bench times the 8-expert gate|up launch with and without lanes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/check's docs step and tools/test_settings_register.py failed: the engine reads STRATA_IQ3_LANES (=0 keeps mmvq_slots_kernel for Inkling 2's IQ3_S / IQ3_XXS cached experts) and it was not in terminal/data/settings-register.json. Add its entry as python tools/settings_register.py writes it, with status rollback (on by default, =0 goes back), owner kernels/cuda and a note, and leave every other entry as it was (as fd20bfc did). docs/SETTINGS.md is regenerated with --docs; it also gains the three rollback switches fd20bfc registered on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the lane kernel turned off, every case compared mmvq_slots_kernel with itself and passed without testing anything. Return 77 (skip) and say why instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
marked this pull request as ready for review
November 23, 2026 01:47
okada-shogo
added a commit
to okada-shogo/PolyStrata
that referenced
this pull request
Nov 23, 2026
…experts with all lanes busy (CUDA) # Conflicts: # docs/SETTINGS.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
For NVIDIA cards that hold most or all experts in VRAM, with an IQ3_S or IQ3_XXS file (for example merbanan's
AD-IQ3_S file, whose expert gate|up matrices are IQ3_S). It makes the decode kernel for cached experts (experts kept
in VRAM) faster. Same bits.
Decode +6.5% after 302 tokens and +6.1% after 8K on a card that holds every AD-IQ3_S expert; prompt unchanged.
On by default for Inkling 2 on CUDA;
STRATA_IQ3_LANES=0keeps the old kernel.What it changes, in plain words: these experts go through
mmvq_slots_kernel, where one warp (32 GPU threads,called lanes) takes one row. That wastes time in three ways:
lanes busy.
With this PR a warp takes 4 rows as one run of calls (4 x 72 calls = 9 full passes), the grid sits in shared memory,
and the signs are made with a multiply and xor + add. The bits stay the same: each row's partial sums go back to the
lane that held them before, then the same
warp_sumruns.Speed in tokens per second (tok/s), higher is better, mean of 3 interleaved runs. RTX 2080 Ti 22 GB (sm_75) + EPYC 7K62, AD-IQ3_S, fp16 KV, default settings (all 3072
experts in VRAM in every run), one
--serverequest per run. main d1f711e vs this PR 0211ccf.Prompt tok/s, higher is better:
Decode tok/s, higher is better:
Each run (tok/s)
Prompt tok/s, higher is better, each run:
Decode tok/s, higher is better, each run:
On an 8 GB card the change is within noise (decode 21.1-21.5 tok/s both ways, AD-IQ3_S with 35% of expert calls
from VRAM), because most of a token's time there is CPU experts; see Validation.
Kernel time, in microseconds (µs), lower is better. What it times: one call of the cached-expert kernel for 8 experts' gate|up products (2304 inputs -> 2304 outputs each),
poly_iq3_lanes_test --bench, Quadro RTX 4000 8 GB (sm_75):The same calls as weight bytes read per second, in GB/s, higher is better:
Related discussion
Split out of #200, as the maintainer asked there:
#200 (comment)
Independent of the other split PRs (based on main, not stacked).
Approach
Engine::lane_slots_, set inInkling2::load_geometry()), CUDA only. HIP, Metal, otherformats and other model families are unchanged.
STRATA_IQ3_LANES=0keeps the old kernel. It is registered interminal/data/settings-register.jsonas a rollback switch (one entry added by hand, docs/SETTINGS.md regenerated).
c = L (mod 32) all land on lane (L + r C) mod 32, in increasing c: that lane's sum is the old lane L's sum, term for
term. One
__shfl_syncmoves it back, then the samewarp_sum.(nibble * 0x00204081) & 0x01010101puts bit k in byte k;(g ^ (ones * 0xFF)) + onesgives the same bytes as__vsub4(g ^ m, m)(no grid byte is 0, so no carry). The loop is not unrolled (unrolling let nvcc contract the sum).poly_iq3_lanes_test(CUDA, random blocks, no model): 24 byte compares againstnative_mmvq(), the pickslaunch and the launch without lanes;
--benchtimes 8 experts. It skips (77) underSTRATA_IQ3_LANES=0, where itwould compare the old kernel with itself.
Validation
Passed:
e2e-ab.sh(main and this PRinterleaved, order reversed every other round, one warm-up;
strata-poly --serve --prompt-cache 0 --conversation-cache-mib 0 --kv fp16 --max-context 32768, 302 + 256, 2,048 + 1 and 8,192 + 256 tokens; both buildsCUDA 12.9,
75;86, at d1f711e and 0211ccf).strata-polyandpoly_iq3_lanes_testbuild at the first commit;poly_iq3_lanes_testagain at the head.python3 tools/settings_register.py --check: exit 0;python3 tools/test_settings_register.py: OK;python3 tools/check --only docs: 6 of 6 (it failed before the register commit:STRATA_IQ3_LANESwas not registered).test's skip under
STRATA_IQ3_LANES=0):poly_iq3_lanes_test: 24 of 24 byte compares, 0 values differ (ok: 0 failures).--bench: the table above.STRATA_FREEZE_EXPERTS=1 --kv-whole --cpu-share 0 --expert-swaps 0), 302-tokenprompt, 64 greedy tokens,
--top-probs 20, fp16 cache, 32K, 1,110 of 3,072 experts in VRAM in every run, orderoff / on / off / on: the ids and all 64 top lines are identical in all four runs.
Each run on the 8 GB card (tok/s)
Quadro RTX 4000 8 GB, AD-IQ3_S, expert placement fixed at load (1,110 of 3,072 experts in VRAM), the old kernel (
STRATA_IQ3_LANES=0) against the new one in the same build. Prompt tok/s, higher is better, each run:STRATA_IQ3_LANES=0(old kernel)Decode tok/s, higher is better, each run:
STRATA_IQ3_LANES=0(old kernel)Order: off, on, off, on.
Failed: none observed.
Not run:
#if !defined(__HIPCC__), butiq_kernels.cuis also compiled for HIP, so a HIP build is still owed.Limits
Credits: the shared-memory grid and the multiply for the signs are merbanan's ideas (his inkling2-turing decode kernels in Strata). The code is our own.
🤖 Generated with Claude Code