Repository navigation
[Engine] Inkling 2 Mini: several requests at once (batch slots, parallel) - #226
Draft
okada-shogo wants to merge 13 commits into
Draft
okada-shogo wants to merge 13 commits into
okada-shogo wants to merge 13 commits into
Conversation
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>
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
Inkling 2 Mini refuses
--batchtoday (inkling2.cpp: "runs one sequence"), so the server answers one request at atime and setup writes
"parallel": 1. This PR lets it take batch slots like the other strata-poly models: up to 16slots in all (
--batch1 to 15; the server uses up to 8, docs/BATCHING.md), a token of each slot in onestep().--batch 0,"parallel": 1) runs the same launches as main: same tokens and top-5 probabilities.--check-batch, every token, 2 to 6 slots).--draft-model; not on Metal yet (refused there; setup keeps"parallel": 1on 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.
"parallel": 1"parallel": 2"parallel": 4"parallel": 8"parallel": 4"parallel": 1"parallel": 2"parallel": 4"parallel": 8"parallel": 4"parallel": 1"parallel": 2"parallel": 4"parallel": 4The 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 (922 experts at 1 slot, 795 at 2, 649 at 4): that is
why it gains less, and why one chat at
"parallel": 4is slower there.Each run (tok/s)
"parallel": 1"parallel": 1"parallel": 2"parallel": 4"parallel": 8"parallel": 4"parallel": 1"parallel": 1"parallel": 2"parallel": 4"parallel": 8"parallel": 4"parallel": 1"parallel": 1"parallel": 2"parallel": 4"parallel": 4Per-chat rates at 8 chats on the 24 GB card: 13.0 to 15.8 tok/s. 8 GB card, 4 chats: 256 step recordings held in
56 MiB (224 KiB each), cap 484, none dropped.
Identity.
--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--check-batch2, 3, 4, 6 slots;--check-stagger2 and 4 slots, with and without graphs; small-card args without--tail-skip; UD-Q2_K_XL--check-stagger4 slots with a cap of 120 step recordings: 372 dropped, made again--check-stagger4 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--check-batch 4 --tail-skip 4Related 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 oncefor 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 (
_rowskernels).step()never rang it, somoe_card()read anunfilled table ("illegal memory access").
step()now rings and answers the doorbell asrun()does.expf), a step's rows on the host (std::exp), which can differ in the lastbit. Where
card_moe(1)routes a token alone on the card, the rows now take the card's picks too.cudaGraphInstantiateran outof 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
step()walks the layers innext_layer()order, asrun()does (other families:il + 1). Newhook
tail_by_rows()(default false, only Inkling 2 sets it).tail_key()includes the bound sequence.--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.
ink_qkv_rows(),ink_attend_rows(),ink_conv_add_rows()call theone-token kernel bodies with a row per
blockIdx.yand each row's own pointers."one_request": "mac", so--parallel Nworks on Linux/Windows; docs/BATCHING.md anddocs/models/inkling.md.
bell_on()is false for other families and for more rows).route_card(),h_wts_; only with the doorbell).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()'sother recordings) drops the step recordings and retries on an out-of-memory too; only where step recordings
exist.
STRATA_POLY_STEP_RECORD_FAIL=Nis a test hook for the unrecorded path.card_moe(1)'s conditions (no--expert-gpu, the slot table,a layer at a time where
L.cardis not 0).--batchup to 15: 32 rows would reach the prompt batch's kernels.--check-stagger's shift is clamped.--parallelmeets--tail-skip; the docs say so.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).--tail-skipwarning reads the finished config ("parallel"kept from the config before too), andis not given where the family answers one request at a time.
Validation
Passed:
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.--check-batch(identity table):strata-poly --tokens @ids302.txt --max-new 64 --top-probs 5 --cpu-share 0 --kv fp16withSTRATA_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 16is refused.terminal/serve/server.pywith"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) and RTX 2070 Super 8 GB.Failed (first runs, fixed by commits 5-9 and passed above):
--check-batch4 and 6 differed after some tokens;--check-staggerand the server at"parallel"2 and 4 stopped with "illegal memory access"; 4 chats at"parallel"4 stopped withcudaGraphInstantiate: out of memory.Not run:
--check-staggercase timed out (3,000 s, then 1,800 s with a64-token prompt and 4 tokens): too slow under the sanitizer. A lighter one (2 slots, a few tokens) is to come.
inkling2.cualready fails (10__ldcs/__ldcgerrors in code this PR does not touch; fixed by [Engine] build Inkling 2's DSpark screen on HIP #206).engine.cppwith this PR builds for HIP; a full HIP build waits for [Engine] build Inkling 2's DSpark screen on HIP #206. No AMD run.--batchfor this model); FP8 caches (Ampere+); cards other than sm_75._rowskernels against the one-token launch, bit for bit; the end-to-end--check-batchcovers them.Limits
--draft-model; not on Metal; up to 16 slots.lin()calls in place oflin_pair()(its multi-row kernel takes up to 8), not checked.--tail-skipcan make a chat's answer depend on the other chats writing at the same time (the skip is decided overall rows of a step); setup warns.
2,048 rows x 2 KiB), plus 32 MiB of attention rows, even while the slot is idle. On an 8 GB card that is 922 -> 795
-> 649 experts in VRAM at 1, 2 and 4 slots. Mapping them lazily is left for later.
--layer-spliton Inkling 2): both PRs edit the sameneed(opt_.layer_split.empty())line. Whicheverlands second should keep
--batchand--layer-splitapart 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. The fixes in commits 8-11 follow an independentreview.
🤖 Generated with Claude Code