Skip to content

[Engine] Inkling 2 Mini: --layer-split across cards, the loop on the faster card - #227

Merged
VecSzn merged 7 commits into
simplexai-labs:mainfrom
okada-shogo:port/layer-split
Nov 23, 2026
Merged

VecSzn merged 7 commits into
simplexai-labs:mainfrom
okada-shogo:port/layer-split

Conversation

@okada-shogo

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

Copy link
Copy Markdown
Contributor

Rebased onto main 5c83833 (2026-11-24).

--top-probs off on a split: VecSzn found that greedy decoding with --top-probs off wrote 0 after the first token. The bug was main's (since 967620e) and main fixed it in 3d28e5c. This PR now only adds a test for it, poly_layer_split_picks_test.

Problem and result

For machines with two or more GPUs. --layer-split now works with Inkling 2 Mini, as it does for the other
strata-poly models. Main refuses it (inkling2.cpp: "runs on one card"). Opt-in: one card without --layer-split runs
the same code as before.

  • The loop's layers (6 to 17, run three times a token) stay on one card. So the second card starts at layer 1 to 6
    or at layer 18 to 22.
  • Once a token, a card passes 64.5 KB to the next one.
  • "auto" knows the loop and each card's memory bandwidth. On two unequal cards it puts the loop on the faster card,
    in either card order. Equal cards (within 5%) get the plain layout.

Speed on two RTX 2070 Super 8 GB (rented, PCIe 3.0 x16 each), IQ4_NL, experts in VRAM, a 302-token prompt, 256 tokens
written, --kv fp16, in tokens per second (tok/s), higher is better. Mean of 3 runs. "One card" is device 0 without --layer-split; "two cards" is this PR with the --layer-split in the Measure column.

Prompt tok/s, higher is better:

Card Model Measure one card (tok/s) two cards (tok/s) Change Experts in VRAM (one card → two cards)
2x RTX 2070 Super 8 GB IQ4_NL prompt of 302 tokens, --layer-split 18 (second card from layer 18) 179.8 195.3 +8.6% 993 → 1,908 of 3,072
2x RTX 2070 Super 8 GB IQ4_NL prompt of 302 tokens, --layer-split 6 (second card from layer 6) 179.8 182.0 +1.2% 993 → 1,575 of 3,072
2x RTX 2070 Super 8 GB IQ4_NL prompt of 302 tokens, --layer-split auto 179.8 205.5 +14.3% 993 → 1,908 of 3,072

Decode tok/s, higher is better:

Card Model Measure one card (tok/s) two cards (tok/s) Change Experts in VRAM (one card → two cards)
2x RTX 2070 Super 8 GB IQ4_NL decode after a 302-token prompt, --layer-split 18 (second card from layer 18) 37.04 50.98 +37.6% 993 → 1,908 of 3,072
2x RTX 2070 Super 8 GB IQ4_NL decode after a 302-token prompt, --layer-split 6 (second card from layer 6) 37.04 48.49 +30.9% 993 → 1,575 of 3,072
2x RTX 2070 Super 8 GB IQ4_NL decode after a 302-token prompt, --layer-split auto 37.04 51.14 +38.1% 993 → 1,908 of 3,072

No split mode was slower than one card. Split 6 is about one card's speed on the prompt (+1.2%) and faster in
decode. It holds fewer experts in VRAM than 18, because its first card has only 6 layers to fill. On two equal
cards auto takes the same layout as 18, so the gap between them on the prompt (+14.3% and +8.6%) is not a layout
change. It is not explained yet: auto ran right after split 6 in each round, and split 18 right after one card.

Identity: every split gives exactly one card's tokens and top-20 probabilities. That means 302 + 64 and 2048 + 16
tokens, greedy, --top-probs 20, --kv fp16, every expert on the CPU (--no-gpu-experts, so no expert cache
differs), with the same md5 of the output. "Parts on one card" = an RTX 2070 8 GB running the split's parts in turn
(STRATA_POLY_CARDS); "two cards" = the two RTX 2070 Super. SAME = the same as this branch on one card, which is the
same as main:

