Skip to content

[Engine] Inkling 2 Mini: several requests at once (batch slots, parallel) - #226

Merged
VecSzn merged 15 commits into
simplexai-labs:mainfrom
okada-shogo:port/batch-slots
Nov 23, 2026
Merged

VecSzn merged 15 commits into
simplexai-labs:mainfrom
okada-shogo:port/batch-slots

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Rebased onto main 3f36e17 (2026-11-23), after main merged #214, #217, #233, #240, #243, #245, #246, #229 and #230. The batch slots' kernels now sit beside main's new attention code (Q8_0 caches, the shorter decode-score kernel, STRATA_KV_INT8), and one new commit refuses --batch on AMD and with --kv q8_0, whose paths the slots' _rows kernels do not cover. Checked on an RTX 2070 8 GB after the rebase: the kernel tests pass, one request gives byte-identical output to main (IQ4_NL with and without experts on the card, UD-Q2_K_XL), and --check-batch with 4 and 6 slots and --check-stagger with 4 give every token as it is alone. The resolution follows the combined branch's (1ef2e7e13).

Problem and result

Inkling 2 Mini refuses --batch today (inkling2.cpp: "runs one sequence"), so the server answers one request at a
time and setup writes "parallel": 1. This PR lets it take batch slots like the other strata-poly models: up to 16
slots in all (--batch 1 to 15; the server uses up to 8, docs/BATCHING.md), a token of each slot in one step().

  • One request (--batch 0, "parallel": 1) runs the same launches as main: same tokens and top-5 probabilities.
  • Each slot writes the tokens it writes alone (--check-batch, every token, 2 to 6 slots).
  • Not with --draft-model; not on Metal yet (refused there; setup keeps "parallel": 1 on a Mac).

Throughput (tok/s, all chats together, higher is better). The server (terminal/serve), 300 tokens a chat,
greedy, fp16 cache, 32K context. Each cell is the mean of 3 rounds. main answers one request at a time, so every row is
compared with main's 1-chat rate.

RTX 2070 Super 8 GB, main = 5b080f3 (re-measured after the rebase: main now has #209's Turing flash attention and
opt-in int8 prompt products), this PR alone = 3f38683. Throughput, tok/s, mean of 3 rounds:

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 39.8 39.7 −0.2%
RTX 2070 Super 8 GB IQ4_NL 2 chats, "parallel": 2 40.0 48.2 +20.7%
RTX 2070 Super 8 GB IQ4_NL 4 chats, "parallel": 4 40.0 52.7 +31.8%
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 4 40.0 37.9 −5.3%
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 1 chat, "parallel": 1 41.0 40.9 −0.2%
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 2 chats, "parallel": 2 41.0 51.1 +24.6%
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 4 chats, "parallel": 4 41.0 57.6 +40.6%
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 1 chat, "parallel": 4 41.0 41.6 +1.4%

Quadro RTX 6000 24 GB, measured before the rebase: main = d1f711e, this PR alone = its head then. Throughput, tok/s,
mean of 3 rounds:

Card Model Measure main this PR alone Change
Quadro RTX 6000 24 GB IQ4_NL 1 chat, "parallel": 1 60.3 60.4 +0.1%
Quadro RTX 6000 24 GB IQ4_NL 2 chats, "parallel": 2 60.3 78.2 +29.7%
Quadro RTX 6000 24 GB IQ4_NL 4 chats, "parallel": 4 60.3 94.7 +57.0%
Quadro RTX 6000 24 GB IQ4_NL 8 chats, "parallel": 8 60.3 103.3 +71.2%
Quadro RTX 6000 24 GB IQ4_NL 1 chat, "parallel": 4 60.3 61.8 +2.4%
Quadro RTX 6000 24 GB UD-Q2_K_XL 1 chat, "parallel": 1 58.7 58.7 -0.1%
Quadro RTX 6000 24 GB UD-Q2_K_XL 2 chats, "parallel": 2 58.7 77.7 +32.3%
Quadro RTX 6000 24 GB UD-Q2_K_XL 4 chats, "parallel": 4 58.7 92.6 +57.7%
Quadro RTX 6000 24 GB UD-Q2_K_XL 8 chats, "parallel": 8 58.7 101.8 +73.4%
Quadro RTX 6000 24 GB UD-Q2_K_XL 1 chat, "parallel": 4 58.7 60.2 +2.6%

