Skip to content

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

Draft
okada-shogo wants to merge 7 commits into
simplexai-labs:mainfrom
okada-shogo:port/batch-slots
Draft

okada-shogo wants to merge 7 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

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 (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). RTX 2070 Super 8 GB, IQ4_NL, fp16 cache, 32K context,
the server (terminal/serve), 300 tokens a chat, greedy. Each cell is the mean of 3 rounds. main answers one request at
a time, so the 2 and 4 chat rows are compared with main's 1-chat rate.

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 38.8 38.5 -0.8%
RTX 2070 Super 8 GB IQ4_NL 2 chats, "parallel": 2 38.8 46.4 +19.6%
RTX 2070 Super 8 GB IQ4_NL 4 chats, "parallel": 4 38.8 49.9 +28.6%
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 4 38.8 36.4 -6.2%

The last row is slower because 4 slots' caches leave fewer experts in VRAM (649 of 3,072, against 921).

Each run (tok/s)
Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 main 38.7 39.3 38.4
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 1 this PR alone 37.8 39.1 38.6
RTX 2070 Super 8 GB IQ4_NL 2 chats, "parallel": 2 this PR alone 45.7 47.1 46.3
RTX 2070 Super 8 GB IQ4_NL 4 chats, "parallel": 4 this PR alone 49.9 49.9 49.8
RTX 2070 Super 8 GB IQ4_NL 1 chat, "parallel": 4 this PR alone 35.9 37.8 35.6

Experts in VRAM: 921 (main) and 922 (this PR) at "parallel": 1, 795 at 2, 649 at 4. Per-chat rates at 4 chats:
13.0 to 14.3 tok/s.

Identity.

Check Card Result
One request, main vs this PR, --batch 0: tokens + top-5 of 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 5 of 5 same
--check-batch 2, 3, 4, 6 slots; --check-stagger 2 and 4 slots (with and without graphs); small-card args; UD-Q2_K_XL RTX 2080 Ti 11 GB every token the same as alone
--check-batch 4 and 6 slots, --check-stagger 4 slots, small-card args, UD-Q2_K_XL; also with a 1 MiB recording budget 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 run, 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. 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). They are now held to a VRAM budget (least recently used dropped first; measured
      224-248 KiB each), and a recording the card has no memory for 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 held to a VRAM budget: a 64th of the card, 64 to 256 MiB (STRATA_POLY_STEP_GRAPH_MIB);
    instantiate out of memory: drop the others, retry once, else run unrecorded. Only where tail_by_rows().

Validation

Passed:

  • CUDA 12.9 build, sm_75, at this branch's head (45be289).
  • cd terminal && ../.venv/bin/python -m unittest tools.test_setup_inkling tools.test_setup_mac tools.test_setup_menu tools.test_setup_choices tools.test_setup_amd serve.test_parallel: 282 tests OK (at commit 4; commits 5-7 touch only engine.cpp/engine.hpp); test_setup_inkling.py again at the head: OK.
  • One request vs main and --check-batch (table above): strata-poly --tokens @ids302.txt --max-new 64 --top-probs 5 --cpu-share 0 --kv fp16 with STRATA_FREEZE_EXPERTS=1 (A/B), and --batch K --check-batch K [--check-stagger] (slots), RTX 2080 Ti 11 GB and RTX 2070 8 GB, sm_75 binaries.
  • Server throughput (table above): RTX 2070 Super 8 GB, terminal/serve/server.py with "parallel" 1/2/4, 1/2/4 concurrent chats, 3 rounds after a warm-up request.

Failed (first run, fixed by commits 5-7 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:

  • compute-sanitizer memcheck of the 4-slot --check-stagger case: queued (a first, larger run timed out).
  • 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.
  • A kernel test of the _rows kernels against the one-token launch, bit for bit; the end-to-end --check-batch covers them.

Limits

  • Not with --draft-model; not on Metal.
  • --tail-skip can make a slot differ from the same request alone (the skip is decided over all rows of a step).
  • One chat on a server with "parallel" 4 is about 6% slower than "parallel" 1 on an 8 GB card: the slots' caches
    take VRAM from the expert cache.
  • With [Engine] Inkling 2 Mini: --layer-split across cards, the loop on the faster card #227 (--layer-split on Inkling 2): both PRs edit the same need(opt_.layer_split.empty()) line. Whichever
    lands second should keep --batch and --layer-split apart on Inkling 2 until that pair is tested.

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.

🤖 Generated with Claude Code

okada-shogo and others added 4 commits November 23, 2026 04:41
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>
okada-shogo and others added 3 commits November 23, 2026 11:04
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>
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