Split Parts on one card, IQ4_NL, 302-token prompt Parts on one card, IQ4_NL, 2048-token prompt Parts on one card, UD-Q2_K_XL, 302-token prompt Parts on one card, UD-Q2_K_XL, 2048-token prompt Two cards, IQ4_NL, 302-token prompt Two cards, IQ4_NL, 2048-token prompt
one card, main vs this PR SAME SAME SAME SAME SAME SAME
one card, doorbell on vs off SAME SAME SAME SAME SAME SAME
--layer-split 3 SAME SAME SAME SAME SAME SAME
--layer-split 6 SAME SAME SAME SAME SAME SAME
--layer-split 18 SAME SAME SAME SAME SAME SAME
--layer-split 20 SAME SAME SAME SAME SAME SAME
--layer-split 6,18 (three parts) SAME SAME SAME SAME SAME SAME
--layer-split auto SAME SAME SAME SAME SAME SAME
--layer-split auto, bandwidths forced to 900 and 300 GB/s SAME SAME SAME SAME SAME SAME
--layer-split auto, bandwidths forced to 300 and 900 GB/s (loop moves to device 1) SAME SAME SAME SAME SAME SAME
--layer-split 6, devices in order 1, 0 not run not run not run not run SAME SAME
--layer-split 18, devices in order 1, 0 not run not run not run not run SAME SAME
Each run (tok/s)

Prompt tok/s, higher is better, each run:

Card Model Measure Build Run 1 (tok/s) Run 2 (tok/s) Run 3 (tok/s)
RTX 2070 Super (device 0) IQ4_NL prompt of 302 tokens one card 181.2 178.3 179.8
RTX 2070 Super (device 1) IQ4_NL prompt of 302 tokens one card 185.7 185.3 184.9
2x RTX 2070 Super IQ4_NL prompt of 302 tokens two cards, --layer-split 18 193.6 195.0 197.3
2x RTX 2070 Super IQ4_NL prompt of 302 tokens two cards, --layer-split 6 182.0 179.9 184.1
2x RTX 2070 Super IQ4_NL prompt of 302 tokens two cards, --layer-split auto 205.0 205.8 205.7

Decode tok/s, higher is better, each run:

Card Model Measure Build Run 1 (tok/s) Run 2 (tok/s) Run 3 (tok/s)
RTX 2070 Super (device 0) IQ4_NL decode after a 302-token prompt one card 38.21 37.51 35.40
RTX 2070 Super (device 1) IQ4_NL decode after a 302-token prompt one card 35.42 34.06 37.45
2x RTX 2070 Super IQ4_NL decode after a 302-token prompt two cards, --layer-split 18 50.94 50.92 51.07
2x RTX 2070 Super IQ4_NL decode after a 302-token prompt two cards, --layer-split 6 48.43 48.46 48.57
2x RTX 2070 Super IQ4_NL decode after a 302-token prompt two cards, --layer-split auto 51.19 51.02 51.20

Experts in VRAM, as logged at load: one card 993 (device 0) and 994 (device 1) of 3,072, 4.8 GiB. Split 18 and auto
1,187 of 2,304 (layers 0 to 17, 5.0 GiB) + 721 of 768 (layers 18 to 23, 4.8 GiB). Split 6: 768 of 768 (3.2 GiB) +
807 of 2,304 (4.0 GiB). The rounds went one card device 0, device 1, split 18, 6, auto, three times.

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

The split (placement only)
  • layer_starts() takes a range no card may start inside (only inkling2_loop passes one: loop.start, loop.end).
    A number inside it is refused; "auto" snaps to the nearer end by bytes.
  • Inkling 2 keeps its residual streams and the loop's bank beside r_ (carry_rows()); carry_out() / carry_in()
    copy them with the rows of r_ in hand_on(), step() and run(). carry_rows() is 0 for every other family.
  • --draft-model (DSpark) stays on one card.
"auto" on unequal cards (placement only)
  • split_plan.hpp (header only) estimates a token's time for every legal cut and both card orders from file sizes and
    peak bandwidth (peak memory clock x bus width; STRATA_POLY_CARD_GBS=a,b overrides it; HIP and Metal report 0, so
    they get the plain layout).
  • The best layout is taken only if it is at least 3% faster than the plain one; cards within 5% keep the plain one.
  • With STRATA_POLY_CARDS above the device count, "auto" probes the devices in turn (before: "invalid device").
  • Example estimate (IQ4_NL sizes, RTX 5080 + RTX 4060 Ti 16 GB): plain split 12.6 ms a token, auto 5.7 ms. An
    estimate, not a measurement.