The 24 GB card holds every expert in VRAM in every run (3,072 of 3,072). On the 8 GB card decode is bound by the CPU's
experts, and the slots' caches take VRAM from the expert cache (IQ4_NL: 921 experts at 1 slot, 794 at 2, 649 at 4;
UD-Q2_K_XL: 1,986, 1,733, 1,442): that is why it gains less there, and why one IQ4_NL chat at "parallel": 4 is 5.3% slower. One chat at "parallel": 1 runs at main's speed
(same tokens as main). Its IQ4_NL row is a second run with main and this PR alternating, 5 fresh servers each, because
the first run (main's servers first) gave 40.0 against 39.3 (−1.8%; each round below). The other rows compare with
that first run's main, 40.0.

Each run (tok/s)

RTX 2070 Super 8 GB, main = 5b080f3, tok/s, each round:

Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 main 40.0 40.0 39.9
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 this PR alone 39.4 39.2 39.2
RTX 2070 Super 8 GB IQ4_NL 2 chats, "parallel": 2 this PR alone 48.2 48.9 47.6
RTX 2070 Super 8 GB IQ4_NL 4 chats, "parallel": 4 this PR alone 52.7 53.3 52.0
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 4 this PR alone 38.5 36.8 38.3
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 1 chat, "parallel": 1 main 40.9 41.1 41.0
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 1 chat, "parallel": 1 this PR alone 40.8 41.0 41.0
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 2 chats, "parallel": 2 this PR alone 50.9 51.1 51.3
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 4 chats, "parallel": 4 this PR alone 57.8 57.5 57.6
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) 1 chat, "parallel": 4 this PR alone 41.3 41.8 41.6

RTX 2070 Super 8 GB, IQ4_NL, 1 chat at "parallel": 1, the alternating run (main, this PR, main, ...), tok/s; each run is one fresh server, the mean of its 3 rounds:

Card Model Measure Build Run 1 Run 2 Run 3 Run 4 Run 5
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 main 39.8 39.5 40.0 40.3 39.4
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 this PR alone 39.4 40.0 39.3 39.9 40.1

Quadro RTX 6000 24 GB, main = d1f711e, tok/s, each round:

Card Model Measure Build Run 1 Run 2 Run 3
Quadro RTX 6000 24 GB IQ4_NL 1 chat, "parallel": 1 main 60.4 60.3 60.3
Quadro RTX 6000 24 GB IQ4_NL 1 chat, "parallel": 1 this PR alone 60.4 60.4 60.4
Quadro RTX 6000 24 GB IQ4_NL 2 chats, "parallel": 2 this PR alone 78.2 78.2 78.3
Quadro RTX 6000 24 GB IQ4_NL 4 chats, "parallel": 4 this PR alone 94.4 94.8 95.0
Quadro RTX 6000 24 GB IQ4_NL 8 chats, "parallel": 8 this PR alone 103.3 103.6 102.9
Quadro RTX 6000 24 GB IQ4_NL 1 chat, "parallel": 4 this PR alone 61.9 61.9 61.5
Quadro RTX 6000 24 GB UD-Q2_K_XL 1 chat, "parallel": 1 main 58.7 58.7 58.8
Quadro RTX 6000 24 GB UD-Q2_K_XL 1 chat, "parallel": 1 this PR alone 58.8 58.5 58.8
Quadro RTX 6000 24 GB UD-Q2_K_XL 2 chats, "parallel": 2 this PR alone 77.6 77.8 77.7
Quadro RTX 6000 24 GB UD-Q2_K_XL 4 chats, "parallel": 4 this PR alone 92.0 92.9 93.0
Quadro RTX 6000 24 GB UD-Q2_K_XL 8 chats, "parallel": 8 this PR alone 101.3 102.1 102.1
Quadro RTX 6000 24 GB UD-Q2_K_XL 1 chat, "parallel": 4 this PR alone 60.3 60.2 60.2

Per-chat rates at 8 chats on the 24 GB card: 13.0 to 15.8 tok/s. 8 GB card, 4 chats (5b080f3 run): IQ4_NL 13.6 to
15.5 tok/s a chat, UD-Q2_K_XL 15.1 to 16.9; step recordings capped at 484, with older ones dropped and made again
(385 dropped in each run), none left unrecorded.

Identity.

