[PR #1748] [CLOSED] [Engine] Remote stage: run the later layers of a layer split on other PCs, over TCP (opt-in; Linux and Windows; Qwen3.8-Flash-Next) #3648

Closed
opened 2026-11-07 15:29:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1748
Author: @lask3802
Created: 10/9/2026
Status: ❌ Closed

Base: main ← Head: remote-stage-pr


📝 Commits (10+)

  • 6946676 Remote stage: run the later layers of a layer split on another PC over TCP
  • 2ba81af Remote stage tools: a node agent, a layer shipper and a split tuner
  • 5657d79 Remote stage docs and measurements: two and three PCs, two models
  • f6241ba stage_ship: pieces in flight at once; the agent checks each piece's sha256
  • fecb3c7 Remote stage: follow 0.1.43's decode defaults on both PCs
  • 9822a07 Remote stage: images (--vision) - the worker's layers get the main's positions
  • 6efea4a Remote stage docs: images, and the checks after the rebase onto 0.1.43
  • ef046e0 Remote stage: a stuck worker ends as a stuck main process does; parking turned off, not refused
  • ae6634f Remote stage: a worker's agent starts an ended worker again
  • 8aeb39e Remote stage: the main process connects again, a new main takes a silent worker over

📊 Changes

21 files changed (+8511 additions, -266 deletions)

View changed files

📝 CMakeLists.txt (+13 -1)
📝 docs/MULTI_GPU.md (+14 -1)
➕ docs/REMOTE_STAGE.md (+598 -0)
➕ docs/remote-stage/ENGINEERING.md (+823 -0)
📝 include/strata/core/expert_source.hpp (+12 -1)
📝 include/strata/core/verify.hpp (+42 -0)
➕ include/strata/net/stage_link.hpp (+247 -0)
📝 include/strata/prefill/prefill.hpp (+28 -0)
📝 metal/CMakeLists.txt (+1 -1)
📝 serve/server.py (+21 -1)
📝 serve/test_server.py (+84 -1)
📝 src/core/expert_source.cpp (+58 -38)
📝 src/core/verify.cpp (+126 -12)
➕ src/net/stage_link.cpp (+1364 -0)
➕ src/net/stage_link_test.cpp (+1028 -0)
📝 src/prefill/prefill.cpp (+117 -4)
📝 src/program/generate.cpp (+1075 -206)
➕ tools/stage_node.py (+877 -0)
➕ tools/stage_ship.py (+385 -0)
➕ tools/stage_tune.py (+758 -0)

...and 1 more files

📄 Description

Problem and result

A layer split hands a token from one stage to the next once per verify window, and each prompt chunk's rows once
per chunk, but both stages had to be cards in one PC. A model that one 10 GB card caches poorly stayed slow unless a
second card fit in the same box. This branch puts that hand-off on a TCP link, so the later layers can run on cards
in other PCs:

  • the main process runs layers [0, K), the head, the draft layer, sampling and the server:
    --layer-split K --split-device 0 --remote-stage HOST:PORT;
  • a worker process on another PC runs [K, 48) without the head: strata --serve --stage-worker PORT --stage-begin K;
    relay workers (--stage-end K2 --stage-next HOST:PORT) make three or more stages;
  • each process loads, caches and keeps the session of its own layers only;
  • Linux (POSIX sockets) and Windows (Winsock); a Windows PC can be a worker natively or under WSL2;
  • --pipeline-windows 2 on the main process (opt-in): its layers run the next decode window, on a guess, while the
    worker and the head verify this one; workers need no new flag or protocol;
  • STRATA_REMOTE_TIMING=1 prints each stage's own time per prompt chunk and per window;
  • images (--vision), recovery without a human, and peers that are not trusted (below);
  • three standard-library Python tools: a node agent that starts workers (tools/stage_node.py), a splitter that
    ships a node only its layers' bytes (tools/stage_ship.py), and a tuner that measures configurations
    (tools/stage_tune.py).

Without --remote-stage or --stage-worker nothing changes (see Approach).

Docs: docs/REMOTE_STAGE.md (use), docs/remote-stage/ENGINEERING.md (design, process, every number). The raw data
(every run's JSONL, the timing lines, the tuner reports, the benchmark scripts) is on the branch remote-stage-data
of my fork: https://github.com/lask3802/Strata/tree/remote-stage-data/bench/results/2026-10-10-remote-stage

This head is the same branch rebased onto 0.2.4.1; its checks and GPU runs are under Approach, "Rebased onto
0.2.4.1". The first subsection below was measured on the 0.2.0-beta head, and so
were the checks and faults under Validation; the later subsections (marked with their engines, 0.1.41 to 0.1.43.1)
are the earlier heads' runs, with the cards the other way round, kept for comparison. Each says where it was run
again.

Results on the 0.2.0-beta head

The same two PCs with their cards swapped since the earlier runs: the main process on an RTX 2080 Ti 11 GB (PCIe 3.0
x16) + Ryzen 9 5900XT, the worker on an RTX 3080 10 GB + Ryzen 9 5900X, 10 GbE, Linux; this head's build on both, the
node agent of this head on the worker. --kv int8 --kv-resident 32768 --max-context 131072 --spec 4, greedy, the
expert cache automatic, one run per row, all in one session. Short decode: nine prompts of 256 tokens, the mean.
Prefill / decode tok/s: prompts of 7.5K / 30K / 91K tokens read from 0 with 320-token answers (the same prompts as
the 0.1.41 table below). The split is K=26, --prefill 5888, without --pipeline-windows, as there. The route tail
skip is on (the 0.2.0-beta default), unlike in the 0.1.41 table.

configuration (0.2.0-beta) expert slots short decode 8K 32K 100K
an IQ3_S of Qwen3.8-Flash-Next, 2080 Ti alone 1,834 52.6 687 / 43.7 976 / 48.2 890 / 44.3
the same, 2080 Ti + 3080 (10 GbE), K=26, chunk 5888 2,881 + 3,210 74.0 899 / 61.2 1,483 / 63.8 1,530 / 61.6
UD-Q4_K_XL, 2080 Ti alone (its config as served, --resident-budget-gib 70) 957 31.5 502 / 26.8 572 / 29.2 562 / 25.9
UD-Q4_K_XL, 2080 Ti + 3080 (10 GbE), K=26, chunk 5888 1,598 + 2,108 48.5 689 / 39.6 1,119 / 43.9 1,187 / 42.0

Two PCs: decode +41% on the IQ3_S and +54% on UD-Q4_K_XL; the 91K prompt in 59 s instead of 102 (IQ3_S) and in 77 s
instead of 162 (UD-Q4_K_XL). The three-PC rows were not run (the third PC was not reachable).

Pipelined decode (--pipeline-windows 2), K=26, the 40 varied prompts of 200 tokens, one binary, order
off-on-on-off:

build off on on off gain
this head on 0.2.0-beta, 2080 Ti main (2,881 and 2,636 cache slots) 70.68 69.19 70.13 70.22 -0.8%

No gain on this pair at K=26, against +9-12% with the RTX 3080 as the main (below). Here the main process is the slow
side: 28.2-28.6 ms of its own per window against a 12.4-12.6 ms round trip (the K sweep below), so the overlap hides
the shorter of the two, and the 245 cache slots it costs the main process slow that longer part.

K on this pair. The balance moved with the cards: the 2080 Ti main is now about twice the worker's time per
window at K=26, so layers go to the worker. Same session, --pipeline-windows 2 unless marked, the worker on a copy
of the layers it needs; 12 of the 40 prompts x 200 tokens, three rounds (the median of the rounds' means), then three
~30K prompts read from 0 with 200 tokens each (the means); the per-window times are the main process's timing lines
over the 12 prompts (STRATA_REMOTE_TIMING=1):

K, layers on the main process --pipeline-windows low-context decode, tok/s ~30K prefill, tok/s ~30K decode, tok/s main process's part, ms a window round trip, ms a window cache slots, main + worker
26 2 67.95 1,409 58.0 28.59 12.61 2,636 + 3,210
22 2 69.75 1,574 59.5 23.26 16.48 2,910 + 3,030
18 2 69.91 1,403 62.9 19.11 21.01 3,142 + 2,876
16 2 68.78 1,350 63.3 17.24 23.22 3,312 + 2,781
14 2 68.81 1,284 60.8 15.43 25.69 3,471 + 2,681
12 2 65.39 1,233 58.4 14.91 28.02 3,489 + 2,639
26 again, after 12 2 68.06 1,411 59.7 28.18 12.44 2,636 + 3,210
18 0 69.75 1,430 63.4 20.43 20.56 3,367 + 2,876
22 0 70.90 1,591 61.3 25.05 16.64 3,142 + 3,030
Strata Link default (deferral on), 26 2 84.40 1,371 70.1 24.30 10.81 2,566 + 3,148
Strata Link default (deferral on), 22 0 85.13 1,543 73.3 22.42 14.07 3,082 + 2,957
Strata Link default (deferral on), 20 2 84.41 1,492 70.3 19.45 15.88 2,933 + 2,907
Strata Link default (deferral on), 20 0 85.40 1,507 75.8 20.39 15.87 3,160 + 2,907
Strata Link default (deferral on), 26 again 2 85.20 1,368 69.7 23.99 10.79 2,566 + 3,148

The main process's time per window and the worker's round trip cross between K=18 and K=22, and decode is flat
there (69.75-69.91, inside the run-to-run spread). Prompts pull the other way below K=22: at K=26 the main process is
the slowest stage per chunk (3.5 s against the worker's 2.4 s), at K=18 and lower the worker is (3.5-4.2 s), and
K=22, about even, reads a ~30K prompt 10% faster than any other K. Without the overlap decode is no slower at either
K tried (70.90 against 69.75 at K=22, 69.75 against 69.91 at K=18), so on this pair the overlap's gain does not show
at any K, while its 444 MiB cost the main process 225-248 cache slots.

The "Strata Link default" rows are my fork's build (this branch with #1887, #2690 and other changes, Expert
Deferral on as its default, STRATA_VERIFY_DEFER_CPU=1), on both PCs, in the same session after the rows above, with
its own flags (--max-context 262144 --prompt-cache 6 --pcie-frac 0 on both PCs) and the same prompts. They are not
this branch alone and not the same flags, so they are not an A/B against the rows above; they show where K lands when
a layer no longer waits for its CPU expert rows of low routing weight. Deferral changes the output (#2690 has its KL). With it,
decode is flat from K=26 to K=20 (84.4-85.4, the two K=26 runs 84.40 and 85.20), the main process's part still the
longer one at every K, and K=22 again reads a ~30K prompt fastest (+13% over K=26).

Images. As in the 0.1.43 table below: fixed expert sets on both PCs, the tail skip off, one-token windows, the
first token's distribution of vision_check's six picture questions and its text question, against the same build
on the 2080 Ti alone; the split at K=26 with and without the position table (STRATA_STAGE_POSITIONS=0):

prompts KL with the table KL without it top-1 the same, with / without
the text question 5.9e-5 5.9e-5 9 / 9 of 10
six pictures, geometric mean 2.6e-3 4.4e-3 53 / 51 of 60
the two table questions 1.8e-2, 1.5e-2 6.9e-2, 6.2e-2 10 / 8 and 9 / 9 of 10

With the table the pictures' geometric mean is 42% lower (better on 5 of 6; on the first, 3.9e-6 against 1.3e-6,
both near zero). With the table, 5 of the 7 answers on the split were the same text as on one card; the shapes list
and the screenshot's description were worded differently.

Answers. As in the 0.1.43 tables below: one-token windows, fixed expert sets on both PCs,
STRATA_ROUTE_TAIL_SKIP=0, greedy, two 4-turn conversations of 16K-token prompts (8 answers a run), K=26, each run
the first replay on a freshly started server:

what differs between the two runs cache slots on the main process answers the same
--pipeline-windows 0 vs 2, automatic cache 2,884 vs 2,636 2 of 8
0, automatic vs --expert-cache 2636 2,884 vs 2,999 0 of 8
0 at --expert-cache 2636 (three servers) and at 2300 (one), each against the first 2,999 each 8 of 8
2 at --expert-cache 2636 (three servers) and at 2300 (one), each against the first 2,760 each 8 of 8
2 with every third guess made wrong (STRATA_PIPELINE_FORCE_MISS=3), at 2636 and at 2300, against 2 2,760 8 of 8
0 vs 2 at the same --expert-cache (2636, and 2300) 2,999 vs 2,760 1 of 8

So on this head, at a fixed cache, every fresh server gave the first one's answers, with either setting (earlier:
2 of 3 servers at 0, 4 of 4 at 2). The comparison the table below makes, 0 against 2 at one cache size, could not be made here: on a native
pack --expert-cache N is a byte budget of N of the largest blobs, cut to the VRAM that is free less the reserves,
and --pipeline-windows 2's 444 MiB comes out of that free VRAM. At N=2636 and at N=2300 both arms hit that cut
(2,999 slots at 0 both times, 2,760 at 2), so the last row still compares two cache sizes. A smaller N, under
both cuts, was not run. Whether the forced misses happened is not shown either: the main process printed no
pipeline count line (STRATA_DECODE_TIMING=1 was set), so the FORCE_MISS row shows only that the variable changed
no answer.

Results (engine 0.1.41, before the pipelined decode)

PC A: RTX 3080 10 GB (PCIe 4.0 at x8), Ryzen 9 5900XT, 128 GB DDR4-3200, Linux. PC B: RTX 2080 Ti 11 GB, Ryzen 9
5900X, 64 GB DDR4-2400, Linux. PC C: RTX 3070 8 GB, Ryzen 7 5700X3D, 64 GB DDR4-3600, Windows 11. Links 1 GbE, and
10 GbE between A and B (~400 MB/s, slot-limited). --kv int8 --kv-resident 32768 --max-context 131072 --spec 4,
greedy, one run per row. Prefill / decode tok/s; prompts of 7.5K / 30K / 57K / 91K tokens with 320-token answers.
0.1.42 turned STRATA_ROUTE_TAIL_SKIP on by default for CUDA serve. The two-PC rows ran again on this head (the
first subsection, the cards swapped); the three-PC rows and the Windows clocks did not (Not run).

configuration short decode 8K 32K 100K
RVN IQ3_S, 3080 alone 39.9 791 / 38.1 1,118 / 37.2 1,120 / 38.0
RVN IQ3_S, A + B (1 GbE), K=26, chunk 5888 53.5 655 / 48.1 1,231 / 49.7 1,521 / 45.6
RVN IQ3_S, A + B + C (A-B 10 GbE), 24 / 16 / 8, C clocks locked 51.3 658 / 47.8 1,110 / 46.5 1,640 / 44.7
UD-Q4_K_XL, 3080 alone (the better of two runs: prefill with a RAM budget, decode without) 27.3 302 / 25.4 324 / 24.5 326 / 23.7
UD-Q4_K_XL, A + B (10 GbE), K=26, chunk 5888 38.8 659 / 34.4 1,147 / 36.9 1,164 / 33.6
UD-Q4_K_XL, A + B + C, 24 / 16 / 8, C locked 38.4 549 / 35.3 945 / 36.6 1,334 / 35.2

Two PCs: decode +18-44% on IQ3_S, and on UD-Q4_K_XL (which one 10 GB card caches poorly) +42% and a 100K prompt in
88 s instead of 293. Long prompts need a large chunk (5888-8192). A third PC adds a hop to every window: it paid for
100K prompts and cost 1-8% of decode; the tuner's eight three-stage splits of UD-Q4_K_XL tied within the spread.

Windows lowers a worker GPU's clocks between decode windows, while the other stages run. The RTX 3070 under
Windows (or WSL2) waited 12-22 ms for its 8 layers per window, and 3.7-4.1 ms with nvidia-smi -lgc 1500,1905 -lmc 7001,7001 (short decode 33.8 -> 41.8); the 2080 Ti under Linux held P2. The node agent can lock and reset the clocks
around a worker ("gpu_clocks", as administrator), and the tuner's report says when a Windows node has not.

Pipelined decode on a remote main (--pipeline-windows 2, engine 0.1.43 and later)

RTX 3080 main (layers 0-25), RTX 2080 Ti worker (26-47), 10 GbE, RVN IQ3_S, --spec 4, 40 varied prompts of 200
tokens, one binary per session, order off-on-on-off:

build off on on off gain
this branch on 0.1.43.1 (2152 and 1951 cache slots) 65.0 71.5 70.8 65.4 +9%
the same change on engine 0.1.43, another session 62.8 70.4 70.7 62.7 +12%

Both tables of this subsection ran again on this head with the cards swapped ("Pipelined decode" and "K on this
pair" above).

The overlap hides part of the main process's layers behind the round trip, so with it on it pays to move layers to
the worker until the two are about even. Same PCs, fp32 rows, --pipeline-windows 2, this branch with #1887 and my
bf16 branch on top; 12 of the 40 prompts x 200 tokens, and a ~30K prompt read from 0 then 200 tokens; medians of 3,
one session:

K, layers on the main process main process's part, ms a window round trip, ms a window decode, tok/s 30K prompt, tok/s decode after it, tok/s
26 22.6 16.6 70.3 1,351 53.3
24 19.3 19.1 73.4 1,218 58.8
22 17.0 21.6 73.1 1,158 59.2
20 15.3 24.1 71.4 1,130 55.9
26 again, at the end 22.8 16.6 70.9 1,369 54.3

Prompts pull the other way: on two PCs the worker is the slowest stage per chunk (3.5-4.6 s against the main
process's 2.2-2.9 s), so K=24 is +4-5% decode and -10% on long prompts against K=26. On three PCs (an RTX 3070 last
stage over 1 GbE, clocks locked, bf16 rows) the overlap gave +15% decode at 26 / 14 / 8 (59.3 -> 68.3 tok/s), and my
comment on the bf16 rows
has the three-PC splits.

choice gains costs
--pipeline-windows 2 +9-12% decode on two PCs, +15% on three 444 MiB of the main process's expert cache (about 200 slots here); with the automatic cache the answers differ from a run without it (below)
fewer layers on the main process decode, until its part matches the round trip prompt speed while a remote stage is the slowest per chunk (K=24: -10%)
another PC VRAM; long prompts once re-split (+12-16% at 30K here) a hop and its layers on every round trip; decode ties two PCs only after re-splitting
a Windows card's clocks left unlocked nothing to set up the RTX 3070's 8 layers took 11-13 ms a window, against 5.9 ms locked

Answers (run again on this head: "Answers" under the first subsection). The cache size is part of the result: a different slot count places other experts on the CPU, which
moves near-tie tokens, so with the automatic cache --pipeline-windows 2 compares two cache sizes, not two loops.
Measured with one-token windows (--spec 4 --mtp-max-t 1 --suffix-draft 0), STRATA_ROUTE_TAIL_SKIP=0, greedy, two
4-turn conversations of 16K-token prompts, 8 answers per run, the same two PCs. With the change on engine 0.1.43:

what differs between the two runs answers the same
--pipeline-windows 0 vs 2, automatic cache 2 of 8
0 at --expert-cache 1951 vs 0 at 2153 2 of 8 (the same answers differ)

So the note "The cache size changes no output bit" in generate.cpp (the cache sizing comment) does not hold on this
setup.

This branch on 0.1.43.1 at --expert-cache 1951, each run the first replay on a freshly started server, against the
branch's first --pipeline-windows 0 server:

runs servers with all 8 answers the same
0, the branch this one is built on 2 of 2
0, three more servers 2 of 3 (the third: 4 of 8)
2 4 of 4
2, every third or second guess made wrong (STRATA_PIPELINE_FORCE_MISS=3 / 2; 256-317 of about 545 windows undone per run) 2 of 3 (the third: 6 of 8)

The runs that differ took another word partway into an answer, with 0 as well as with 2. Later replays on one
server drift with either setting; the cause is not known.

Recovery (engine 0.1.43 and 0.1.43.1)

Every row below ran again on this head; those results are in Validation, beside these.

Two PCs fail in ways one PC does not (the worker ends, either PC restarts, the link drops), and each needed a person
before. Fault injection on A + B (10 GbE, RVN IQ3_S, K=26), agent and server, none needing a hand. The first seven
rows ran on 0.1.43 (371b400f), the last three on 0.1.43.1 with STRATA_REMOTE_CONNECT_S=60, against the build before
them (0936f027), and again at 4bbcb16e and 5c454ed6:

Fault That request The next request
the worker killed (kill -9) while idle waited for the agent's restart, answered after 45.6 s -
the worker killed in the middle of an answer 503, Retry-After: 30 (2.9 s) answered after 50.2 s
the same, streamed an error event of the server_error kind answered after 44.8 s
the worker stopped and started through its agent - answered in 1.6 s
the main engine killed while idle restarted by the server, took the worker over: answered after 20.5 s 1.2 s
the main engine killed in the middle of an answer the server's 503 for an engine that stopped answered after 13.4 s
the worker stopped while a request waited, started 70 s later answered after 109.6 s, past the 90 s check -
the worker stopped; a streamed client leaves after 20 s, a second request at once ended at the STOP, the engine kept (before: waited 60 s, then the engine ended) 503 after 58.2 s (before: 37.9 s, for an engine that stopped)
the worker started again - answered after 12.7-15.5 s
the worker's port taken by a listener that never answers 503 after 60.0 s (before: 310.5 s) -

Images (--vision, engine 0.1.43)

Run again on this head, on the swapped cards: "Images" under the first subsection.

On A + B (RVN IQ3_S), fixed expert sets, the tail skip off, the first token's distribution against the same model on
one card:

prompts KL
text, with or without the table 1.6e-4
six pictures, with the table, against without (STRATA_STAGE_POSITIONS=0) geometric mean 43% lower (better on 3, the table picture 7.4e-4 against 1.7e-2; slightly worse on 3, not explained)

With the served flags the answers were right (shapes, a table's numbers, a chart, a screenshot, text after them).

Byte for byte without a remote stage (earlier bases)

On this head: the five greedy prompts on one 2080 Ti against main (Validation, the first row); the 16K-token replay
was not run without a remote stage.

base check result
0.1.41 one card, five greedy prompts (one of 9,364 tokens): this branch twice, main once identical
0.1.42 fixed expert sets (the stock config does not repeat run to run), a 2 x 4-turn replay on a 16K-token prompt, main, this branch and #1887 twice each the second round 8 of 8; main's first run an outlier
0.1.43 the same replay: branch, main, main, branch all four pairs 8 of 8
0.1.43.1, no --pipeline-windows against the branch it is built on, two fresh servers each: the replay on the split and on one RTX 3080; five greedy prompts on the split the same
  • This PR was open before the 0.2.0-beta reset (closed with every open PR on 2026-10-19); this is the same branch
    rebased onto main e88ee39d. No maintainer agreement on scope yet.
  • #1256 (a model split across machines) was closed as not planned, and #482 (a networked pool) was declined because it
    cannot be tested across PCs here. This is opt-in and self-contained, and it can be tested on one PC with two cards
    (Approach, "Trying it on one PC"). #1055 had the idea for decode only. If it is not wanted upstream, that is fine:
    I will keep maintaining it in my fork, and the Windows clock finding above may be useful on its own.
  • CC-David-CC checked it against the in-process split: #1773 (three Tesla P4s, 9 of 9 exact) and #1813's parity gate
    (24 requests, passed on the earlier head f2673bd2).
  • @YukihiroHemmi's report on untrusted peers (at 4bbcb16e) is fixed here (Approach, "Untrusted peers").
  • #1887 (conversation checkpoints across the link) is stacked on this one.
  • #2689 and #2690 (Expert Deferral, STRATA_VERIFY_DEFER_CPU) came from this split's measurements but need no
    remote stage; they are their own PRs and are not part of this branch.

Approach

The link. The protocol (version 5) is a hello, then per-window and per-chunk messages: StageClient on the main
process, serve_stage on a worker (a receiving thread, double buffers, the take-over, a relay's idle hook),
StageRelay for a worker that forwards to the next. The hello checks the protocol, the geometry each PC read from
its own GGUF, the model pack's fingerprint, the K/V type, the window and context sizes, the prompt chunk (a worker
must be able to lend the main process's chunk whole) and --vision; the shared token is checked before anything
after the hello is read. The Verifier, Prefill and arena get hooks: set_no_head, set_remote
(remote_run_, remote_commit_), a pipelined chunk hand-off, and a layer range for the expert arena and
load_experts_gguf, so each PC loads and caches its own layers only.

Pipelined decode (--pipeline-windows 2, opt-in). Without it a decode window is the main process's own part
(head, drafter, its layers) and then the round trip through the remote stages, one after the other. With it, #1656's
two-stage loop runs on the main process: layers 0 to K-1 are the front stage, the worker followed by this PC's head
the last one. While the worker and the head verify window N, layers 0 to K-1 already run window N+1 on the guess that
N is accepted whole; a wrong guess is undone on this PC (GDN snapshot). The worker only ever gets verified windows, in
the serial loop's order. Both stages share the main process's GPU, so the second verifier of each and the snapshots,
444 MiB at K=26, are kept out of its expert cache (the log says so). The automatic default still resolves to 0 on a
remote main; --adapt-async turns it off (not measured there); a worker refuses it.

Recovery.

  • the node agent starts an ended worker again (5 s, doubling to 300 s; its last log kept as .prev.log);
  • the main process connects again at its start and at a request's start, within STRATA_REMOTE_CONNECT_S (180 s) in
    all, the hello's reply included; a client that goes away ends the wait and the engine stays; a link lost in the
    middle of a request still ends the engine, and the server starts it again; INFO remote_stage_wait=S lines keep
    the server's 90 s frozen-engine check off and reach the client as keep-alives;
  • a new main process takes over a worker silent for STRATA_REMOTE_TAKEOVER_S (30 s);
  • a relay closes its main process's connection when its next worker is gone, seen while idle;
  • the stall watchdog (#29) watches each message a worker serves;
  • a worker that cannot lend the buffers for the main process's chunk lends for its own (#2090, #340);
  • the server answers a remote stage's error with 503 and Retry-After: 30, not 400.

Untrusted peers. Any host reaching a worker's port could end it without a token: messages were parsed before the
hello, and T * handoff_floats wrapped before T was bounded. Now a worker reads nothing but a hello first (10 s in
all) and nothing more until its token is checked, and bounds T first; the main process caps an error reply at 64 KiB.
stage_link_test sends these headers by hand; each of ten mutations that undo one fix failed a check when it was
written (two of them only on Windows, where a socket's shutdown does not wake a recv).

Images. A picture's tokens rotate by M-RoPE positions that are not their cell index. The protocol's Positions
message (the main process sends the table before a request with a picture, the identity after it) and vision in the
hello carry them; a relay forwards the table.

Following upstream. Written on fb58e0d (0.1.41), now on main e88ee39d (0.2.0-beta, engine 0.1.45.3). What each
release needed here:

  • 0.1.42: workers take the main process's STRATA_ROUTE_TAIL_SKIP rank from the hello; the CPU prefill share's
    every-expert-cached check counts the process's own layers.
  • 0.1.43: the tail-skip default counts only a process's own layers' experts; a remote main keeps the probed PCIe
    share under STRATA_PCIE_AUTO_SPLIT=1; STRATA_ADAPT_OVERLAP was left opt-in on a worker, not faster there (6
    interleaved pairs: decode median 64.19 tok/s on, 64.33 off).
  • 0.1.43.1: #2090 halves a chunk whose loan does not fit, but a worker reads the main process's chunk whole, so it
    lends for its own chunk or names the --prefill that fits; #2010 made the overlap opt-in everywhere; the 503's
    Retry-After goes through upstream's _json.
  • 0.1.44 to 0.2.0-beta (this rebase; the last commit, "follow 0.1.44 to 0.2.0-beta on both PCs"):
    --prefill-head-alias is refused with a remote stage (a worker has no head); a Qwen3.6-35B-A3B file is refused with
    the remote stage's flags (its own engine path has no layer split and skips an unknown option in serve mode); a
    remote stage is refused on the Metal build (its window runs init, run and commit itself, past the hooks; the Metal
    build links the link's code from the first commit on); --adapt-async 1 is turned off with a line on a worker
    and, in the expert arena's mode, on a remote main; the 8192 automatic chunk cap of a layer split on gfx12 applies to a remote main; pin by
    need (STRATA_PIN_BY_NEED=1) is off with a layer range (its padded stride does not fit a range's packed arena) and
    the log says so. A worker's arena counts its deferred registration slices (STRATA_DEFERRED_REGISTER=1) from its
    range's first layer. The moved lend and refill are upstream's current ones (STRATA_REFILL_PARTS, the planned
    segment's exact chunk, 0.2's planned_chunk), which a worker calls with exact 0; Verifier::run calls the
    remote hook before upstream's prelaunch check; STRATA_HANDOFF_PIPE's pieces stay in-process only; the server's
    Retry-After uses _json's retry_after. Read in the code without a change: 0.2's host-aware prompt plan and
    STRATA_RAM_ADAPT2 act on the mapped file tier only, and the sm_86 / sm_60 defaults are each PC's own. The
    conflicts and how each side was kept are in ENGINEERING.md ("After the rebase onto 0.2.0-beta").

What changed:

file change
include/strata/net/stage_link.hpp, src/net/stage_link.cpp (new) the protocol (version 5), StageClient, StageRelay, serve_stage; a connect with a deadline and a stop flag; alive, abort; a hello first, sizes bounded before they are multiplied; POSIX and Winsock
src/net/stage_link_test.cpp (new) the link over loopback, crafted headers included
src/program/generate.cpp the stage flags and their checks; the layer range for the arena, weights, profile and session; the worker's serve loop and relay; the head-only stage; the hello; timing lines; the image position table; the watchdog over a worker's messages; the reconnect; --pipeline-windows on a remote main
include/strata/core/verify.hpp, src/core/verify.cpp set_no_head, set_remote; for --pipeline-windows, the round trip on a job thread, the head launched when the rows are back, remote_settle for a drain stopped at an error, the job joined when the engine ends
serve/server.py, serve/test_server.py a remote stage's ERR is a 503 with Retry-After: 30; the wait line is a keep-alive
include/strata/prefill/prefill.hpp, src/prefill/prefill.cpp the pipelined chunk hand-off
include/strata/core/expert_source.hpp, src/core/expert_source.cpp a layer range for the arena and load_experts_gguf
CMakeLists.txt, metal/CMakeLists.txt stage_link.cpp, ws2_32 on Windows, stage_link_test; the Metal binary links stage_link.cpp
tools/stage_node.py, tools/stage_ship.py, tools/stage_tune.py, tools/test_stage_node.py (new) the agent, the splitter, the tuner, their tests
docs/REMOTE_STAGE.md, docs/remote-stage/ENGINEERING.md (new), docs/MULTI_GPU.md the docs

What it leaves alone. Without --remote-stage or --stage-worker no new code path runs: the new Verifier,
Prefill and arena hooks are inert at their defaults (no range, no remote callbacks, no_head false). On a remote
main without --pipeline-windows (or with 0), its windows go through the link on the request's thread and the cache
keeps its size. With a remote stage these are refused at start: --batch, --peer-device, --control-vector (and
the speed projection), --expert-cache-remote, --prefill-head-alias, --pipeline-windows on a worker, a
Qwen3.6-35B-A3B file and the Metal build; the prompt cache, conversation parking, mid-prompt checkpoints,
--kv-grow, pin by need, and --adapt-async 1 on a worker and in the arena mode on the main PC are turned off
with a log line. Not touched: setup,
the SYCL port's copies, the HIP-specific code; in the server, only lines that only a remote stage prints.

Trying it on one PC

Two cards in one PC are enough. The worker runs on one card and the main process on the other, over 127.0.0.1; the
reference is the in-process split of the same two cards, so their answers can be compared token for token.

# the worker: layers 26-47 on the second card
CUDA_VISIBLE_DEVICES=1 strata --serve --stage-worker 7841 --stage-begin 26 --stage-bind 127.0.0.1 \
  <the model's args, as in the main config> --prefill 5888
# the main process: layers 0-25 and the head on the first card; in the server config's "args":
#   "--layer-split", "26", "--split-device", "0", "--remote-stage", "127.0.0.1:7841"   (and CUDA_VISIBLE_DEVICES=0)
# the reference: the same config with "--layer-split", "26", "--split-device", "1" and no --remote-stage

Exact comparisons need the run-to-run noise off on both: the same --expert-cache N (with auto the slot count
moves with the reserves and other flags, and an expert computed on the CPU instead of the GPU gives other numbers),
fixed expert sets (--pcie-frac 0 --adapt-every 0 --adapt-swaps 0), STRATA_ROUTE_TAIL_SKIP=0,
STRATA_PREFILL_CPU_SHARE=0, STRATA_IQ_MT_MIN=1, and one-token windows (--mtp-max-t 1 --suffix-draft 0). With
MTP's longer windows one card does not repeat its own greedy answers (upstream main 7695859a, RTX 3080 alone, RVN
IQ3_S, served decode flags, fixed expert sets, 40 prompts, two runs: 32 of 40 the same, 35 of 40 with
STRATA_IQ_MT_MIN=1), so compare with one-token windows.

Rebased onto 0.2.4.1 (2026-10-24)

This head is the branch rebased onto main 8183c6b6 (v0.2.4.1 and one docs commit, engine 0.1.49.1). The rebase applied
with no conflicts, and git range-diff against the 0.2.3 head (bb7984df) shows every commit as the same patch. 0.2.4's
DeepSeek V4.1-Flash engine (strata-dsv41, src/dsv41) is a binary of its own and has no remote stage.

Checked on this head (Linux, the build of the runs below): the build, stage_link_test and five CPU tests
(conv_cache_test, spec_prob_test, batch_rows_test, conversation_validation_test,
conversation_transfer_test) passed. Not run on this head: the Windows build and ctest.

GPU runs on this head (2026-10-24). The same two PCs, model and runs as in the 0.2.3 section below: the main
process on the RTX 2080 Ti, the worker on the RTX 3080, 10 GbE, Linux, K=26, --max-context 131072, greedy, this
head's build on both. The CI container on the main PC's host used 0 cores during every run. In the 0.2.3 section
below, "this head" means the 0.2.3 head (bb7984df); in the sections before Approach, it means the 0.2.0-beta head
(a3e15682).

check 0.2.4.1 (this head) 0.2.3 (bb7984df)
one card, no remote flag, exact flags: five greedy prompts against main byte-identical byte-identical
the split answers the five prompts 5 of 5 5 of 5
low-context decode, 2080 Ti alone (median of 3) 53.58 tok/s 51.85 tok/s
low-context decode, split, --pipeline-windows 2 (median of 3) 67.64 tok/s (+26.2%) 66.73 tok/s (+28.7%)
~32K prompt, 2080 Ti alone: prefill / decode 922 / 44.9 tok/s 912 / 42.3 tok/s
~32K prompt, split, --pipeline-windows 2: prefill / decode 1,363 / 61.9 tok/s 1,331 / 59.6 tok/s
images (--vision, split): six picture questions, then a text turn 7 answers, no error 7 answers, no error

The "2080 Ti alone" rows ran main's build (the default path is byte-identical). The 0.2.3 split rows overlapped a
build on the main PC's host (see the 0.2.3 section), so those are, if anything, low.

Faults on this head, all as on 0.2.3 (--serve, the split, a 100-token request):

fault the request in flight the next request
F1: the worker killed 15 s into a request HTTP 503, Retry-After: 30, "remote stage: the peer closed the connection" answered after 45.2 s
F2: the same, streaming a server_error stream event, same message answered after 51.3 s
F3: the worker killed while idle - answered after 61.5 s
F4: the node agent stopped and started - answered after 1.3 s; the main kept its engine

Rebased onto 0.2.3 (2026-10-23)

This head is the branch rebased onto main 5c8dd322 (v0.2.3, engine 0.1.48). Git stopped at two conflicts, both in
the first commit and both beside new upstream lines: the strata target in CMakeLists.txt (upstream's DFlash2 tool
targets and strata_utf8_manifest, next to src/net/stage_link.cpp and ws2_32) and two adjacent member blocks in
prefill.hpp (the DFlash2 taps, next to remote_rows_from_). No remote-stage code changed in the rebase.

Two 0.2.x defaults could meet a remote stage, and neither does:

  • --conversation-cache-mib is sized from the free RAM under --serve when it is not given (#3493). A remote stage
    still sets it to 0 before that sizing, on the main process and on a worker, so parking stays off as before.
  • --draft dflash2 is refused under --serve, and a remote stage needs --serve. The verifier's taps also need the
    whole model in one stage (lb == 0, le == n_layers).

Checked on this head (Windows, MSVC 19.44 + CUDA 13.0, -DSTRATA_BUILD_CONVERSATION_TESTS=ON):

check result
build (every target but hc_persist_parity) passed
stage_link_test, the 7 conversation tests passed
ctest overall 81 of 86 passed

The other 5 fail the same way on v0.2.3 itself in the same environment:

  • hc_persist_parity and hc_persist_default_off are not run, because the test calls setenv, which MSVC does not have.
  • gemm_bf16_parity and gr_upmix_parity cannot find the CUDA DLLs on ctest's PATH. With the DLLs on the PATH,
    gemm_bf16_parity passes and gr_upmix_parity fails 21 cases, also on v0.2.3.
  • ple_parity needs a model file.

GPU runs on this head (2026-10-23). The same two PCs as below: the main process on the RTX 2080 Ti, the worker
on the RTX 3080, 10 GbE, Linux, this head's build on both. The IQ3_S of Qwen3.8-Flash-Next, K=26,
--max-context 131072, greedy. In the older sections below, "this head" means the 0.2.0-beta head (a3e15682).

check 0.2.3 (this head) 0.2.0-beta (a3e15682)
one card, no remote flag, exact flags: five greedy prompts against main byte-identical byte-identical
the split answers the five prompts 5 of 5 5 of 5
low-context decode, 2080 Ti alone (median of 3) 51.85 tok/s 54.02 tok/s
low-context decode, split, --pipeline-windows 2 (median of 3) 66.73 tok/s (+28.7%) 68.04 tok/s (+26.0%)
~32K prompt, 2080 Ti alone: prefill / decode 912 / 42.3 tok/s 945 / 47.6 tok/s
~32K prompt, split, --pipeline-windows 2: prefill / decode 1,331 / 59.6 tok/s 1,394 / 57.8 tok/s
images (--vision, split): six picture questions, then a text turn 7 answers, no error 7 answers, no error

The split's speed runs overlapped a build on the main PC's host (4.5-6.8 cores for three of the four minutes), so
its numbers on this head are, if anything, low.

Faults on this head, all as on 0.2.0-beta (--serve, the split, a 100-token request):

fault the request in flight the next request
F1: the worker killed 15 s into a request HTTP 503, Retry-After: 30, "remote stage: the peer closed the connection" answered after 45.4 s
F2: the same, streaming a server_error stream event, same message answered after 49.9 s
F3: the worker killed while idle - answered after 61.5 s
F4: the node agent stopped and started - answered after 1.3 s; the main kept its engine

Validation

Revision: this head, a3e15682 (19 commits on main e88ee39d) (the builds and tests below ran on it before a last wording fix in ENGINEERING.md; git diff outside
docs/ is empty). The upstream baseline for the Python suites is
e88ee39d itself, run the same way in the same environment.

Passed:

  • Windows 11, MSVC 2022 (19.44.35229) + CUDA 13.0.88, Ninja, Release, sm_86 (-DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON): cmake --build build --target strata stage_link_test conv_cache_test draft_kv_plan_test split_ring_test message_boundary_test coupled_draft_test spec_prob_test bf16_bits_test batch_rows_test batch_groups_test conversation_cache_test conversation_validation_test, rc 0, strata.exe
    linked. Besides C4996 (getenv deprecated, as in main's own files), every MSVC warning is on a line from
    main.

  • The same build, the CPU tests with CUDA_VISIBLE_DEVICES=-1, each rc 0: stage_link_test (all passed),
    conv_cache_test, draft_kv_plan_test, split_ring_test (23 checks), message_boundary_test (21),
    coupled_draft_test, spec_prob_test (72 cases), bf16_bits_test, batch_rows_test, batch_groups_test,
    conversation_cache_test (4772 checks), conversation_validation_test (972 host-only checks).

  • Linux (Ubuntu 24.04 container), GCC 13.3 + CUDA 13.0.88, sm_75 + sm_86, Ninja, Release, from a clean build
    directory (-DSTRATA_ENABLE_CUDA=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON):
    ninja strata stage_link_test, rc 0; stage_link_test passes.

  • g++ -std=c++20 -O2 -Wall -Wextra -c of src/net/stage_link.cpp and src/net/stage_link_test.cpp (GCC 13.3):
    no warning.

  • python -m unittest tools.test_stage_node on Linux (Python 3.12.3): 48 tests OK; python -m pytest tools/test_stage_node.py on Windows (Python 3.10.8, pytest 9.0.2): 48 passed.

  • python -m pytest serve on Windows (Python 3.10.8): 867 passed, 17 skipped (main e88ee39d: 864 passed, 17
    skipped; the three more are this branch's server tests).

  • python -m pytest tools/test_setup_*.py on Windows: 681 passed, 2 skipped, and the same 22 failures as main
    (below); this branch does not touch setup.

  • GPUs, this head's Linux build (the same binary on both PCs) against the baseline's: the main process on an RTX
    2080 Ti 11 GB (PCIe 3.0 x16) + Ryzen 9 5900XT, the worker on an RTX 3080 10 GB + Ryzen 9 5900X, 10 GbE, Linux; an
    IQ3_S of Qwen3.8-Flash-Next (the worker with its layers' shipped bytes), K=26, --prefill 5888, --max-context 131072 on both, the node agent (tools/stage_node.py) of this head on the worker:

    check how result
    default path, no remote flag one 2080 Ti, five greedy prompts (default_path_check), fixed expert sets and one-token windows, this head against main e88ee39d byte-identical (the five answers' md5 the same)
    answers on the split the same five prompts, the same exact flags on both PCs, --pipeline-windows 0 all five answered, no error; they differ from one card of the same build (another expert placement: 1,837 cache slots on one card, 2,884 + 3,210 on the split), expected and not a check
    decode, low context 12 prompts x 200 tokens, three rounds, the median of the rounds' means; the 2080 Ti alone (the baseline) against the split with --pipeline-windows 2 54.02 against 68.04 tok/s (+26.0%), 0 errors in either
    a ~32K prompt read from 0, then 200 tokens the same two prefill 944.8 against 1,393.6 tok/s, decode 47.6 against 57.8 tok/s
    images --vision on both PCs, the split, --pipeline-windows 2; four pictures, six questions, then a text question 7 answers, none an error

    Faults, on held splits (--pipeline-windows 2), the agent restarting the worker. The first four rows are one
    held split; the main engine's rows and the worker stopped while a request waits are a second, with
    STRATA_REMOTE_CONNECT_S unset (180 s); the last three a third, with STRATA_REMOTE_CONNECT_S=60, as earlier:

    fault that request the next request earlier (0.1.43 / 0.1.43.1)
    the worker killed (kill -9) 15 s into an answer 503, Retry-After: 30, "remote stage: the peer closed the connection" answered after 45.1 s 50.2 s
    the same, streamed an error event of the server_error kind answered after 51.0 s 44.8 s
    the worker killed while idle answered after 61.6 s (the agent's restart and load) - 45.6 s
    the worker stopped and started through its agent - answered after 1.3 s, the main engine kept 1.6 s
    the main engine killed (kill -9) while idle the server started it again: answered after 11.0 s 1.1 s 20.5 s, then 1.2 s
    the main engine killed 3 s into an answer the server's 503 for an engine that stopped (4.5 s) answered after 10.6 s 13.4 s
    the worker stopped while a request waited, started 70 s later answered after 107.5 s, the main engine kept - 109.6 s
    the worker stopped; a streamed client leaves after 20 s, a second request at once ended with the client, the engine kept 503 after 58.1 s, "cannot connect to ...: Connection refused" 58.2 s
    the worker started again - answered after 11.1 and 11.4 s 12.7-15.5 s
    the worker's port taken by a listener that never answers 503 after 60.0 s, "receive failed: timed out (no reply to the hello)" - 60.0 s

Failed:

  • python -m pytest tools/test_setup_*.py on Windows (Python 3.10.8): 22 failures (test_setup_download's
    parallel download, two of test_setup_engine_hash's refusal tests, and 19 subtests of test_setup_golden).
    main e88ee39d fails the same 22 in the same environment, test for test; I have not looked into them, and none
    touches a file of this branch.

Not run:

  • On GPUs on this head: a relay (three PCs) and the Windows worker, so the three-PC rows of the 0.1.41 table, the
    Windows clock finding and the three-PC splits stay as measured then: the third PC, the Windows one, did not answer
    on the day. The new refusals and the turned-off switches of 0.1.44 to 0.2 are read from the code, not run.
  • --pipeline-windows 0 against 2 at one cache slot count (both arms' --expert-cache hit the free-VRAM cut; see
    "Answers" above), and a count of the windows the forced misses undid.
  • The HIP (ROCm) and SYCL builds on this head (the SYCL port keeps its own copies of the files this changes, and HIP
    builds the CUDA target's sources); the Metal build (no Mac).
  • MSVC /W4 on the link's files on this head.
  • --prefill-head-alias, Qwen3.6-35B-A3B and gfx12 checks: no file or card for them here.

Limits

  • Qwen3.8-Flash-Next only (48 layers); the hello checks the geometry.
  • AMD or Intel cards (HIP and SYCL built on earlier heads, not run); the SYCL port has no remote stage.
  • --pipeline-windows 2: byte for byte with windows of more than one token; how often a guess holds; a Windows main;
    a drain stopped at an error with a worker window in flight (found in review, not run).
  • Images through a relay worker or with other models; Windows as the main PC.
  • Other quantizations of the family (official IQ3_S, IQ3_XXS, IQ2_XS, UD-IQ4_XS).
  • Correctness against the in-process split with fixed caches; the 0.1.41 results are one run per configuration
    (decode moved by up to ~14% between two runs).
  • Recovery not covered: a network partition, a relay's next worker ending on GPUs (loopback only), a Windows PC on
    either side of a fault, a worker lending for its own chunk on GPUs, a reconnect in the middle of a request. A ring
    topology; a WAN.
  • Plain TCP, not encrypted: token ids and hidden states cross the network in clear. The shared token only keeps other
    LAN hosts from driving a worker; without it a host gets no further than a hello. A worker serves one main process
    at a time, so a host that keeps connecting can still hold its port. The docs say to use it on a trusted LAN or
    inside a tunnel.
  • The node agent's token lets a request start the engine with whitelisted flags and write files under its data
    directory: a credential, LAN only.
  • One feature in one PR; I can split it into the engine hooks, the network stage, the pipelined decode and the tools
    if that is easier to review.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1748 **Author:** [@lask3802](https://github.com/lask3802) **Created:** 10/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `remote-stage-pr` --- ### 📝 Commits (10+) - [`6946676`](https://github.com/Niko1221/Strata/commit/6946676e5ed0d146ee8cd7f89b1f38e4bfbabc38) Remote stage: run the later layers of a layer split on another PC over TCP - [`2ba81af`](https://github.com/Niko1221/Strata/commit/2ba81af0392be9559a231357ba1426cccad7f528) Remote stage tools: a node agent, a layer shipper and a split tuner - [`5657d79`](https://github.com/Niko1221/Strata/commit/5657d7979185c6a41f062f01745d4230b573b70c) Remote stage docs and measurements: two and three PCs, two models - [`f6241ba`](https://github.com/Niko1221/Strata/commit/f6241ba8b6d599730129145d16a1bd2b632fcad4) stage_ship: pieces in flight at once; the agent checks each piece's sha256 - [`fecb3c7`](https://github.com/Niko1221/Strata/commit/fecb3c7ebe200a409f465135702673fe59e07831) Remote stage: follow 0.1.43's decode defaults on both PCs - [`9822a07`](https://github.com/Niko1221/Strata/commit/9822a07abb2b70635beda0bb77be94c8a869a3a5) Remote stage: images (--vision) - the worker's layers get the main's positions - [`6efea4a`](https://github.com/Niko1221/Strata/commit/6efea4a6b10f86b97856c2e549101483fe079090) Remote stage docs: images, and the checks after the rebase onto 0.1.43 - [`ef046e0`](https://github.com/Niko1221/Strata/commit/ef046e0b86d7ee3f78590d8c896ee6c1e5444d3d) Remote stage: a stuck worker ends as a stuck main process does; parking turned off, not refused - [`ae6634f`](https://github.com/Niko1221/Strata/commit/ae6634f8831ac5be3eeaff96fed68bb8a2219052) Remote stage: a worker's agent starts an ended worker again - [`8aeb39e`](https://github.com/Niko1221/Strata/commit/8aeb39e04903573db20f6d651249f5148a163afd) Remote stage: the main process connects again, a new main takes a silent worker over ### 📊 Changes **21 files changed** (+8511 additions, -266 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+13 -1) 📝 `docs/MULTI_GPU.md` (+14 -1) ➕ `docs/REMOTE_STAGE.md` (+598 -0) ➕ `docs/remote-stage/ENGINEERING.md` (+823 -0) 📝 `include/strata/core/expert_source.hpp` (+12 -1) 📝 `include/strata/core/verify.hpp` (+42 -0) ➕ `include/strata/net/stage_link.hpp` (+247 -0) 📝 `include/strata/prefill/prefill.hpp` (+28 -0) 📝 `metal/CMakeLists.txt` (+1 -1) 📝 `serve/server.py` (+21 -1) 📝 `serve/test_server.py` (+84 -1) 📝 `src/core/expert_source.cpp` (+58 -38) 📝 `src/core/verify.cpp` (+126 -12) ➕ `src/net/stage_link.cpp` (+1364 -0) ➕ `src/net/stage_link_test.cpp` (+1028 -0) 📝 `src/prefill/prefill.cpp` (+117 -4) 📝 `src/program/generate.cpp` (+1075 -206) ➕ `tools/stage_node.py` (+877 -0) ➕ `tools/stage_ship.py` (+385 -0) ➕ `tools/stage_tune.py` (+758 -0) _...and 1 more files_ </details> ### 📄 Description ## Problem and result A layer split hands a token from one stage to the next once per verify window, and each prompt chunk's rows once per chunk, but both stages had to be cards in one PC. A model that one 10 GB card caches poorly stayed slow unless a second card fit in the same box. This branch puts that hand-off on a TCP link, so the later layers can run on cards in **other PCs**: - the main process runs layers [0, K), the head, the draft layer, sampling and the server: `--layer-split K --split-device 0 --remote-stage HOST:PORT`; - a worker process on another PC runs [K, 48) without the head: `strata --serve --stage-worker PORT --stage-begin K`; relay workers (`--stage-end K2 --stage-next HOST:PORT`) make three or more stages; - each process loads, caches and keeps the session of its own layers only; - Linux (POSIX sockets) and Windows (Winsock); a Windows PC can be a worker natively or under WSL2; - `--pipeline-windows 2` on the main process (opt-in): its layers run the next decode window, on a guess, while the worker and the head verify this one; workers need no new flag or protocol; - `STRATA_REMOTE_TIMING=1` prints each stage's own time per prompt chunk and per window; - images (`--vision`), recovery without a human, and peers that are not trusted (below); - three standard-library Python tools: a node agent that starts workers (`tools/stage_node.py`), a splitter that ships a node only its layers' bytes (`tools/stage_ship.py`), and a tuner that measures configurations (`tools/stage_tune.py`). Without `--remote-stage` or `--stage-worker` nothing changes (see Approach). Docs: `docs/REMOTE_STAGE.md` (use), `docs/remote-stage/ENGINEERING.md` (design, process, every number). The raw data (every run's JSONL, the timing lines, the tuner reports, the benchmark scripts) is on the branch `remote-stage-data` of my fork: https://github.com/lask3802/Strata/tree/remote-stage-data/bench/results/2026-10-10-remote-stage This head is the same branch rebased onto 0.2.4.1; its checks and GPU runs are under Approach, "Rebased onto 0.2.4.1". The first subsection below was measured on the 0.2.0-beta head, and so were the checks and faults under Validation; the later subsections (marked with their engines, 0.1.41 to 0.1.43.1) are the earlier heads' runs, with the cards the other way round, kept for comparison. Each says where it was run again. ### Results on the 0.2.0-beta head The same two PCs with their cards swapped since the earlier runs: the main process on an RTX 2080 Ti 11 GB (PCIe 3.0 x16) + Ryzen 9 5900XT, the worker on an RTX 3080 10 GB + Ryzen 9 5900X, 10 GbE, Linux; this head's build on both, the node agent of this head on the worker. `--kv int8 --kv-resident 32768 --max-context 131072 --spec 4`, greedy, the expert cache automatic, one run per row, all in one session. Short decode: nine prompts of 256 tokens, the mean. Prefill / decode tok/s: prompts of 7.5K / 30K / 91K tokens read from 0 with 320-token answers (the same prompts as the 0.1.41 table below). The split is K=26, `--prefill 5888`, without `--pipeline-windows`, as there. The route tail skip is on (the 0.2.0-beta default), unlike in the 0.1.41 table. | configuration (0.2.0-beta) | expert slots | short decode | 8K | 32K | 100K | |---|---|---:|---:|---:|---:| | an IQ3_S of Qwen3.8-Flash-Next, 2080 Ti alone | 1,834 | 52.6 | 687 / 43.7 | 976 / 48.2 | 890 / 44.3 | | the same, 2080 Ti + 3080 (10 GbE), K=26, chunk 5888 | 2,881 + 3,210 | 74.0 | 899 / 61.2 | 1,483 / 63.8 | 1,530 / 61.6 | | UD-Q4_K_XL, 2080 Ti alone (its config as served, `--resident-budget-gib 70`) | 957 | 31.5 | 502 / 26.8 | 572 / 29.2 | 562 / 25.9 | | UD-Q4_K_XL, 2080 Ti + 3080 (10 GbE), K=26, chunk 5888 | 1,598 + 2,108 | 48.5 | 689 / 39.6 | 1,119 / 43.9 | 1,187 / 42.0 | Two PCs: decode +41% on the IQ3_S and +54% on UD-Q4_K_XL; the 91K prompt in 59 s instead of 102 (IQ3_S) and in 77 s instead of 162 (UD-Q4_K_XL). The three-PC rows were not run (the third PC was not reachable). **Pipelined decode** (`--pipeline-windows 2`), K=26, the 40 varied prompts of 200 tokens, one binary, order off-on-on-off: | build | off | on | on | off | gain | |---|---:|---:|---:|---:|---:| | this head on 0.2.0-beta, 2080 Ti main (2,881 and 2,636 cache slots) | 70.68 | 69.19 | 70.13 | 70.22 | -0.8% | No gain on this pair at K=26, against +9-12% with the RTX 3080 as the main (below). Here the main process is the slow side: 28.2-28.6 ms of its own per window against a 12.4-12.6 ms round trip (the K sweep below), so the overlap hides the shorter of the two, and the 245 cache slots it costs the main process slow that longer part. **K on this pair.** The balance moved with the cards: the 2080 Ti main is now about twice the worker's time per window at K=26, so layers go to the worker. Same session, `--pipeline-windows 2` unless marked, the worker on a copy of the layers it needs; 12 of the 40 prompts x 200 tokens, three rounds (the median of the rounds' means), then three ~30K prompts read from 0 with 200 tokens each (the means); the per-window times are the main process's timing lines over the 12 prompts (`STRATA_REMOTE_TIMING=1`): | K, layers on the main process | `--pipeline-windows` | low-context decode, tok/s | ~30K prefill, tok/s | ~30K decode, tok/s | main process's part, ms a window | round trip, ms a window | cache slots, main + worker | |---|---:|---:|---:|---:|---:|---:|---| | 26 | 2 | 67.95 | 1,409 | 58.0 | 28.59 | 12.61 | 2,636 + 3,210 | | 22 | 2 | 69.75 | 1,574 | 59.5 | 23.26 | 16.48 | 2,910 + 3,030 | | 18 | 2 | **69.91** | 1,403 | 62.9 | 19.11 | 21.01 | 3,142 + 2,876 | | 16 | 2 | 68.78 | 1,350 | 63.3 | 17.24 | 23.22 | 3,312 + 2,781 | | 14 | 2 | 68.81 | 1,284 | 60.8 | 15.43 | 25.69 | 3,471 + 2,681 | | 12 | 2 | 65.39 | 1,233 | 58.4 | 14.91 | 28.02 | 3,489 + 2,639 | | 26 again, after 12 | 2 | 68.06 | 1,411 | 59.7 | 28.18 | 12.44 | 2,636 + 3,210 | | 18 | 0 | 69.75 | 1,430 | 63.4 | 20.43 | 20.56 | 3,367 + 2,876 | | 22 | 0 | 70.90 | 1,591 | 61.3 | 25.05 | 16.64 | 3,142 + 3,030 | | Strata Link default (deferral on), 26 | 2 | 84.40 | 1,371 | 70.1 | 24.30 | 10.81 | 2,566 + 3,148 | | Strata Link default (deferral on), 22 | 0 | 85.13 | 1,543 | 73.3 | 22.42 | 14.07 | 3,082 + 2,957 | | Strata Link default (deferral on), 20 | 2 | 84.41 | 1,492 | 70.3 | 19.45 | 15.88 | 2,933 + 2,907 | | Strata Link default (deferral on), 20 | 0 | 85.40 | 1,507 | 75.8 | 20.39 | 15.87 | 3,160 + 2,907 | | Strata Link default (deferral on), 26 again | 2 | 85.20 | 1,368 | 69.7 | 23.99 | 10.79 | 2,566 + 3,148 | The main process's time per window and the worker's round trip cross between K=18 and K=22, and decode is flat there (69.75-69.91, inside the run-to-run spread). Prompts pull the other way below K=22: at K=26 the main process is the slowest stage per chunk (3.5 s against the worker's 2.4 s), at K=18 and lower the worker is (3.5-4.2 s), and K=22, about even, reads a ~30K prompt 10% faster than any other K. Without the overlap decode is no slower at either K tried (70.90 against 69.75 at K=22, 69.75 against 69.91 at K=18), so on this pair the overlap's gain does not show at any K, while its 444 MiB cost the main process 225-248 cache slots. The "Strata Link default" rows are my fork's build (this branch with #1887, #2690 and other changes, Expert Deferral on as its default, `STRATA_VERIFY_DEFER_CPU=1`), on both PCs, in the same session after the rows above, with its own flags (`--max-context 262144 --prompt-cache 6 --pcie-frac 0` on both PCs) and the same prompts. They are not this branch alone and not the same flags, so they are not an A/B against the rows above; they show where K lands when a layer no longer waits for its CPU expert rows of low routing weight. Deferral changes the output (#2690 has its KL). With it, decode is flat from K=26 to K=20 (84.4-85.4, the two K=26 runs 84.40 and 85.20), the main process's part still the longer one at every K, and K=22 again reads a ~30K prompt fastest (+13% over K=26). **Images.** As in the 0.1.43 table below: fixed expert sets on both PCs, the tail skip off, one-token windows, the first token's distribution of `vision_check`'s six picture questions and its text question, against the same build on the 2080 Ti alone; the split at K=26 with and without the position table (`STRATA_STAGE_POSITIONS=0`): | prompts | KL with the table | KL without it | top-1 the same, with / without | |---|---:|---:|---| | the text question | 5.9e-5 | 5.9e-5 | 9 / 9 of 10 | | six pictures, geometric mean | 2.6e-3 | 4.4e-3 | 53 / 51 of 60 | | the two table questions | 1.8e-2, 1.5e-2 | 6.9e-2, 6.2e-2 | 10 / 8 and 9 / 9 of 10 | With the table the pictures' geometric mean is 42% lower (better on 5 of 6; on the first, 3.9e-6 against 1.3e-6, both near zero). With the table, 5 of the 7 answers on the split were the same text as on one card; the shapes list and the screenshot's description were worded differently. **Answers.** As in the 0.1.43 tables below: one-token windows, fixed expert sets on both PCs, `STRATA_ROUTE_TAIL_SKIP=0`, greedy, two 4-turn conversations of 16K-token prompts (8 answers a run), K=26, each run the first replay on a freshly started server: | what differs between the two runs | cache slots on the main process | answers the same | |---|---|---| | `--pipeline-windows 0` vs `2`, automatic cache | 2,884 vs 2,636 | 2 of 8 | | `0`, automatic vs `--expert-cache 2636` | 2,884 vs 2,999 | 0 of 8 | | `0` at `--expert-cache 2636` (three servers) and at 2300 (one), each against the first | 2,999 each | 8 of 8 | | `2` at `--expert-cache 2636` (three servers) and at 2300 (one), each against the first | 2,760 each | 8 of 8 | | `2` with every third guess made wrong (`STRATA_PIPELINE_FORCE_MISS=3`), at 2636 and at 2300, against `2` | 2,760 | 8 of 8 | | `0` vs `2` at the same `--expert-cache` (2636, and 2300) | 2,999 vs 2,760 | 1 of 8 | So on this head, at a fixed cache, every fresh server gave the first one's answers, with either setting (earlier: 2 of 3 servers at `0`, 4 of 4 at `2`). The comparison the table below makes, `0` against `2` at one cache size, could not be made here: on a native pack `--expert-cache N` is a byte budget of N of the largest blobs, cut to the VRAM that is free less the reserves, and `--pipeline-windows 2`'s 444 MiB comes out of that free VRAM. At N=2636 and at N=2300 both arms hit that cut (2,999 slots at `0` both times, 2,760 at `2`), so the last row still compares two cache sizes. A smaller N, under both cuts, was not run. Whether the forced misses happened is not shown either: the main process printed no pipeline count line (`STRATA_DECODE_TIMING=1` was set), so the FORCE_MISS row shows only that the variable changed no answer. ### Results (engine 0.1.41, before the pipelined decode) PC A: RTX 3080 10 GB (PCIe 4.0 at x8), Ryzen 9 5900XT, 128 GB DDR4-3200, Linux. PC B: RTX 2080 Ti 11 GB, Ryzen 9 5900X, 64 GB DDR4-2400, Linux. PC C: RTX 3070 8 GB, Ryzen 7 5700X3D, 64 GB DDR4-3600, Windows 11. Links 1 GbE, and 10 GbE between A and B (~400 MB/s, slot-limited). `--kv int8 --kv-resident 32768 --max-context 131072 --spec 4`, greedy, one run per row. Prefill / decode tok/s; prompts of 7.5K / 30K / 57K / 91K tokens with 320-token answers. 0.1.42 turned `STRATA_ROUTE_TAIL_SKIP` on by default for CUDA serve. The two-PC rows ran again on this head (the first subsection, the cards swapped); the three-PC rows and the Windows clocks did not (Not run). | configuration | short decode | 8K | 32K | 100K | |---|---:|---:|---:|---:| | RVN IQ3_S, 3080 alone | 39.9 | 791 / 38.1 | 1,118 / 37.2 | 1,120 / 38.0 | | RVN IQ3_S, A + B (1 GbE), K=26, chunk 5888 | 53.5 | 655 / 48.1 | 1,231 / 49.7 | 1,521 / 45.6 | | RVN IQ3_S, A + B + C (A-B 10 GbE), 24 / 16 / 8, C clocks locked | 51.3 | 658 / 47.8 | 1,110 / 46.5 | 1,640 / 44.7 | | UD-Q4_K_XL, 3080 alone (the better of two runs: prefill with a RAM budget, decode without) | 27.3 | 302 / 25.4 | 324 / 24.5 | 326 / 23.7 | | UD-Q4_K_XL, A + B (10 GbE), K=26, chunk 5888 | 38.8 | 659 / 34.4 | 1,147 / 36.9 | 1,164 / 33.6 | | UD-Q4_K_XL, A + B + C, 24 / 16 / 8, C locked | 38.4 | 549 / 35.3 | 945 / 36.6 | 1,334 / 35.2 | Two PCs: decode +18-44% on IQ3_S, and on UD-Q4_K_XL (which one 10 GB card caches poorly) +42% and a 100K prompt in 88 s instead of 293. Long prompts need a large chunk (5888-8192). A third PC adds a hop to every window: it paid for 100K prompts and cost 1-8% of decode; the tuner's eight three-stage splits of UD-Q4_K_XL tied within the spread. **Windows lowers a worker GPU's clocks between decode windows**, while the other stages run. The RTX 3070 under Windows (or WSL2) waited 12-22 ms for its 8 layers per window, and 3.7-4.1 ms with `nvidia-smi -lgc 1500,1905 -lmc 7001,7001` (short decode 33.8 -> 41.8); the 2080 Ti under Linux held P2. The node agent can lock and reset the clocks around a worker (`"gpu_clocks"`, as administrator), and the tuner's report says when a Windows node has not. ### Pipelined decode on a remote main (`--pipeline-windows 2`, engine 0.1.43 and later) RTX 3080 main (layers 0-25), RTX 2080 Ti worker (26-47), 10 GbE, RVN IQ3_S, `--spec 4`, 40 varied prompts of 200 tokens, one binary per session, order off-on-on-off: | build | off | on | on | off | gain | |---|---|---|---|---|---| | this branch on 0.1.43.1 (2152 and 1951 cache slots) | 65.0 | 71.5 | 70.8 | 65.4 | +9% | | the same change on engine 0.1.43, another session | 62.8 | 70.4 | 70.7 | 62.7 | +12% | Both tables of this subsection ran again on this head with the cards swapped ("Pipelined decode" and "K on this pair" above). The overlap hides part of the main process's layers behind the round trip, so with it on it pays to move layers to the worker until the two are about even. Same PCs, fp32 rows, `--pipeline-windows 2`, this branch with #1887 and my bf16 branch on top; 12 of the 40 prompts x 200 tokens, and a ~30K prompt read from 0 then 200 tokens; medians of 3, one session: | K, layers on the main process | main process's part, ms a window | round trip, ms a window | decode, tok/s | 30K prompt, tok/s | decode after it, tok/s | |---|---|---|---|---|---| | 26 | 22.6 | 16.6 | 70.3 | 1,351 | 53.3 | | 24 | 19.3 | 19.1 | **73.4** | 1,218 | 58.8 | | 22 | 17.0 | 21.6 | 73.1 | 1,158 | 59.2 | | 20 | 15.3 | 24.1 | 71.4 | 1,130 | 55.9 | | 26 again, at the end | 22.8 | 16.6 | 70.9 | 1,369 | 54.3 | Prompts pull the other way: on two PCs the worker is the slowest stage per chunk (3.5-4.6 s against the main process's 2.2-2.9 s), so K=24 is +4-5% decode and -10% on long prompts against K=26. On three PCs (an RTX 3070 last stage over 1 GbE, clocks locked, bf16 rows) the overlap gave +15% decode at 26 / 14 / 8 (59.3 -> 68.3 tok/s), and [my comment on the bf16 rows](https://github.com/Niko1221/Strata/pull/1748#issuecomment-6155624491) has the three-PC splits. | choice | gains | costs | |---|---|---| | `--pipeline-windows 2` | +9-12% decode on two PCs, +15% on three | 444 MiB of the main process's expert cache (about 200 slots here); with the automatic cache the answers differ from a run without it (below) | | fewer layers on the main process | decode, until its part matches the round trip | prompt speed while a remote stage is the slowest per chunk (K=24: -10%) | | another PC | VRAM; long prompts once re-split (+12-16% at 30K here) | a hop and its layers on every round trip; decode ties two PCs only after re-splitting | | a Windows card's clocks left unlocked | nothing to set up | the RTX 3070's 8 layers took 11-13 ms a window, against 5.9 ms locked | **Answers** (run again on this head: "Answers" under the first subsection). The cache size is part of the result: a different slot count places other experts on the CPU, which moves near-tie tokens, so with the automatic cache `--pipeline-windows 2` compares two cache sizes, not two loops. Measured with one-token windows (`--spec 4 --mtp-max-t 1 --suffix-draft 0`), `STRATA_ROUTE_TAIL_SKIP=0`, greedy, two 4-turn conversations of 16K-token prompts, 8 answers per run, the same two PCs. With the change on engine 0.1.43: | what differs between the two runs | answers the same | |---|---| | `--pipeline-windows 0` vs `2`, automatic cache | 2 of 8 | | `0` at `--expert-cache 1951` vs `0` at 2153 | 2 of 8 (the same answers differ) | So the note "The cache size changes no output bit" in `generate.cpp` (the cache sizing comment) does not hold on this setup. This branch on 0.1.43.1 at `--expert-cache 1951`, each run the first replay on a freshly started server, against the branch's first `--pipeline-windows 0` server: | runs | servers with all 8 answers the same | |---|---| | `0`, the branch this one is built on | 2 of 2 | | `0`, three more servers | 2 of 3 (the third: 4 of 8) | | `2` | 4 of 4 | | `2`, every third or second guess made wrong (`STRATA_PIPELINE_FORCE_MISS=3` / `2`; 256-317 of about 545 windows undone per run) | 2 of 3 (the third: 6 of 8) | The runs that differ took another word partway into an answer, with `0` as well as with `2`. Later replays on one server drift with either setting; the cause is not known. ### Recovery (engine 0.1.43 and 0.1.43.1) Every row below ran again on this head; those results are in Validation, beside these. Two PCs fail in ways one PC does not (the worker ends, either PC restarts, the link drops), and each needed a person before. Fault injection on A + B (10 GbE, RVN IQ3_S, K=26), agent and server, none needing a hand. The first seven rows ran on 0.1.43 (371b400f), the last three on 0.1.43.1 with `STRATA_REMOTE_CONNECT_S=60`, against the build before them (0936f027), and again at 4bbcb16e and 5c454ed6: | Fault | That request | The next request | |---|---|---| | the worker killed (`kill -9`) while idle | waited for the agent's restart, answered after 45.6 s | - | | the worker killed in the middle of an answer | 503, `Retry-After: 30` (2.9 s) | answered after 50.2 s | | the same, streamed | an error event of the `server_error` kind | answered after 44.8 s | | the worker stopped and started through its agent | - | answered in 1.6 s | | the main engine killed while idle | restarted by the server, took the worker over: answered after 20.5 s | 1.2 s | | the main engine killed in the middle of an answer | the server's 503 for an engine that stopped | answered after 13.4 s | | the worker stopped while a request waited, started 70 s later | answered after 109.6 s, past the 90 s check | - | | the worker stopped; a streamed client leaves after 20 s, a second request at once | ended at the STOP, the engine kept (before: waited 60 s, then the engine ended) | 503 after 58.2 s (before: 37.9 s, for an engine that stopped) | | the worker started again | - | answered after 12.7-15.5 s | | the worker's port taken by a listener that never answers | 503 after 60.0 s (before: 310.5 s) | - | ### Images (`--vision`, engine 0.1.43) Run again on this head, on the swapped cards: "Images" under the first subsection. On A + B (RVN IQ3_S), fixed expert sets, the tail skip off, the first token's distribution against the same model on one card: | prompts | KL | |---|---| | text, with or without the table | 1.6e-4 | | six pictures, with the table, against without (`STRATA_STAGE_POSITIONS=0`) | geometric mean 43% lower (better on 3, the table picture 7.4e-4 against 1.7e-2; slightly worse on 3, not explained) | With the served flags the answers were right (shapes, a table's numbers, a chart, a screenshot, text after them). ### Byte for byte without a remote stage (earlier bases) On this head: the five greedy prompts on one 2080 Ti against `main` (Validation, the first row); the 16K-token replay was not run without a remote stage. | base | check | result | |---|---|---| | 0.1.41 | one card, five greedy prompts (one of 9,364 tokens): this branch twice, `main` once | identical | | 0.1.42 | fixed expert sets (the stock config does not repeat run to run), a 2 x 4-turn replay on a 16K-token prompt, `main`, this branch and #1887 twice each | the second round 8 of 8; `main`'s first run an outlier | | 0.1.43 | the same replay: branch, `main`, `main`, branch | all four pairs 8 of 8 | | 0.1.43.1, no `--pipeline-windows` | against the branch it is built on, two fresh servers each: the replay on the split and on one RTX 3080; five greedy prompts on the split | the same | ## Related discussion - This PR was open before the 0.2.0-beta reset (closed with every open PR on 2026-10-19); this is the same branch rebased onto `main` e88ee39d. No maintainer agreement on scope yet. - #1256 (a model split across machines) was closed as not planned, and #482 (a networked pool) was declined because it cannot be tested across PCs here. This is opt-in and self-contained, and it can be tested on one PC with two cards (Approach, "Trying it on one PC"). #1055 had the idea for decode only. If it is not wanted upstream, that is fine: I will keep maintaining it in my fork, and the Windows clock finding above may be useful on its own. - CC-David-CC checked it against the in-process split: #1773 (three Tesla P4s, 9 of 9 exact) and #1813's parity gate (24 requests, passed on the earlier head f2673bd2). - @YukihiroHemmi's report on untrusted peers (at 4bbcb16e) is fixed here (Approach, "Untrusted peers"). - #1887 (conversation checkpoints across the link) is stacked on this one. - #2689 and #2690 (Expert Deferral, `STRATA_VERIFY_DEFER_CPU`) came from this split's measurements but need no remote stage; they are their own PRs and are not part of this branch. ## Approach **The link.** The protocol (version 5) is a hello, then per-window and per-chunk messages: `StageClient` on the main process, `serve_stage` on a worker (a receiving thread, double buffers, the take-over, a relay's idle hook), `StageRelay` for a worker that forwards to the next. The hello checks the protocol, the geometry each PC read from its own GGUF, the model pack's fingerprint, the K/V type, the window and context sizes, the prompt chunk (a worker must be able to lend the main process's chunk whole) and `--vision`; the shared token is checked before anything after the hello is read. The `Verifier`, `Prefill` and arena get hooks: `set_no_head`, `set_remote` (`remote_run_`, `remote_commit_`), a pipelined chunk hand-off, and a layer range for the expert arena and `load_experts_gguf`, so each PC loads and caches its own layers only. **Pipelined decode** (`--pipeline-windows 2`, opt-in). Without it a decode window is the main process's own part (head, drafter, its layers) and then the round trip through the remote stages, one after the other. With it, #1656's two-stage loop runs on the main process: layers 0 to K-1 are the front stage, the worker followed by this PC's head the last one. While the worker and the head verify window N, layers 0 to K-1 already run window N+1 on the guess that N is accepted whole; a wrong guess is undone on this PC (GDN snapshot). The worker only ever gets verified windows, in the serial loop's order. Both stages share the main process's GPU, so the second verifier of each and the snapshots, 444 MiB at K=26, are kept out of its expert cache (the log says so). The automatic default still resolves to 0 on a remote main; `--adapt-async` turns it off (not measured there); a worker refuses it. **Recovery.** - the node agent starts an ended worker again (5 s, doubling to 300 s; its last log kept as `.prev.log`); - the main process connects again at its start and at a request's start, within `STRATA_REMOTE_CONNECT_S` (180 s) in all, the hello's reply included; a client that goes away ends the wait and the engine stays; a link lost in the middle of a request still ends the engine, and the server starts it again; `INFO remote_stage_wait=S` lines keep the server's 90 s frozen-engine check off and reach the client as keep-alives; - a new main process takes over a worker silent for `STRATA_REMOTE_TAKEOVER_S` (30 s); - a relay closes its main process's connection when its next worker is gone, seen while idle; - the stall watchdog (#29) watches each message a worker serves; - a worker that cannot lend the buffers for the main process's chunk lends for its own (#2090, #340); - the server answers a remote stage's error with 503 and `Retry-After: 30`, not 400. **Untrusted peers.** Any host reaching a worker's port could end it without a token: messages were parsed before the hello, and `T * handoff_floats` wrapped before T was bounded. Now a worker reads nothing but a hello first (10 s in all) and nothing more until its token is checked, and bounds T first; the main process caps an error reply at 64 KiB. `stage_link_test` sends these headers by hand; each of ten mutations that undo one fix failed a check when it was written (two of them only on Windows, where a socket's shutdown does not wake a recv). **Images.** A picture's tokens rotate by M-RoPE positions that are not their cell index. The protocol's `Positions` message (the main process sends the table before a request with a picture, the identity after it) and `vision` in the hello carry them; a relay forwards the table. **Following upstream.** Written on fb58e0d (0.1.41), now on `main` e88ee39d (0.2.0-beta, engine 0.1.45.3). What each release needed here: - **0.1.42:** workers take the main process's `STRATA_ROUTE_TAIL_SKIP` rank from the hello; the CPU prefill share's every-expert-cached check counts the process's own layers. - **0.1.43:** the tail-skip default counts only a process's own layers' experts; a remote main keeps the probed PCIe share under `STRATA_PCIE_AUTO_SPLIT=1`; `STRATA_ADAPT_OVERLAP` was left opt-in on a worker, not faster there (6 interleaved pairs: decode median 64.19 tok/s on, 64.33 off). - **0.1.43.1:** #2090 halves a chunk whose loan does not fit, but a worker reads the main process's chunk whole, so it lends for its own chunk or names the `--prefill` that fits; #2010 made the overlap opt-in everywhere; the 503's `Retry-After` goes through upstream's `_json`. - **0.1.44 to 0.2.0-beta** (this rebase; the last commit, "follow 0.1.44 to 0.2.0-beta on both PCs"): `--prefill-head-alias` is refused with a remote stage (a worker has no head); a Qwen3.6-35B-A3B file is refused with the remote stage's flags (its own engine path has no layer split and skips an unknown option in serve mode); a remote stage is refused on the Metal build (its window runs init, run and commit itself, past the hooks; the Metal build links the link's code from the first commit on); `--adapt-async 1` is turned off with a line on a worker and, in the expert arena's mode, on a remote main; the 8192 automatic chunk cap of a layer split on gfx12 applies to a remote main; pin by need (`STRATA_PIN_BY_NEED=1`) is off with a layer range (its padded stride does not fit a range's packed arena) and the log says so. A worker's arena counts its deferred registration slices (`STRATA_DEFERRED_REGISTER=1`) from its range's first layer. The moved `lend` and `refill` are upstream's current ones (`STRATA_REFILL_PARTS`, the planned segment's `exact` chunk, 0.2's `planned_chunk`), which a worker calls with `exact` 0; `Verifier::run` calls the remote hook before upstream's prelaunch check; `STRATA_HANDOFF_PIPE`'s pieces stay in-process only; the server's `Retry-After` uses `_json`'s `retry_after`. Read in the code without a change: 0.2's host-aware prompt plan and `STRATA_RAM_ADAPT2` act on the mapped file tier only, and the sm_86 / sm_60 defaults are each PC's own. The conflicts and how each side was kept are in ENGINEERING.md ("After the rebase onto 0.2.0-beta"). **What changed:** | file | change | |---|---| | `include/strata/net/stage_link.hpp`, `src/net/stage_link.cpp` (new) | the protocol (version 5), `StageClient`, `StageRelay`, `serve_stage`; a connect with a deadline and a stop flag; `alive`, `abort`; a hello first, sizes bounded before they are multiplied; POSIX and Winsock | | `src/net/stage_link_test.cpp` (new) | the link over loopback, crafted headers included | | `src/program/generate.cpp` | the stage flags and their checks; the layer range for the arena, weights, profile and session; the worker's serve loop and relay; the head-only stage; the hello; timing lines; the image position table; the watchdog over a worker's messages; the reconnect; `--pipeline-windows` on a remote main | | `include/strata/core/verify.hpp`, `src/core/verify.cpp` | `set_no_head`, `set_remote`; for `--pipeline-windows`, the round trip on a job thread, the head launched when the rows are back, `remote_settle` for a drain stopped at an error, the job joined when the engine ends | | `serve/server.py`, `serve/test_server.py` | a remote stage's ERR is a 503 with `Retry-After: 30`; the wait line is a keep-alive | | `include/strata/prefill/prefill.hpp`, `src/prefill/prefill.cpp` | the pipelined chunk hand-off | | `include/strata/core/expert_source.hpp`, `src/core/expert_source.cpp` | a layer range for the arena and `load_experts_gguf` | | `CMakeLists.txt`, `metal/CMakeLists.txt` | `stage_link.cpp`, `ws2_32` on Windows, `stage_link_test`; the Metal binary links `stage_link.cpp` | | `tools/stage_node.py`, `tools/stage_ship.py`, `tools/stage_tune.py`, `tools/test_stage_node.py` (new) | the agent, the splitter, the tuner, their tests | | `docs/REMOTE_STAGE.md`, `docs/remote-stage/ENGINEERING.md` (new), `docs/MULTI_GPU.md` | the docs | **What it leaves alone.** Without `--remote-stage` or `--stage-worker` no new code path runs: the new `Verifier`, `Prefill` and arena hooks are inert at their defaults (no range, no remote callbacks, `no_head` false). On a remote main without `--pipeline-windows` (or with 0), its windows go through the link on the request's thread and the cache keeps its size. With a remote stage these are refused at start: `--batch`, `--peer-device`, `--control-vector` (and the speed projection), `--expert-cache-remote`, `--prefill-head-alias`, `--pipeline-windows` on a worker, a Qwen3.6-35B-A3B file and the Metal build; the prompt cache, conversation parking, mid-prompt checkpoints, `--kv-grow`, pin by need, and `--adapt-async 1` on a worker and in the arena mode on the main PC are turned off with a log line. Not touched: setup, the SYCL port's copies, the HIP-specific code; in the server, only lines that only a remote stage prints. ### Trying it on one PC Two cards in one PC are enough. The worker runs on one card and the main process on the other, over 127.0.0.1; the reference is the in-process split of the same two cards, so their answers can be compared token for token. ``` # the worker: layers 26-47 on the second card CUDA_VISIBLE_DEVICES=1 strata --serve --stage-worker 7841 --stage-begin 26 --stage-bind 127.0.0.1 \ <the model's args, as in the main config> --prefill 5888 # the main process: layers 0-25 and the head on the first card; in the server config's "args": # "--layer-split", "26", "--split-device", "0", "--remote-stage", "127.0.0.1:7841" (and CUDA_VISIBLE_DEVICES=0) # the reference: the same config with "--layer-split", "26", "--split-device", "1" and no --remote-stage ``` Exact comparisons need the run-to-run noise off on both: the same `--expert-cache N` (with `auto` the slot count moves with the reserves and other flags, and an expert computed on the CPU instead of the GPU gives other numbers), fixed expert sets (`--pcie-frac 0 --adapt-every 0 --adapt-swaps 0`), `STRATA_ROUTE_TAIL_SKIP=0`, `STRATA_PREFILL_CPU_SHARE=0`, `STRATA_IQ_MT_MIN=1`, and one-token windows (`--mtp-max-t 1 --suffix-draft 0`). With MTP's longer windows one card does not repeat its own greedy answers (upstream `main` 7695859a, RTX 3080 alone, RVN IQ3_S, served decode flags, fixed expert sets, 40 prompts, two runs: 32 of 40 the same, 35 of 40 with `STRATA_IQ_MT_MIN=1`), so compare with one-token windows. ### Rebased onto 0.2.4.1 (2026-10-24) This head is the branch rebased onto `main` 8183c6b6 (v0.2.4.1 and one docs commit, engine 0.1.49.1). The rebase applied with no conflicts, and `git range-diff` against the 0.2.3 head (bb7984df) shows every commit as the same patch. 0.2.4's DeepSeek V4.1-Flash engine (`strata-dsv41`, `src/dsv41`) is a binary of its own and has no remote stage. Checked on this head (Linux, the build of the runs below): the build, `stage_link_test` and five CPU tests (`conv_cache_test`, `spec_prob_test`, `batch_rows_test`, `conversation_validation_test`, `conversation_transfer_test`) passed. **Not run on this head:** the Windows build and ctest. **GPU runs on this head (2026-10-24).** The same two PCs, model and runs as in the 0.2.3 section below: the main process on the RTX 2080 Ti, the worker on the RTX 3080, 10 GbE, Linux, K=26, `--max-context 131072`, greedy, this head's build on both. The CI container on the main PC's host used 0 cores during every run. In the 0.2.3 section below, "this head" means the 0.2.3 head (bb7984df); in the sections before Approach, it means the 0.2.0-beta head (a3e15682). | check | 0.2.4.1 (this head) | 0.2.3 (bb7984df) | |---|---|---| | one card, no remote flag, exact flags: five greedy prompts against `main` | byte-identical | byte-identical | | the split answers the five prompts | 5 of 5 | 5 of 5 | | low-context decode, 2080 Ti alone (median of 3) | 53.58 tok/s | 51.85 tok/s | | low-context decode, split, `--pipeline-windows 2` (median of 3) | 67.64 tok/s (+26.2%) | 66.73 tok/s (+28.7%) | | ~32K prompt, 2080 Ti alone: prefill / decode | 922 / 44.9 tok/s | 912 / 42.3 tok/s | | ~32K prompt, split, `--pipeline-windows 2`: prefill / decode | 1,363 / 61.9 tok/s | 1,331 / 59.6 tok/s | | images (`--vision`, split): six picture questions, then a text turn | 7 answers, no error | 7 answers, no error | The "2080 Ti alone" rows ran `main`'s build (the default path is byte-identical). The 0.2.3 split rows overlapped a build on the main PC's host (see the 0.2.3 section), so those are, if anything, low. Faults on this head, all as on 0.2.3 (`--serve`, the split, a 100-token request): | fault | the request in flight | the next request | |---|---|---| | F1: the worker killed 15 s into a request | HTTP 503, `Retry-After: 30`, "remote stage: the peer closed the connection" | answered after 45.2 s | | F2: the same, streaming | a `server_error` stream event, same message | answered after 51.3 s | | F3: the worker killed while idle | - | answered after 61.5 s | | F4: the node agent stopped and started | - | answered after 1.3 s; the main kept its engine | ### Rebased onto 0.2.3 (2026-10-23) This head is the branch rebased onto `main` 5c8dd322 (v0.2.3, engine 0.1.48). Git stopped at two conflicts, both in the first commit and both beside new upstream lines: the `strata` target in CMakeLists.txt (upstream's DFlash2 tool targets and `strata_utf8_manifest`, next to `src/net/stage_link.cpp` and `ws2_32`) and two adjacent member blocks in `prefill.hpp` (the DFlash2 taps, next to `remote_rows_from_`). No remote-stage code changed in the rebase. Two 0.2.x defaults could meet a remote stage, and neither does: - `--conversation-cache-mib` is sized from the free RAM under `--serve` when it is not given (#3493). A remote stage still sets it to 0 before that sizing, on the main process and on a worker, so parking stays off as before. - `--draft dflash2` is refused under `--serve`, and a remote stage needs `--serve`. The verifier's taps also need the whole model in one stage (`lb == 0`, `le == n_layers`). Checked on this head (Windows, MSVC 19.44 + CUDA 13.0, `-DSTRATA_BUILD_CONVERSATION_TESTS=ON`): | check | result | |---|---| | build (every target but `hc_persist_parity`) | passed | | `stage_link_test`, the 7 conversation tests | passed | | ctest overall | 81 of 86 passed | The other 5 fail the same way on v0.2.3 itself in the same environment: - `hc_persist_parity` and `hc_persist_default_off` are not run, because the test calls `setenv`, which MSVC does not have. - `gemm_bf16_parity` and `gr_upmix_parity` cannot find the CUDA DLLs on ctest's PATH. With the DLLs on the PATH, `gemm_bf16_parity` passes and `gr_upmix_parity` fails 21 cases, also on v0.2.3. - `ple_parity` needs a model file. **GPU runs on this head (2026-10-23).** The same two PCs as below: the main process on the RTX 2080 Ti, the worker on the RTX 3080, 10 GbE, Linux, this head's build on both. The IQ3_S of Qwen3.8-Flash-Next, K=26, `--max-context 131072`, greedy. In the older sections below, "this head" means the 0.2.0-beta head (a3e15682). | check | 0.2.3 (this head) | 0.2.0-beta (a3e15682) | |---|---|---| | one card, no remote flag, exact flags: five greedy prompts against `main` | byte-identical | byte-identical | | the split answers the five prompts | 5 of 5 | 5 of 5 | | low-context decode, 2080 Ti alone (median of 3) | 51.85 tok/s | 54.02 tok/s | | low-context decode, split, `--pipeline-windows 2` (median of 3) | 66.73 tok/s (+28.7%) | 68.04 tok/s (+26.0%) | | ~32K prompt, 2080 Ti alone: prefill / decode | 912 / 42.3 tok/s | 945 / 47.6 tok/s | | ~32K prompt, split, `--pipeline-windows 2`: prefill / decode | 1,331 / 59.6 tok/s | 1,394 / 57.8 tok/s | | images (`--vision`, split): six picture questions, then a text turn | 7 answers, no error | 7 answers, no error | The split's speed runs overlapped a build on the main PC's host (4.5-6.8 cores for three of the four minutes), so its numbers on this head are, if anything, low. Faults on this head, all as on 0.2.0-beta (`--serve`, the split, a 100-token request): | fault | the request in flight | the next request | |---|---|---| | F1: the worker killed 15 s into a request | HTTP 503, `Retry-After: 30`, "remote stage: the peer closed the connection" | answered after 45.4 s | | F2: the same, streaming | a `server_error` stream event, same message | answered after 49.9 s | | F3: the worker killed while idle | - | answered after 61.5 s | | F4: the node agent stopped and started | - | answered after 1.3 s; the main kept its engine | ## Validation Revision: this head, a3e15682 (19 commits on `main` e88ee39d) (the builds and tests below ran on it before a last wording fix in ENGINEERING.md; `git diff` outside `docs/` is empty). The upstream baseline for the Python suites is e88ee39d itself, run the same way in the same environment. **Passed:** - Windows 11, MSVC 2022 (19.44.35229) + CUDA 13.0.88, Ninja, Release, sm_86 (`-DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON`): `cmake --build build --target strata stage_link_test conv_cache_test draft_kv_plan_test split_ring_test message_boundary_test coupled_draft_test spec_prob_test bf16_bits_test batch_rows_test batch_groups_test conversation_cache_test conversation_validation_test`, rc 0, `strata.exe` linked. Besides C4996 (`getenv` deprecated, as in `main`'s own files), every MSVC warning is on a line from `main`. - The same build, the CPU tests with `CUDA_VISIBLE_DEVICES=-1`, each rc 0: `stage_link_test` (all passed), `conv_cache_test`, `draft_kv_plan_test`, `split_ring_test` (23 checks), `message_boundary_test` (21), `coupled_draft_test`, `spec_prob_test` (72 cases), `bf16_bits_test`, `batch_rows_test`, `batch_groups_test`, `conversation_cache_test` (4772 checks), `conversation_validation_test` (972 host-only checks). - Linux (Ubuntu 24.04 container), GCC 13.3 + CUDA 13.0.88, sm_75 + sm_86, Ninja, Release, from a clean build directory (`-DSTRATA_ENABLE_CUDA=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON`): `ninja strata stage_link_test`, rc 0; `stage_link_test` passes. - `g++ -std=c++20 -O2 -Wall -Wextra -c` of `src/net/stage_link.cpp` and `src/net/stage_link_test.cpp` (GCC 13.3): no warning. - `python -m unittest tools.test_stage_node` on Linux (Python 3.12.3): 48 tests OK; `python -m pytest tools/test_stage_node.py` on Windows (Python 3.10.8, pytest 9.0.2): 48 passed. - `python -m pytest serve` on Windows (Python 3.10.8): 867 passed, 17 skipped (`main` e88ee39d: 864 passed, 17 skipped; the three more are this branch's server tests). - `python -m pytest tools/test_setup_*.py` on Windows: 681 passed, 2 skipped, and the same 22 failures as `main` (below); this branch does not touch setup. - GPUs, this head's Linux build (the same binary on both PCs) against the baseline's: the main process on an RTX 2080 Ti 11 GB (PCIe 3.0 x16) + Ryzen 9 5900XT, the worker on an RTX 3080 10 GB + Ryzen 9 5900X, 10 GbE, Linux; an IQ3_S of Qwen3.8-Flash-Next (the worker with its layers' shipped bytes), K=26, `--prefill 5888`, `--max-context 131072` on both, the node agent (`tools/stage_node.py`) of this head on the worker: | check | how | result | |---|---|---| | default path, no remote flag | one 2080 Ti, five greedy prompts (default_path_check), fixed expert sets and one-token windows, this head against `main` e88ee39d | byte-identical (the five answers' md5 the same) | | answers on the split | the same five prompts, the same exact flags on both PCs, `--pipeline-windows 0` | all five answered, no error; they differ from one card of the same build (another expert placement: 1,837 cache slots on one card, 2,884 + 3,210 on the split), expected and not a check | | decode, low context | 12 prompts x 200 tokens, three rounds, the median of the rounds' means; the 2080 Ti alone (the baseline) against the split with `--pipeline-windows 2` | 54.02 against **68.04** tok/s (+26.0%), 0 errors in either | | a ~32K prompt read from 0, then 200 tokens | the same two | prefill 944.8 against 1,393.6 tok/s, decode 47.6 against 57.8 tok/s | | images | `--vision` on both PCs, the split, `--pipeline-windows 2`; four pictures, six questions, then a text question | 7 answers, none an error | Faults, on held splits (`--pipeline-windows 2`), the agent restarting the worker. The first four rows are one held split; the main engine's rows and the worker stopped while a request waits are a second, with `STRATA_REMOTE_CONNECT_S` unset (180 s); the last three a third, with `STRATA_REMOTE_CONNECT_S=60`, as earlier: | fault | that request | the next request | earlier (0.1.43 / 0.1.43.1) | |---|---|---|---| | the worker killed (`kill -9`) 15 s into an answer | 503, `Retry-After: 30`, "remote stage: the peer closed the connection" | answered after 45.1 s | 50.2 s | | the same, streamed | an error event of the `server_error` kind | answered after 51.0 s | 44.8 s | | the worker killed while idle | answered after 61.6 s (the agent's restart and load) | - | 45.6 s | | the worker stopped and started through its agent | - | answered after 1.3 s, the main engine kept | 1.6 s | | the main engine killed (`kill -9`) while idle | the server started it again: answered after 11.0 s | 1.1 s | 20.5 s, then 1.2 s | | the main engine killed 3 s into an answer | the server's 503 for an engine that stopped (4.5 s) | answered after 10.6 s | 13.4 s | | the worker stopped while a request waited, started 70 s later | answered after 107.5 s, the main engine kept | - | 109.6 s | | the worker stopped; a streamed client leaves after 20 s, a second request at once | ended with the client, the engine kept | 503 after 58.1 s, "cannot connect to ...: Connection refused" | 58.2 s | | the worker started again | - | answered after 11.1 and 11.4 s | 12.7-15.5 s | | the worker's port taken by a listener that never answers | 503 after 60.0 s, "receive failed: timed out (no reply to the hello)" | - | 60.0 s | **Failed:** - `python -m pytest tools/test_setup_*.py` on Windows (Python 3.10.8): 22 failures (`test_setup_download`'s parallel download, two of `test_setup_engine_hash`'s refusal tests, and 19 subtests of `test_setup_golden`). `main` e88ee39d fails the same 22 in the same environment, test for test; I have not looked into them, and none touches a file of this branch. **Not run:** - On GPUs on this head: a relay (three PCs) and the Windows worker, so the three-PC rows of the 0.1.41 table, the Windows clock finding and the three-PC splits stay as measured then: the third PC, the Windows one, did not answer on the day. The new refusals and the turned-off switches of 0.1.44 to 0.2 are read from the code, not run. - `--pipeline-windows 0` against 2 at one cache slot count (both arms' `--expert-cache` hit the free-VRAM cut; see "Answers" above), and a count of the windows the forced misses undid. - The HIP (ROCm) and SYCL builds on this head (the SYCL port keeps its own copies of the files this changes, and HIP builds the CUDA target's sources); the Metal build (no Mac). - MSVC `/W4` on the link's files on this head. - `--prefill-head-alias`, Qwen3.6-35B-A3B and gfx12 checks: no file or card for them here. ## Limits - Qwen3.8-Flash-Next only (48 layers); the hello checks the geometry. - AMD or Intel cards (HIP and SYCL built on earlier heads, not run); the SYCL port has no remote stage. - `--pipeline-windows 2`: byte for byte with windows of more than one token; how often a guess holds; a Windows main; a drain stopped at an error with a worker window in flight (found in review, not run). - Images through a relay worker or with other models; Windows as the main PC. - Other quantizations of the family (official IQ3_S, IQ3_XXS, IQ2_XS, UD-IQ4_XS). - Correctness against the in-process split with fixed caches; the 0.1.41 results are one run per configuration (decode moved by up to ~14% between two runs). - Recovery not covered: a network partition, a relay's next worker ending on GPUs (loopback only), a Windows PC on either side of a fault, a worker lending for its own chunk on GPUs, a reconnect in the middle of a request. A ring topology; a WAN. - Plain TCP, not encrypted: token ids and hidden states cross the network in clear. The shared token only keeps other LAN hosts from driving a worker; without it a host gets no further than a hello. A worker serves one main process at a time, so a host that keeps connecting can still hold its port. The docs say to use it on a trusted LAN or inside a tunnel. - The node agent's token lets a request start the engine with whitelisted flags and write files under its data directory: a credential, LAN only. - One feature in one PR; I can split it into the engine hooks, the network stage, the pipelined decode and the tools if that is easier to review. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:29:48 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3648
No description provided.