Fix: a card that starts at layer 6 ran the loop forever (b32a413)

Inkling2::layer_head() set the loop's pass pass_ to 0 at the card's first layer (if (il == lo_) pass_ = 0;).
next_layer() runs the loop again by going from layer 17 back to 6 with pass_ + 1. On a card whose first layer is 6,
every return to 6 set pass_ to 0 again, so the card never left the loop (--layer-split 6 and 6,18 hung after
loading). Now the reset is skipped when the card's first layer is the loop's first:
if (il == lo_ && il != core_start_). next_layer() already sets pass_ back to 0 after the last pass, so each call
still starts at pass 0. One card (first layer 0) runs the same code as before.

Validation

Passed:

  • --top-probs off at 2e05830 (main's 3d28e5c fix), Bazzite RTX 2070 8 GB (sm_75), parts on one card (STRATA_POLY_CARDS=2), sm_75;86 build, fp16 KV:
    • poly_layer_split_picks_test MODEL SPLIT 32: splits auto and 6, IQ4_NL and UD-Q2_K_XL: 4 of 4 PASS.
    • strata-poly identity, IQ4_NL, 302 + 64 tokens: splits 6 and auto, each with --top-probs 20 (ids + top lines) and off (ids), vs one card: 5 SAME, 0 DIFF, 0 timeouts.
  • --top-probs off with our earlier fix (611fa2f, same change as main's), Bazzite RTX 2070 8 GB (sm_75), parts on one card (STRATA_POLY_CARDS), CUDA 12.9, sm_75;86 build, --no-gpu-experts, fp16 KV:
    • New poly_layer_split_picks_test MODEL SPLIT 32 (greedy ids on one card and split, picked on the card and from the logits): splits auto, 6, 18, 6,18, IQ4_NL and UD-Q2_K_XL. The build before the fix FAILs all 8 (split, picked on the card: 2567,0,0,0,...), the fix PASSes all 8.
    • strata-poly identity against one card with --top-probs 20, with --top-probs 20 (ids + top lines) and with --top-probs off (ids): 302 + 64 tokens on both files (splits 3, 6, 18, 20, 6,18, auto, auto with bandwidths 300,900) and 2048 + 16 on IQ4_NL (6, 18, auto): 37 SAME, 0 DIFF, 0 timeouts. Before the fix, split auto with --top-probs off: DIFF (150060,0,0,...).
    • CPU: poly_split_plan_test ok; tools.test_settings_register 8 OK; tools/check --only docs 6 of 6; terminal/tools test_setup*.py 1368 OK, 1 skipped.
  • Two real cards: vast.ai instance with 2x RTX 2070 Super 8 GB (driver 580.178.04, power limit 130 W, PCIe 3.0 x16 each,
    Xeon E5-2630 v4, 40 threads, 62 GB). Main d1f711e and this branch b32a413, both built there with CUDA 12.9.86,
    sm_75. Identity (table above): 24 SAME, 0 DIFF, 0 timeouts (each run capped at 600 s), 0 runs failed. Speed: the
    15 runs above, all rc=0.
  • Two or three parts on one card (STRATA_POLY_CARDS=2 / 3), RTX 2070 8 GB (sm_75), b32a413 vs one card, vs the
    branch before the fix and vs main: 44 SAME, 0 timeouts, 49 runs rc=0 (table above).
  • poly_split_plan_test (no GPU): split_plan_test: ok. Equal cards keep the plain cut and order, unequal pairs get the
    loop on the fast card in both orders, only legal starts are taken, and a change happens only where it is 3% faster.
  • CUDA 12.9 build, sm_75: strata-poly at this branch's head.
  • python3 tools/check --only docs: 6 of 6.

Failed:

  • None at 2e05830. Before main's 3d28e5c, a split with --top-probs off wrote 0 after the first token.
  • None at b32a413. Before it, --layer-split 6 and 6,18 hung after loading (fixed above).

Not run:

  • --layer-split with --kv q8_0 (main's [Engine] Inkling 2: --kv q8_0, an 8-bit attention cache without FP8 hardware #214).
  • UD-Q2_K_XL on the two real cards, and the phase with experts in VRAM comparing splits' outputs: the box could not
    make the Q2 loop file (q2_to_loop.py: no gguf module in its venv). UD-Q2_K_XL ran only as parts on one card.
  • Speed on one card, main vs this branch (one card runs the same code; its outputs are the same as main's).
  • Two unequal cards (only forced bandwidths, STRATA_POLY_CARD_GBS). cobra91 was asked to try his RTX 5080 +
    RTX 4060 Ti.
  • The refusal of --layer-split 10 and 23.
  • HIP and Metal builds (main's HIP build of inkling2.cu already fails on __ldcs / __ldcg, fixed by [Engine] build Inkling 2's DSpark screen on HIP #206).

Limits

  • With experts in VRAM a split holds a different set of experts on the cards than one card. Their sums round
    differently on the card and on the CPU, so a split's tokens can differ from one card's, as with any cache size.
    The identity runs keep every expert on the CPU for that reason.
  • "auto"'s choice on unequal cards is an estimate from file sizes and peak bandwidth, not measured yet.
  • Only two cards get the loop-aware choice; three or more use the plain "auto".
  • AMD cards get the plain layout unless STRATA_POLY_CARD_GBS is set.
  • Two parts on one card with experts on it can run short of VRAM (main has no reserve for a later part on the same
    card). That is only the one-card test mode.
  • With [Engine] Inkling 2 Mini: several requests at once (batch slots, parallel) #226 (--batch 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 (need(opt_.batch == 0 || !split_, ...)) until
    that pair is tested.

Credits: keeping the looped core on the fast card is cobra91's and kuraneko1's idea (Strata PR #6506); the code here
is our own, adapted from our --layer-split in #200.

🤖 Generated with Claude Code

@okada-shogo
okada-shogo marked this pull request as ready for review November 23, 2026 02:11
okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
…ss cards, the loop on the faster card

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

VecSzn commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

This one is not merged and the rest of the batch is in main now. I found a bug when I test it on two cards with --layer-split auto and greedy decoding, and --top-probs off. The first token is correct, but every tokens after it is 0. If I turn on --top-probs 5, then the tokens are exactly same as one card. All the checks in the PR have --top-probs on, so they didn't catch this bug. Could you fix this and rebase it to main?

okada-shogo added a commit to okada-shogo/PolyStrata that referenced this pull request Nov 23, 2026
…ss cards, the loop on the faster card

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

# Conflicts:
#	docs/models/inkling.md
#	engine/src/poly/inkling2.cpp
#	terminal/data/settings-register.json
@VecSzn

VecSzn commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Correction to my last comment, the token 0 bug isn't in this PR, it's been in main since 967620e, and a greedy run on a layer split reads the wrong card's logits. LFM2.5 on main shows the same thing. Sorry about blaming your split. I fixed it on main in 3d28e5c and with that your split gives the same tokens as one card in our checks, at the auto split and at layer 6, with and without --top-probs

@okada-shogo

okada-shogo commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. With --top-probs off, a split read the picked token from the first card's unfilled buffer; picks now go to the last card (611fa2f). A new test, poly_layer_split_picks_test, covers --top-probs off, and the identity runs now use it both on and off. Rebased onto main 6d59254, new head 611fa2f.

Just saw your message, let me confirm

okada-shogo and others added 7 commits November 24, 2026 01:20
A card of a split runs a run of the 24 layers, and the loop's twelve (6 to 17) stay on one card: next_layer() runs
them again for a later pass, so a card starts at layer 1 to 6 or 18 to 22.  layer_starts() takes a range no card
starts inside: a number given inside it is refused with a message, and "auto" takes the nearer of its ends by the
layers' bytes.  Engine::open() gives that range only for inkling2_loop; the other families pass none.

Inkling 2 keeps its residual streams and the loop's bank beside r_ (carry_rows()), so a hand-off now carries them
too: hand_on() and step() copy them behind the rows of r_ (carry_out(), 64.5 KB a token with r_), and the next card
copies them back in run() and step() (carry_in()).  carry_rows() is 0 for every other family, so their hand-off
and one-card paths are unchanged.  The input's norm loads on the card with layer 0 and the output's mix query on
the card with the output; one card loads both at layer 0 as before.  --draft-model stays on one card (its
features are three layer runs' inputs, which may be another card's).

Ported from our engine's --layer-split for Inkling (okada-shogo/PolyStrata inkling2 9fe4fee), adapted to
VecSzn's 24-layer engine with next_layer().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inkling 2 Mini runs layers 6 to 17 three times a token: 36 of its 48 layer runs.  The plain "auto" shares layers
by free VRAM and puts the loop wherever the bytes fall.  On a fast and a slow card, with the server's "faster card
last" order (#1352), that gives the slow card the loop: on an RTX 5080 + RTX 4060 Ti 16 GB the estimate is 12.6 ms
a token where the loop on the 5080 is 5.7 ms.

split_plan.hpp estimates a token's time for every legal start of the second card and both device orders.  Dense
weights are read once a run, expert_used_count/expert_count of the experts once a run, the output once a token.
Each card caches its most-run experts first and reads the rest on the CPU.  The cards run in turn, so the times
add.  layer_starts() takes the fastest layout when it is at least 3% faster than the plain one, and open() may then
swap which device takes the first layers.  Cards within 5% of each other's bandwidth (the server's #1760 rule),
cards whose bandwidth is not known (HIP, Metal) and every other family keep the plain layout and order.
Bandwidth is the peak memory clock times the bus width; STRATA_POLY_CARD_GBS=a,b overrides it.  "auto" now probes
devices in turn when STRATA_POLY_CARDS asks for more parts than there are devices (it failed there before), so
the choice can be tried on one card.  poly_split_plan_test checks the choice on made-up cards, no GPU needed.

The idea of keeping the looped core on the faster card is cobra91's and kuraneko1's (Strata PR #6506, their
two-card Inkling 2 layout); this is our own code for a plain layer split.

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_POLY_CARD_GBS (each card's bandwidth for
--layer-split auto) and it was not in terminal/data/settings-register.json.

Add its entry as python tools/settings_register.py writes it, with
status research, owner poly and a note, and leave every other entry as
it was (as fd20bfc did).  A research setting is not listed in
docs/SETTINGS.md, so that page is not touched.

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

The two-parts-on-one-card runs (STRATA_POLY_CARDS=2, CPU experts) gave
the one-card tokens and top-20 probabilities for splits 3, 18 and 20,
but splits 6 and 6,18 never produced a token (worker threads spinning).
Say so in docs/models/inkling.md, and that 18 is the cut to use for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… layer keeps the pass

layer_head() set the loop's pass to 0 at the card's first layer.  When a
card starts at layer 6, the loop's first layer, each later pass came back
to that layer and set the pass to 0 again, so the loop never ended
(--layer-split 6 and 6,18 hung after loading).  Such a card now keeps the
pass there; next_layer() leaves it 0 after the last pass.  One card
(first layer 0) runs as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… RTX 2070 Super's speeds

Drop the known-bug note (b32a413 fixes the hang at layer 6).  Say that
--layer-split has run on two RTX 2070 Super 8 GB (vast.ai): every split
gave one card's tokens and top-20 probabilities with the experts on the
CPU, and with the experts in VRAM split 18 wrote 51.0 tok/s and split 6
48.5 where one card wrote 37.0 (IQ4_NL, 302 + 256, mean of 3 runs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
poly_layer_split_picks_test (by hand, needs the model and a card;
STRATA_POLY_CARDS lets one card run the parts) writes greedy tokens on
one card and split, with the token picked on the card (eval_picks(),
picked(): no --top-probs) and from the logits, and wants the same ids.
It covers main's 3d28e5c (VecSzn: a split's greedy token from its
last card); before that fix the split picked on the card wrote 0 after
the first token.

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

Copy link
Copy Markdown
Contributor Author

Thanks, no worries. Rebased onto main with 3d28e5c and dropped our duplicate fix; kept the split test (poly_layer_split_picks_test). Same tokens as one card here too, --top-probs on and off. New head 2e05830.

@VecSzn
VecSzn merged commit 56690df into simplexai-labs:main Nov 23, 2026
2 checks passed
@VecSzn

VecSzn commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

It was merged into main and poly_layer_split_picks_test didn't build on windows because MSVC doesn't have setenv, so it's using _putenv_s now like main.cpp does (80190a3)

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