Check Card Result
One request, main vs this PR, --batch 0: tokens + top-5 of 48-64 steps; IQ4_NL and UD-Q2_K_XL, expert cache frozen, all experts on the CPU, --no-graphs, small-card args RTX 2080 Ti 11 GB, RTX 2070 8 GB all same
--check-batch 2, 3, 4, 6 slots; --check-stagger 2 and 4 slots, with and without graphs; small-card args without --tail-skip; UD-Q2_K_XL RTX 2080 Ti 11 GB, RTX 2070 8 GB every token the same as alone
--check-stagger 4 slots with a cap of 120 step recordings: 372 dropped, made again RTX 2070 8 GB every token the same as alone
--check-stagger 4 slots with every 3rd step recording failed on purpose: unrecorded runs (3,360) plus heavy re-recording, since each failure also drops the other step recordings RTX 2070 8 GB every token the same as alone
--check-batch 4 --tail-skip 4 both differs (expected, see Limits)

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

  • step() takes Inkling 2's rows in one head (batch_heads()): the dense products, mixes, norms and router run once
    for all rows. What reads or writes a sequence's own state (K/V convolutions, cache stores, attention, the output
    convolutions) uses the one-token kernel code with each row's own slot, in one launch for all rows (_rows kernels).
  • Three bugs found by the first test runs, fixed here:
    • A step of one row was routed on the card for the doorbell, but step() never rang it, so moe_card() read an
      unfilled table ("illegal memory access"). step() now rings and answers the doorbell as run() does.
    • A token alone is routed on the card (expf), a step's rows on the host (std::exp), which can differ in the last
      bit. Where card_moe(1) routes a token alone on the card, the rows now take the card's picks too.
    • Step recordings are keyed by their rows' sequences, so they grew without end until cudaGraphInstantiate ran out
      of memory (4 chats on 8 GB). At most a fixed count is held now (512 on an 8 GB card, about 128 MiB; least
      recently used dropped first). A recording the card has no memory for drops the step recordings and tries again,
      and a step that still cannot be recorded runs unrecorded.
Commit by commit
  1. Two slots: step() walks the layers in next_layer() order, as run() does (other families: il + 1). New
    hook tail_by_rows() (default false, only Inkling 2 sets it). tail_key() includes the bound sequence.
  2. --check-stagger (test tool, every family): with --check-batch K, prompts and answers of different lengths,
    sequences that join between steps. Changes no engine path.
  3. Up to 16 slots in one launch each: ink_qkv_rows(), ink_attend_rows(), ink_conv_add_rows() call the
    one-token kernel bodies with a row per blockIdx.y and each row's own pointers.
  4. Setup and docs: "one_request": "mac", so --parallel N works on Linux/Windows; docs/BATCHING.md and
    docs/models/inkling.md.
  5. A step of one row rings the doorbell (bell_on() is false for other families and for more rows).
  6. The rows take the card's picks where a token alone does (route_card(), h_wts_; only with the doorbell).
  7. Step recordings bounded (superseded by 8).
  8. Step recordings held to a count (STRATA_POLY_STEP_GRAPHS; a line on every drop). cudaGraphExecDestroy()
    gives no memory back to cudaMemGetInfo(), so 7's byte budget did not hold. record() (run()'s and step()'s
    other recordings) drops the step recordings and retries on an out-of-memory too; only where step recordings
    exist. STRATA_POLY_STEP_RECORD_FAIL=N is a test hook for the unrecorded path.
  9. The rows take the card's picks only under all of card_moe(1)'s conditions (no --expert-gpu, the slot table,
    a layer at a time where L.card is not 0).
  10. --batch up to 15: 32 rows would reach the prompt batch's kernels. --check-stagger's shift is clamped.
  11. Setup warns when --parallel meets --tail-skip; the docs say so.
  12. A layer card_moe() has not tried yet counts as the card's only where its types have the card's pick kernels
    (as moe_card() would find).
  13. Setup's --tail-skip warning reads the finished config ("parallel" kept from the config before too), and
    is not given where the family answers one request at a time.

Validation

Passed:

  • CUDA 12.9 build, sm_75, at this branch's head (11dfb28). The GPU runs below are of f4bfc38; commits 12-13 change
    a rule no current file reaches (12) and setup's text (13).
  • cd terminal && ../.venv/bin/python -m unittest tools.test_setup_* (all 90 setup test modules) serve.test_parallel: 1,410 tests OK, 1 skipped, at 11dfb28.
  • One request vs main and --check-batch (identity table): strata-poly --tokens @ids302.txt --max-new 64 --top-probs 5 --cpu-share 0 --kv fp16 with STRATA_FREEZE_EXPERTS=1 (main vs PR), and --batch K --check-batch K [--check-stagger] (slots), RTX 2080 Ti 11 GB and RTX 2070 8 GB, sm_75 binaries. --batch 16 is refused.
  • Server throughput (table above): terminal/serve/server.py with "parallel" 1/2/4/8 and as many concurrent chats, 3 rounds after a warm-up request; Quadro RTX 6000 24 GB (Xeon Gold 6244; main d1f711e) and RTX 2070 Super 8 GB (Ryzen 5 3600XT; main 5b080f3 vs 3f38683, local CUDA 12.9 sm_75 builds, bconc-rm.sh logs ~/inkling-work/batch-port/rm226-iq4/, rm226-q2l/, rm226-alt/ (the alternating 1-chat run), all rc=0).
  • compute-sanitizer memcheck (head f5f898d), RTX 3090 24 GB (rented, sm_86 build, CUDA 12.9.1, compute-sanitizer
    2025.2.1), IQ4_NL with all 3,072 experts in VRAM: compute-sanitizer --tool memcheck strata-poly --tokens @ids64.txt --batch K --check-batch K --check-stagger --max-context 256 --prompt-batch 64 --kv fp16, K=4 with --max-new 8
    (prompts of 16/16/16/64 tokens) and K=2 with --max-new 4. Both rc=0, every sequence the same as on its own,
    ERROR SUMMARY: 0 errors (243 s and 92 s; earlier runs on the 8 GB card timed out).

Failed (first runs, fixed by commits 5-9 and passed above): --check-batch 4 and 6 differed after some tokens;
--check-stagger and the server at "parallel" 2 and 4 stopped with "illegal memory access"; 4 chats at
"parallel" 4 stopped with cudaGraphInstantiate: out of memory.

Not run:

  • HIP build: main's HIP build of inkling2.cu already fails (10 __ldcs / __ldcg errors in code this PR does not touch; fixed by [Engine] build Inkling 2's DSpark screen on HIP #206). engine.cpp with this PR builds for HIP; a full HIP build waits for [Engine] build Inkling 2's DSpark screen on HIP #206. No AMD run.
  • Metal (refuses --batch for this model); FP8 caches (Ampere+); cards other than sm_75 (except the memcheck run above).
  • A kernel test of the _rows kernels against the one-token launch, bit for bit; the end-to-end --check-batch covers them.

Limits

Credits: design ported from our own engine's batch slots (#200), onto VecSzn's engine and his step() machinery
(batch_heads(), rows_heads, next_layer()) and his doorbell. The fixes in commits 8-11 follow an independent
review.

🤖 Generated with Claude Code

okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
…eem to take

The budget of 45be289 summed what cudaMemGetInfo() lost across each
step recording's instantiation and took the recordings' average off for
each one dropped.  But cudaGraphExecDestroy() gives the driver's memory
back to no cudaMemGetInfo(), and later recordings take the memory it
kept with no loss shown: in the review's replay of the algorithm (an
8 MiB budget, new keys, 20-kernel graphs on the RTX 2070 Super) the sum
stayed at 6 MiB while the card gave 128 MiB and more.  A fixed number
held stayed flat there (50 MiB after 10 cycles of drop and make).

- record_step() holds at most step_cap_ step recordings: 4 a MiB of a
  64th of the card, 256 to 1,024 (512 on an 8 GB card, about 128 MiB at
  the 220-250 KiB a recording measured), or STRATA_POLY_STEP_GRAPHS.
  Past it the ones launched longest ago go (never the step's own), down
  to three quarters.  The size line ("N held, X MiB, Y KiB each") is
  printed only before the first drop, where the sum is right.
- Every drop prints a line: how many, how many held, and the totals made,
  dropped and run unrecorded.
- record() (run()'s and step()'s other recordings) gives the same way on
  an instantiation out of memory: the step recordings are dropped (all
  of them from run(), all but the step's own from step()) and it tries
  once more.  It does so only where step recordings exist (Inkling 2
  with batch slots); every other family fails there as before.
- STRATA_POLY_STEP_RECORD_FAIL=N (tests): every Nth step recording fails
  as if out of memory, so that the unrecorded path runs.
- metal_invalidate_graphs() forgets the step recordings it destroys.

Not covered: an out-of-memory at a recording's first launch, which
ck() still turns into an error.

Class: same bits.

The findings are from the independent review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
… its kernels

f8edaf3 gave a step's rows the card's picks on every layer whose
L.card is not 0, which includes -1: a layer card_moe() has not tried
yet (prompts of under 32 tokens, then a step of several rows).  Such a
layer would be routed on the host alone if its experts' types have no
card-pick kernel (native_mmvq_ids_supported()), where moe_card() sets
L.card to 0.  It now counts as the card's only where they have one.

The doorbell is set up only where every layer's types have those
kernels, so with today's files this cannot be hit; the test keeps the
rows' rule the same as moe_card()'s even so.

From the independent re-review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
f4bfc38 warned only when --parallel was given on this run, so setup
run again without it kept "parallel": 4 from the config before and said
nothing.  The warning now reads the finished config (write_setup_config()'s
after_carry: "parallel" asked or kept, the person's own args), and is not
given for a family that answers one request at a time (on a Mac for
"one_request": "mac").  test_setup_inkling.py checks a second setup run
without --parallel.

From the independent re-review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo
okada-shogo marked this pull request as ready for review November 23, 2026 10:15
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
…eem to take

The budget of 45be289 summed what cudaMemGetInfo() lost across each
step recording's instantiation and took the recordings' average off for
each one dropped.  But cudaGraphExecDestroy() gives the driver's memory
back to no cudaMemGetInfo(), and later recordings take the memory it
kept with no loss shown: in the review's replay of the algorithm (an
8 MiB budget, new keys, 20-kernel graphs on the RTX 2070 Super) the sum
stayed at 6 MiB while the card gave 128 MiB and more.  A fixed number
held stayed flat there (50 MiB after 10 cycles of drop and make).

- record_step() holds at most step_cap_ step recordings: 4 a MiB of a
  64th of the card, 256 to 1,024 (512 on an 8 GB card, about 128 MiB at
  the 220-250 KiB a recording measured), or STRATA_POLY_STEP_GRAPHS.
  Past it the ones launched longest ago go (never the step's own), down
  to three quarters.  The size line ("N held, X MiB, Y KiB each") is
  printed only before the first drop, where the sum is right.
- Every drop prints a line: how many, how many held, and the totals made,
  dropped and run unrecorded.
- record() (run()'s and step()'s other recordings) gives the same way on
  an instantiation out of memory: the step recordings are dropped (all
  of them from run(), all but the step's own from step()) and it tries
  once more.  It does so only where step recordings exist (Inkling 2
  with batch slots); every other family fails there as before.
- STRATA_POLY_STEP_RECORD_FAIL=N (tests): every Nth step recording fails
  as if out of memory, so that the unrecorded path runs.
- metal_invalidate_graphs() forgets the step recordings it destroys.

Not covered: an out-of-memory at a recording's first launch, which
ck() still turns into an error.

Class: same bits.

The findings are from the independent review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
… its kernels

f8edaf3 gave a step's rows the card's picks on every layer whose
L.card is not 0, which includes -1: a layer card_moe() has not tried
yet (prompts of under 32 tokens, then a step of several rows).  Such a
layer would be routed on the host alone if its experts' types have no
card-pick kernel (native_mmvq_ids_supported()), where moe_card() sets
L.card to 0.  It now counts as the card's only where they have one.

The doorbell is set up only where every layer's types have those
kernels, so with today's files this cannot be hit; the test keeps the
rows' rule the same as moe_card()'s even so.

From the independent re-review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
f4bfc38 warned only when --parallel was given on this run, so setup
run again without it kept "parallel": 4 from the config before and said
nothing.  The warning now reads the finished config (write_setup_config()'s
after_carry: "parallel" asked or kept, the person's own args), and is not
given for a family that answers one request at a time (on a Mac for
"one_request": "mac").  test_setup_inkling.py checks a second setup run
without --parallel.

From the independent re-review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VecSzn

VecSzn commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Its not merged, its opt-in, so nothing depends on it. Its just the batch slots are changing the attention kernels that 233, 214, and 246 also rewrote, and those 3 are in main now so its going to need a rebase onto main.

okada-shogo and others added 15 commits November 23, 2026 20:58
Inkling 2 no longer refuses --batch: up to 2 sequences beside the first
(not with --draft-model, whose caches and block are one sequence's, and
not on Metal yet).  Its step() rows go through one head
(batch_heads()): the products, the depth mixes, the loop's messages,
the norms and the router run once for all rows, so a step reads the
dense weights once.  What reads or writes a sequence's state goes a row
at a time with the launches one token alone has (ink_qkv(), ink_attend()
sized by the row's own room, ink_conv_add()), each with its own
sequence's slot (run_slot(): seq_buf(), seq_state()) and its position
from at_.  The --loop-bf16 controllers' gates and the FFN controller
also go a row at a time with a token's launches, since their few-token
launches are other kernels.

Engine::step() now takes the layers in next_layer()'s order, as run()
does, so a looped core runs its passes in a step too.  A new hook,
tail_by_rows(), keeps step()'s rows through layer_tail() and records a
tail by its rows' sequences (Layer::rows_tails), for Inkling 2's
convolution of the experts' sum, whose state is a sequence's own; such a
step is not split into halves.  The other families do not set it: their
paths are unchanged.  Inkling 2's tail recordings in run() are kept a
sequence apiece (tail_key()), since Layer::tail is shared by the
sequences and holds the bound one's state; with one sequence the keys
are the ones before.

Class: same bits for one request (--batch 0 runs the launches it ran
before).  With slots, each row's per-sequence steps are a token's own
launches, so they give it the bits it gets alone; the shared products
take the few-token kernels main documents as giving each row its
single-row bits (lin()/mmvq, gemv_set(), the norms and mixes).

The batch-slot design follows our reference (fork branch inkling2-batch,
d525c9a) on VecSzn's Inkling 2 engine and his step() machinery
(batch_heads(), rows_heads, next_layer()).

Built for CUDA (sm_75).  HIP (inkling2.cpp and engine.cpp are in the HIP
build) and Metal not built here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --check-batch K, sequence j's prompt is the first n >> 3 (K - 1 - j)
of the --tokens' n (16 at least), read when the others have taken
j * max_new / (2K) steps, and it writes max_new - j * max_new / K
tokens: prompts of different lengths (so rows of a step at different
positions and attention sizes), sequences that join between steps, and
steps of fewer rows as they leave.  Without it --check-batch is as
before.  A test of the engine's step() for every family; ported from
our reference branch (inkling2-batch, d525c9a).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling 2 takes --batch up to the engine's 16 (kInkRows, 32, is the most
rows a launch takes).  The steps of step()'s rows that read or write a
sequence's state were a launch a row; they are now one launch for all
rows (the _rows kernels), each row with its own state and cache
pointers:
- ink_qkv_rows(): the K and V convolutions, the clips and the cache
  stores, a row a blockIdx.y.
- ink_attend_rows(): scores, softmax, values and join over each row's
  own caches.  The launch is sized for the largest room among the rows;
  each row's join adds only the value parts it has alone
  (InkAttnRows::parts, from its own room, or its position and itself
  when not recorded).  A row's scores and parts do not depend on the
  launch's size, so its bits are its own launch's.
- ink_conv_add_rows(): the attention's and the experts' output
  convolutions.
The kernels' bodies moved, unchanged, into __device__ functions that
the one-token launches and the _rows launches both call.  The rows
read their positions from at_, which step() writes every step.  Not on
Metal, which has no _rows kernels and refuses --batch for Inkling 2.
The loop controllers stay a row at a time with a token's launches.

Class: same bits.  One request runs the same kernel code; each slot's
row gets the bits its own launch gave it.

Built for CUDA (sm_75).  HIP (inkling2.cu is HIP-compiled) not built
here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling 2 Mini's family is "one_request": "mac": setup.py no longer
writes "parallel": 1 for it, so --parallel N works on Linux and Windows
as for the other strata-poly families (written when asked, with
poly_parallel_note()).  setup_mac.py still writes 1 (the engine refuses
--batch for this model on Metal).  test_setup_inkling.py checks both.
docs/BATCHING.md lists the model; docs/models/inkling.md says requests
at once are opt-in on NVIDIA, not with the draft file, and one at a time
on a Mac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Engine::step() with one row (a batch slot alone in a step: the first
request of a server with "parallel" set, or --check-stagger's steps
before the others join and after they leave) routed it on the card,
since card_moe(1) says yes for the doorbell (bell_on(): Inkling 2 with
experts outside VRAM), but step() never set bell_.  moe_card() then took
the mirror's branch (far_plan(), far_pull()) with the far table that
card_moe() leaves unfilled when it counts on the doorbell, and read
expert pointers that are not there: "step: an illegal memory access was
encountered" (--check-batch 4 --check-stagger, --no-graphs too, and the
server's first request at parallel 2 and 4, which answered HTTP 400).
With --batch 0 step() is not used, so one request was not hit.

step() now sets bell_ = bell_on(R) as run() does, keys its whole
recording by it, and answers the rings with bell_serve(): after the
whole recording's launch, or layer by layer after the card's experts,
as run() does.  bell_on() is false for every family but Inkling 2
(bells()), and for R > 1: other families' steps, and Inkling 2's steps
of several rows, launch what they launched before.

Class: same bits.  A one-row step now takes the experts the way the same
token alone takes them (the doorbell, the card's picks).

The doorbell is VecSzn's (202c1ad, after Strata v0.2.19's Inkling
hybrid mode).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the doorbell (bell_on(): Inkling 2 with experts outside VRAM) a
token alone is routed on the card: route_card(), whose sigmoid is the
card's expf.  A step of several rows went to moe(), which routed each
row on the host: route(), the same formula with the host's std::exp.
The two need not round alike in the last bit, so a row's expert weights
(and, at a near tie, an expert) could differ from the ones it got alone,
and greedy answers parted after some tokens: --check-batch 4 and 6 gave
"DIFF" (cb4-iq4 sequence 4 at token 20 of 64, cb6 3 sequences), and the
small-card arguments and UD-Q2_K_XL more often.  At 2 slots no token
happened to change.

Where a token alone routes on the card, step() now routes its rows there
too before the router's event (route_card() of R rows: a row a warp, a
row's bits its own), copies the picks and weights to pinned memory
(h_ids_, h_wts_, the latter only for bells() with --batch), and moe()
takes them in place of route() for those rows (step_ids_).  The rest of
moe() is as before.  Not with --cache-bias, whose host route() biases
the picks, and not on HIP or Metal (no doorbell there, so a token alone
routes on the host as the rows do).

Class: same bits as a token alone; one request (--batch 0) and the other
families do not reach the new code (h_wts_ is null for them).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
step() records Inkling 2's heads and tails (Layer::rows_heads,
rows_tails) and whole steps (step_passes_) by their rows' sequences and
rooms.  With slots that come and go, every new set of rows made new
recordings, and nothing dropped them: on the RTX 2070 Super, four chats
at "parallel" 4 with a 32K context filled the card until
cudaGraphInstantiate failed ("out of memory"), and the engine ended.

Where the tails take the rows (tail_by_rows(): Inkling 2), step() now
goes through step_replay():
- each recording's VRAM is what cudaMemGetInfo() lost across its
  cudaGraphInstantiate; together they are held to a budget, a 64th of
  the card from 64 to 256 MiB (128 on an 8 GB card), or
  STRATA_POLY_STEP_GRAPH_MIB.  Past it the recordings launched longest
  ago go (never the step's own), down to three quarters of it;
- an instantiation that fails for memory drops every other step
  recording and tries once more; failing still, the step's work runs
  unrecorded, and no step records for the next 256 steps;
- a line "step recordings: N held, X MiB (Y KiB each)" each time the
  count doubles from 256, for sizing the budget.

The other families' step() records and replays as before (the same
maps, record() and cudaGraphLaunch()).

Class: same bits.  A recording replays the launches it records, and an
unrecorded run makes the same launches with positions by value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eem to take

The budget of 45be289 summed what cudaMemGetInfo() lost across each
step recording's instantiation and took the recordings' average off for
each one dropped.  But cudaGraphExecDestroy() gives the driver's memory
back to no cudaMemGetInfo(), and later recordings take the memory it
kept with no loss shown: in the review's replay of the algorithm (an
8 MiB budget, new keys, 20-kernel graphs on the RTX 2070 Super) the sum
stayed at 6 MiB while the card gave 128 MiB and more.  A fixed number
held stayed flat there (50 MiB after 10 cycles of drop and make).

- record_step() holds at most step_cap_ step recordings: 4 a MiB of a
  64th of the card, 256 to 1,024 (512 on an 8 GB card, about 128 MiB at
  the 220-250 KiB a recording measured), or STRATA_POLY_STEP_GRAPHS.
  Past it the ones launched longest ago go (never the step's own), down
  to three quarters.  The size line ("N held, X MiB, Y KiB each") is
  printed only before the first drop, where the sum is right.
- Every drop prints a line: how many, how many held, and the totals made,
  dropped and run unrecorded.
- record() (run()'s and step()'s other recordings) gives the same way on
  an instantiation out of memory: the step recordings are dropped (all
  of them from run(), all but the step's own from step()) and it tries
  once more.  It does so only where step recordings exist (Inkling 2
  with batch slots); every other family fails there as before.
- STRATA_POLY_STEP_RECORD_FAIL=N (tests): every Nth step recording fails
  as if out of memory, so that the unrecorded path runs.
- metal_invalidate_graphs() forgets the step recordings it destroys.

Not covered: an out-of-memory at a recording's first launch, which
ck() still turns into an error.

Class: same bits.

The findings are from the independent review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0dd95b8 took the card's picks for a step's rows where bell_on(1)
holds.  card_moe(1), which decides how a token alone is routed, also
wants the card's slot table (d_slots_), room for a token's experts
(card_rows()), no --dump and no --expert-gpu (ecard_), and a layer it
found it cannot route on the card (L.card == 0) goes to the host.  With
--expert-gpu, say, a token alone was routed on the host while the rows
took the card's picks: the same last-bit mismatch the other way round.
The rows now take the card's picks under all of card_moe(1)'s
conditions, and a layer at a time only where L.card is not 0.

Class: same bits as a token alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_geometry() took --batch up to 31 (kInkRows - 1), but a step of 32
rows reaches kStageRows, where control3() and the products take the
prompt batch's kernels, the experts go through MMQ and none is routed on
the card: a row would not get the bits it gets alone, and nothing that
large was checked.  --batch 16 and more are now refused with "Inkling 2
takes up to 15 sequences beside the first (--batch 1 to 15)".

--check-stagger: the prompt of sequence j is n >> 3 (K - 1 - j), a shift
of 64 or more for K of 23 and more; the shift stops at 63.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…thers

Setup's small-card flags for Inkling 2 Mini include --tail-skip 4, and
the engine decides that skip over a step's rows, which are several chats'
tokens.  Setup now warns when --parallel 2 or more meets --tail-skip;
docs/BATCHING.md and docs/models/inkling.md say so, the slots' up to 16,
and what each slot's window rings take (about 320 MiB at fp16).
test_setup_inkling.py checks the warning, and that a card holding every
expert gets none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its kernels

f8edaf3 gave a step's rows the card's picks on every layer whose
L.card is not 0, which includes -1: a layer card_moe() has not tried
yet (prompts of under 32 tokens, then a step of several rows).  Such a
layer would be routed on the host alone if its experts' types have no
card-pick kernel (native_mmvq_ids_supported()), where moe_card() sets
L.card to 0.  It now counts as the card's only where they have one.

The doorbell is set up only where every layer's types have those
kernels, so with today's files this cannot be hit; the test keeps the
rows' rule the same as moe_card()'s even so.

From the independent re-review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f4bfc38 warned only when --parallel was given on this run, so setup
run again without it kept "parallel": 4 from the config before and said
nothing.  The warning now reads the finished config (write_setup_config()'s
after_carry: "parallel" asked or kept, the person's own args), and is not
given for a family that answers one request at a time (on a Mac for
"one_request": "mac").  test_setup_inkling.py checks a second setup run
without --parallel.

From the independent re-review of simplexai-labs#226.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…D_FAIL

tools/check's docs step failed: step()'s recordings read these two and the
register did not list them.  Their entries as python tools/settings_register.py
writes them (status research, owner poly), every other entry as it was.
Neither is opt-in or rollback, so docs/SETTINGS.md does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since this branch was made, main took simplexai-labs#217 (Inkling 2 on AMD) and simplexai-labs#214
(--kv q8_0).  The batch slots' _rows kernels are the fused q/k/v and clips
kernels that HIP does not run (inkling2.cu: clips_apart()), and they read
fp16 and FP8 caches only, so load_geometry() now says so: --batch on AMD
and --batch with --kv q8_0 stop at load with a message, as --draft-model and
Metal do.  A single sequence on either is unchanged.  The same checks as
the combined branch's resolution of simplexai-labs#226 with simplexai-labs#214 and simplexai-labs#217.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
…t once (batch slots, parallel)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/models/inkling.md
#	engine/src/poly/inkling2.cpp
#	engine/src/poly/inkling2.cu
#	engine/src/poly/inkling2.hpp
#	terminal/setup.py
@okada-shogo

Copy link
Copy Markdown
Contributor Author

@VecSzn Right, thank you for the catch. I rebased it onto main so it should merge correct now.

@VecSzn
VecSzn merged commit f35b12a into simplexai-labs:main Nov 23, 2026
22 of 28 checks passed
@VecSzn

VecSzn commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

It's merged into main, but is opt-in. One thing to look at: through the server at "parallel" 4 and 8, some greedy answers are different from "parallel" 1 within the first words, even though --check-batch passes, and Qwen3.6 on main gives the same answers there. Also the engine no longer refuses --batch on AMD, Metal, with --kv q8_0, --draft-model or --layer-split, it says why, and runs one request at a time, because a config with "parallel" and one of those had no server at all (ec45170).

@okada-shogo

Copy link
Copy Markdown
Contributor Author

Thanks. Found it: at parallel ≥ 2 the server's slot path left turn_at off GEN/BGEN, so the prompt was read in different calls and Inkling's greedy answer moved. Fix: #287. With it, parallel 1/4/8 give the same answers when the expert split is the same.

The rest is placement: with 4/8 slots fewer experts fit in VRAM, and CPU vs GPU expert sums aren't bit-identical. With every expert in VRAM or the split frozen, the answers match.

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