Skip to content

Latest commit

 

History

History
1968 lines (1697 loc) · 151 KB

tensor-parallel.md

File metadata and controls

1968 lines (1697 loc) · 151 KB

Tensor parallelism

Status (2026-12-02): inference is built — the split, capacity planning, the node service and command line, the distributed engine (see Built at the end for what exists, what deviates from this design and what was measured) and its use by amql-server, with the handshake's full identity check, weight patches sent to the nodes and decode steps captured between exchanges (see The server, the handshake, patches and captured segments). Training is built on the command line (train --tp/--tp-local): see Training, built and the reviewer's guide, tensor-parallel-training-review.md.

Section Status
The split done (ShardPlanner, ShardSlicer, WeightLoader.WithSlices)
Capacity done (ShardPlanner.Build, ShardPlan, --tp-plan); bytes counted as on the device
Nodes and transport done: node service and command line (TpNode, TpCluster, tp-worker, --tp, --tp-local) and the amql-server routes (TpClusterBackend)
Inference done; decode steps captured between exchanges
Training done on the command line (TrainCluster, ShardWorker, TrainableModel.Shard.cs, train --tp); see Training, built
Second round: the smaller points done; see Built: the smaller points
Second round: linear attention by key head done for inference; see Built: linear attention by head
Second round: side data, routed experts by expert done for inference; see Built: side data, experts by expert
Second round: the head and the embedding by vocabulary done for inference; see Built: the head and the embedding, by vocabulary
Second round: indexed attention by head done for inference, with block-sparse attention on the single device engine first; see Built: indexed attention by head
Second round: KV paging across nodes done: each node pages its own part; amql-server's KV on disk works for a distributed model; see Built: KV paging across nodes
Second round: speculative decoding across nodes done for inference; see Built: speculative decoding
Second round in training not done: training passes ShardDivisions.None and plans as in the first round
Operating a cluster (start order, recovery, manager, GUI) built; the GUI in AMQL Studio (amql-studio.md); see Built
Protocol AMQLTP04 (AMQLTP03's side data, experts slot, head's logits, page operations and asked acknowledgements; a refusal's code on the wire)

One model, run across several GPUs at once: in one machine (local) or in several (network), on identical or different hardware. Each node holds a share of every layer in proportion to the capacity it was given, and the nodes exchange activations through Amql.Cluster links (cluster.md). The same split serves inference and training.

The split

A layer's two large operators are sums over an inner dimension, so they divide exactly:

Operator Inner dimension A node's shard
Softmax attention KV-head groups (a KV head and the query heads that read it) rows of Q, K, V (and the output gate, head gate) for its heads; the columns of O for its query heads; the KV cache of its heads only
Dense FFN intermediate rows rows of up and gate; columns of down

Each node computes partial = O_shard · attend(QKV_shard · h) or partial = Down_shard · act(Up_shard · h). The sum of the partials over the nodes is the operator's output. Biases that are added once (O, down) belong to the coordinator's shard.

An operator that does not divide this way is placed whole on one node (a shard that is everything on one node and nothing on the others): gated delta-rule linear attention, short convolutions, routed experts, attention whose q/k norm spans all heads or which has an indexer. Dividing those (experts by expert, linear attention by head) is later work; placing them whole is already correct and still spreads the model, a layer's operator at a time.

Nothing in the kernels changes. A shard is an ordinary plan with fewer heads and a narrower FFN whose weights are slices of the stored tensors, so the inference engine and the training backends run it with the kernels they already have. No operator, path or option is named after a model family.

What stays on the coordinator: the embedding, every norm, the residual stream, the final norm and the head, sampling. The residual never leaves it; workers see an operator's (normed) input and return their partial output.

Plans that run by visit (depth loops) are refused in the first version, with the reason.

Capacity

Each node states a capacity in bytes: by default the free memory of its device when it starts, less a reserve; --capacity overrides it (that is the knob for a slower card: give it less). The planner:

  1. counts the bytes of every placeable piece: fixed pieces (embedding, head, norms: coordinator), whole operators, and the divisible operators per unit (per KV-head group including that group's KV cache at the planned context; per 32 FFN rows);
  2. gives each node a target of capacity / Σ capacity of the total, and fails with the numbers if the total exceeds the sum of capacities;
  3. places the fixed pieces, then whole operators largest first on the node furthest below its target, then fills the divisible operators so each node ends as near its target as the units allow (largest remainder; FFN rows in multiples of 32 so 4-bit block scales stay aligned; a node may hold none of an operator and is then not called for it).

The result is a ShardPlan: for each node, for each layer's mixer and FFN, its range (or all, or none). It is deterministic from the plan and the capacities, so every node can derive or check it, and it is printed (--tp-plan prints and exits).

Nodes and transport

Clustering is a runtime property, not a way of starting a process. Every inference host (amql-server) is an ordinary server that can be joined to a cluster for a task and released from it again, through its API, while it runs:

A cluster belongs to a model, not to a host. Each model a host can load has its own distribution: none (it loads on this host alone, as now), or a node set. Model X may be spread over nodes N[], model Y loaded locally, and model Z spread over a different set N1[], on the same host at the same time; a node may hold shards for several clusters, coordinate one model while being a member for another, and keep serving its own local models beside them. Nothing is exclusive except memory.

  • Set: PUT /v1/models/{model}/cluster on the host that will coordinate that model, with the other nodes' addresses, optional capacities (per node, for this model), the context to plan for and the shared key. DELETE /v1/models/{model}/cluster removes it (the model is local again); GET reports the node set, the shard plan and each node's state; GET /v1/cluster lists every cluster this host coordinates or is a member of. The distribution can also be given in the server's model configuration, which is the same setting made at start.
  • Load: the distribution takes effect when the model is loaded (on the request that needs it, or at once with "load": true). The coordinator connects to each node's cluster endpoint, they prove knowledge of the key to each other (a challenge and response over the link, HMAC-SHA256; the key itself is never sent), agree the container's identity and the shard plan, and load their shards. A model with no distribution loads exactly as before.
  • Use: requests for the model go to its coordinator's normal endpoints (chat, completions) and run across its nodes. Other models on every node are served as usual.
  • Release: unloading the model, deleting its distribution, or DELETE of that membership on a member node (the cluster then ends, since a model with a shard missing cannot run) frees that model's shards on every node; nothing else on those nodes is touched. A link that drops, or a coordinator that disappears, releases the members' shards for that model after a timeout, so a node is never left holding them.

amql-server already serves any number of models per process, each under its own id, but the set is fixed at start: every --model is loaded and warmed then, and there is no route that loads or unloads one. This design needs both at run time (POST /v1/models/{model}/load and /unload, and a model added with PUT /v1/models/{model} giving its container), for local models as much as for distributed ones; that is part of this work.

Capacity is per node per cluster: what a node offers model X is stated when X's distribution is set (default: its free device memory at load time, less a reserve), so shards of several models and the node's own models share the device by the amounts given. A join that does not fit is refused with the numbers; a node may unload idle local models to make the room it agreed to give, and reloads them on demand as it would after a start.

A node accepts a join only when a key has been set on it (--cluster-key, the environment, or PUT /v1/cluster/key from the local machine) and the caller proves the same key; nodes sharing a key are a group from which any model's node set can be drawn. A distribution may name its own key, so two groups can overlap on a node without trusting each other. The key authenticates membership; it does not encrypt the links, which belong on a trusted network.

The same node service runs outside the server for the command line: amql-cli tp-worker is a process that only waits to be joined (training uses it), and --tp host:port,... / --tp-local 1,2 on generate, bench and train form a cluster for the life of the command and release it at the end. Local tensor parallelism is nodes on the other GPUs of the same machine, started by the coordinator and reached over loopback; a second instance on the same GPU (--tp-local 0) is the test configuration when there is only one card. One GPU per process needs no multi-device change in the native engine, and a fault in one device's process does not take the others' state with it.

Every node loads its shard from its own copy of the container, reading only the byte ranges it holds (row slices are contiguous file ranges and go disk → GPU directly; a column slice's tensor is read whole to the device and its columns copied into place there). The handshake compares the containers' identity (hashes of index.json and the system graph) and the shard plan. Sending weights to a node that lacks the container is not done.

All communication is Amql.Cluster: control as small messages (SendAsync/ReceiveAsync), activations as notified writes between registered buffers (GPU memory where the link can reach it, otherwise the link stages). f32 on the wire.

Inference

Per layer the coordinator: norms the residual; sends the mixer input to each node that holds part of the mixer; computes its own partial while they compute theirs; adds the partials; applies the post norm and residual; the same again for the FFN. A decode step is two exchanges of one hidden row per layer; a prefill chunk two exchanges of rows × hidden.

Workers hold per-sequence state (their heads' KV cache, positions, any whole operator's recurrent state), so the coordinator mirrors sequence operations to them: new, release, reset, reserve, mark, rewind, window slide, advance. Operations with no mirror are refused under tensor parallelism in the first version, by name: saving and restoring marks (KV paging; since built, see KV paging across nodes), KV downloads, the drafter and MTP head (since run on the coordinator: Built: speculative decoding), calibration (Grams), residual taps.

The whole-step CUDA graph cannot span an exchange, so a distributed model's steps run uncaptured in the first version; the segments between exchanges are now captured (see Captured segments).

A model that is not distributed is untouched. It keeps the whole-step captured graph, the fused norms and the projections that write straight into the residual, exactly as today: the distributed path is chosen per engine when its model has a node set, and the local path's launches, captures and kernel arguments do not change. This is a requirement with a check, not an intention: decode tokens/s and the per-step profile of a local model are measured before and after the change (the 0.8B and the 4B, single sequence and a batch), and any difference beyond run-to-run noise is a defect to fix before the work is accepted.

Checks: logits equal to the single-engine run within summation-order tolerance for every split tested (2 and 3 nodes, uneven capacities, a node with no share of some operator, whole operators on a worker), greedy text equal on the test prompts, marks and rewinds under speculation, a batch of sequences.

Training

Workers run the same differentiable operators over their shard (TrainableModel on the sliced plan), with their own tape, gradients and AdamW moments, on either backend (so a CPU node can take a share).

  • Forward: the coordinator's tape has one operation per exchange. It sends the input, the worker runs its partial and keeps its tape, the coordinator adds the partials.
  • Backward: that operation's backward sends the output's gradient; the worker back-propagates its tape (its weight gradients accumulate locally) and returns the gradient on the input, which the coordinator adds. With recomputation the forward is replayed with recording on, as locally.
  • Step: the coordinator gathers each node's sum of squared gradients for the global-norm clip and the finite check, then every node applies AdamW with the same learning rate and clip scale. A non-finite step is dropped everywhere.
  • Pause, checkpoint, resume: at step boundaries only, as now; each node writes its shard's state on the coordinator's command and the run directory records the shard plan. A resume needs the same shard plan.
  • Export: the coordinator collects the trained shards' deltas and writes one ordinary patch.

Checks: gradients of every trained weight equal to single-node training within tolerance, a few optimiser steps giving the same loss curve, pause and resume across nodes, the exported patch served by a single engine.

Built (2026-12-02)

Code

Piece Where
Planner: ShardPlanner.Build(plan, capacities, options) → ShardPlan (Describe(), Fingerprint, ToJson/FromJson) src/Amql.Inference/Distributed/ShardPlan.cs, ShardPlanner.cs
A node's sliced plan and the tensor slices it stands for: ShardSlicer.Slice Parallel/ShardSlicer.cs
Slices served on every device read path: WeightLoader.WithSlices src/Amql.Inference/WeightLoader.Slices.cs, OperandStore.ReadStoredRangeToAsync
The distributed engine: a GpuEngine with a ShardRole src/Amql.Inference/GpuEngine.Shard.cs
Links at run time: operations, operator inputs, partials Parallel/TpLinks.cs, TpTransport.cs
The node service (TpNode) and the coordinator's handle (TpCluster) Parallel/TpNode.cs, TpCluster.cs
amql-cli tp-worker, --tp, --tp-local, --tp-key, --tp-capacity, --tp-context, --tp-plan src/Amql.Cli/Program.TensorParallel.cs
Tests tests/Amql.Tests/TensorParallelTests.cs
Checks on real models scripts/tp-local-path-check.sh (the local path before/after), scripts/tp-check.ps1 (clusters of local workers)

How a distributed engine is used. TpCluster.FormAsync(container, options, peers, key, plannedContext) returns a cluster whose Engine is an ordinary GpuEngine: NewSequence, Prefill, StepInPlace (batches of up to 8), Verify/Accept, Mark/Rewind, Reserve, Fork all work on it. A DecodeSession runs on it through DecodeSession.UseDeviceEngine(engine, owns: false) (TpCluster.OpenSession() does this); the server's scheduler can take it the same way. Disposing the cluster frees every node's shard.

Slicing. A node's shard is the model's own plan with its attention cut to its KV-head groups (NumQHeads, NumKvHeads, and the output-gate rows, which sit beside each head's query rows) and its dense FFNs cut to its rows; operators it does not hold are absent. The slices are ordinary operand reads through a sliced WeightLoader, so the engine's upload code is unchanged:

  • row slices (Q/K/V, gate, up, their biases) of stored BF16 and raw NVFP4/MXFP4 are one contiguous range of the file each (elements and block scales), read straight into the device allocation;
  • column slices (O, down) of a tensor whose segment reads directly are read whole straight into a device buffer and their columns copied into the allocation there (pitched copies; see Loose ends); otherwise, and into host memory, they are gathered a block of rows at a time on the host (64 MiB blocks) and written; a 4-bit column cut must fall on a block boundary (head widths and 32-row FFN units make it so) and is refused by name otherwise;
  • f32, FP8 or patched tensors take the managed path: rows read through the map, a patch's delta cut the same way (patches are sliced; the coordinator now sends the patch file to every node at the join, see Weight patches; before, --tp with --patch was refused because the nodes would each need the patch file);
  • quantising at load (AMQL_GPU_FORMAT over a BF16 container) is refused: a slice's NVFP4 scales would differ from the whole tensor's.

The engine. Layer() is not touched. Forward calls ShardLayer instead when the engine has a role; the coordinator there norms, Exchanges the operator (input to the holders, its own partial meanwhile, the partials added), and joins the residual with the same post-norm and residual kernels as Layer. MixerPartial and FfnPartial are the mixer's and FFN's kernels with the same arguments as Layer but no fused norm and no residual epilogue. A worker holding routed experts whole receives the residual and returns the FFN's normed branch (RoutedFfn(partial: true)). Workers mirror every sequence operation (TpCall): new, release, reset, reserve, plan, exact rows, mark, rewind, accept, fork, prefill, step, verify and the prefill precision; each runs the same bookkeeping on its own engine (KV growth, window slides, positions, snapshots), so none of it is sent.

The wire. Setting up uses two-sided messages; running uses notified writes between registered pinned buffers: an operation (worker acknowledges unless it is a pass it takes part in), then per held operator the input rows (f32) and the partial back. An idle coordinator pings every 10 s; a worker leaves a membership whose link drops or whose coordinator is silent for 60 s. Any failure in a pass marks the cluster failed (a worker left mid-pass cannot be put back in step).

Deviations from the design

  • Biases added once belong to the node holding the operator's first unit, not the coordinator: a coordinator holding none of an operator would otherwise need a broadcast add of its own.
  • The namespace Amql.Inference.Distributed hides System.Threading.Tasks.Parallel inside Amql.Inference, so eleven files there now write System.Threading.Tasks.Parallel.For in full.
  • A worker holding a whole routed FFN gets the residual, not a normed input: the router reads the residual and the FFN's own norms run on the holder. Only the joined branch comes back.
  • Uneven bytes per unit: a whole attention (q/k norm over every head, sinks, a relative bias, an indexer, any conditioning) is planned as one unit of its weights plus its whole KV cache.
  • Not in this version: capturing graphs between exchanges (done since, see below); mirroring SaveMark/RestoreMark (refused; done since, each node paging its own part); a coordinator-side --patch (done since). The node's container is found by its path, then by folder name under --containers (TpNodeOptions.ContainerRoots).

Measured

The local path before (the design's base commit) and after, scripts/tp-local-path-check.sh, RTX 5090, 2026-12-02 (bench: 64-token prompt, 256 greedy steps, best of 5; batch: 256 steps; checksum: the bit patterns of the prefill and last-step logits):

Before was run twice (before and after the after-run), to show the noise:

Model before before, again after
qwen3.5-0.8b checksum 61903d9638b2ebf0 61903d9638b2ebf0 61903d9638b2ebf0
decode, tok/s (5 runs) 651.7-669.8 655.8-676.5 650.1-669.5
batch 1/2/4/8, tok/s 690 / 1282 / 1891 / 1737 690 / 1283 / 1893 / 1760 685 / 1278 / 1880 / 1753
profiled step (--profile) 2.83 ms 2.84 ms 2.76 ms, the same calls
qwen3.5-4b checksum 0ba346f870114499 0ba346f870114499 0ba346f870114499
decode, tok/s (5 runs) 169.4-170.5 170.3-171.2 170.2-170.9
batch 1/2/4/8, tok/s 172.3 / 322.8 / 578.6 / 690.0 172.9 / 323.4 / 581.7 / 693.1 173.0 / 323.7 / 580.6 / 692.9
profiled step (--profile) 6.68 ms 6.63 ms 6.63 ms, the same 17 calls

The final build (with the transport tuning) gave the same four checksums again (4B decode 170.0-171.2 tok/s, profiled step 6.68 ms). Before and after interleaved on the 0.8B batch bench, two rounds: before 676-686 / 1250-1277 / 1884-1891 / 1737-1746 tok/s for batches of 1 / 2 / 4 / 8, after 682-688 / 1265-1275 / 1880-1882 / 1746-1755.

Clusters on the one GPU (RTX 5090), workers started with --tp-local and reached over Windows loopback TCP (8 stripes), scripts/tp-check.ps1, 2026-12-02. Greedy is the chat prompt "Explain in two sentences why the sky is blue.", 60 greedy tokens on the single engine and on the cluster; top logit is the largest difference of the chosen token's logit over them. With the defaults (BF16-rounded prompt GEMMs, FP16 KV) a different split rounds differently; with AMQL_GPU_PREFILL=f32 AMQL_KV_FORMAT=f32 the logits agree to the printed 1e-4.

Model Nodes (--tp-local, --tp-capacity) Greedy, defaults Top logit, defaults Exact prefill, f32 KV bench pp64 / tg128, tok/s Exchange, µs (decode)
qwen3.5-0.8b (single engine: 14,000 / 660) 2 (0) 60/60 0.026 1,003 / 49.9 315
3 (0,0) 60/60 0.020 732 / 43.9 402
3 (0,0, -,2,1: workers 0.10 and 0.05 GB) 60/60 0.031 1,527 / 76.2 430
qwen3.5-4b (single engine: 6,200 / 170) 2 60/60 0.020 617 / 34.5 375
3 60/60 0.013 425 / 28.8 482
3 uneven (-,2,1) 60/60 0.061 60/60, 1e-4 728 / 46.6 482
gemma-4-26b-a4b-nvfp4-gptq (routed experts whole, NVFP4 slices) 2 60/60 0.43 30/30, 0 474 / 41.0 423
3 57/60 0.43 60/60, 1e-4 352 / 33.1 505

Which setting the 4-bit model needs (2026-12-02, the same method: tp-check.ps1 -NoBench, the single engine and the cluster under the same environment, gemma-4-26b-a4b-nvfp4-gptq; "defaults" here is before the default below existed):

Setting 2 nodes (0) 3 nodes (0,0)
defaults (BF16-rounded prompt GEMMs, FP16 KV) 60/60, top logit 0.433 57/60, 0.428
exact prefill alone (AMQL_GPU_PREFILL=f32, FP16 KV) 60/60, 0.0012 60/60, 0.005
f32 KV alone (AMQL_KV_FORMAT=f32) 60/60, 0.153 57/60, 0.363
both 60/60, 0.0001 60/60, 0.0001

The divergence comes from the prompt's rounding, not the cache's, so exact prefill alone is the smallest setting that gives 60/60, and FP16 KV (half f32's cache) is kept. A distributed model with 4-bit weights now defaults to exact prefill on every node (the coordinator sets it and the setting is mirrored, as any change of it is), unless AMQL_GPU_PREFILL is set; the plan says so (ShardPlan.Defaults: a default: line in Describe, --tp-plan and the server's cluster GET, defaults in its JSON; tp: default: … on the command line), and a session over the cluster's engine starts with it. Exact prefill costs prompt speed (FP32 SGEMM instead of BF16 tensor cores); it was not benchmarked here.

With the default and no environment set, the clusters give the exact-prefill single engine's text: 60/60 on 2 and on 3 nodes (top logit 0.0012 and 0.005, as above). Note what that is compared with: a single engine at its default (BF16 prompt GEMMs) gives other text from token 57 on, so against it both clusters now read 57/60 (top logit 0.338), where the 2-node cluster read 60/60 before. The default makes a cluster agree with one engine at exact prefill, whatever the split, not with one engine at BF16.

Batches work as on one engine; the 4B over two nodes: 31.9 / 61.2 / 109.5 / 174.3 tok/s for 1 / 2 / 4 / 8 sequences (one engine: 172 / 323 / 579 / 690).

Where an exchange's time goes (AMQL_TP_TIMING=1, the 0.8B over two nodes, a decode step's 1-row exchange): the coordinator waits ~110 µs for its own queued kernels before the input can leave (the sync before the copy out), then ~260 µs for the partial, of which the worker spends ~170 µs launching and running its uncaptured kernels and ~45 µs each way is the link. A 512-row prompt exchange (2 MB each way): ~2 ms on the wire each way, ~3.6 ms of compute.

So a distributed decode step on one machine is bound by launches and round trips, not by the wire: the next steps are capturing each node's operators between exchanges as graphs (the design's known next optimisation; it would take most of the ~170 µs and ~110 µs above) and a lower-latency link (RDMA, or TCP writes posted on the caller's thread, see cluster.md). A 4-to-26B model gains nothing from splitting over one GPU, which is what these runs are for: the same code spreads a model that does not fit one card over several.

Tests on the GPU (TensorParallelGpuTests, in-process nodes over loopback): qwen3 over 2, 3 (one node with no attention heads) and uneven nodes, qwen3_5-gdn (linear attention whole on a worker, the output gate cut per head), llama-bias (biases added once), gemma4-moe (routed experts beside a dense FFN, whole), qwen3 at NVFP4; for each, prompts of 5 and 700 tokens (two chunks), 4 greedy steps, mark and rewind, a 3-row verify and accepting 2, a batch of 3, a DecodeSession over the cluster, refusals; all within 2e-3 of the single engine at exact prefill and f32 KV.

The same GPU test set run together (GpuEngineTests after KvPagingTests/KvFormatTests in one process) fails 43 tests with a sticky illegal address in ministral on the design's base commit as well as here; each class passes alone. That is an existing isolation problem between those tests, not this work.

The server, the handshake, patches and captured segments (2026-12-02)

amql-server

TpClusterBackend (src/Amql.Server/TpClusterBackend.cs) is the server's cluster engine (server.md); ClusterBackends.Create picks it on a host with a CUDA device.

  • Node: --cluster-listen starts a TpNode whose keys are the server's key ring, read at every join (TpNodeOptions.Keys): a key set or cleared at run time counts for the next join, and a node may hold several named keys. The node proves itself under each key it holds (one HMAC each) and the coordinator needs one to be its own; the coordinator's proof then names the key, which the membership reports. Before a shard loads, the node makes room (TpNodeOptions.MakeRoom): idle local models are unloaded, least recently used first, until the device has the shard's bytes and a 512 MiB margin, or the join is refused with the numbers ("this node has 3.10 GiB free on its device and the shard needs 5.20 GiB, after unloading a, b").
  • Coordinator: a model's distribution forms a TpCluster with the model's context extension and the host's device gate; the model's DecodeSession runs on the cluster's engine (UseDeviceEngine(owns: false)) and its generator, adapters and batch scheduler are built over it as for a local model. GET …/cluster gives the plan (ShardPlan.ToJson, Describe) and each node's state (ready, lost when its link dropped, failed) and bytes.
  • Ending: TpCluster.Ended is raised once when a pass fails on a node or a node's link drops; the coordinator's links check every second, so a node that goes while the model is idle ends the cluster within a second rather than at the next ping. A member's DELETE ends its link, so its coordinator sees the same. TpNode.MembershipEnded reports a membership's end on the node.
  • Freeing: releasing a sequence on an ended cluster frees it here and no longer throws, and ModelHost.Dispose frees every part even when one fails, so an unload after a node has gone frees the container and the engine.

The device gate

TpDeviceGate wraps the server's device lock and records which thread took it. The scheduler takes it through ModelHost.DeviceTurns; TpCoordinatorLinks lets it go around every wait (a worker's acknowledgement, an operator's partial, the links' own lock while the heartbeat holds it) when the waiting thread holds it; a worker's Run takes it around each operation's device work and lets it go while it waits for an operator's input. After a wait the engine sets its own launch setting again (the native library's PDL switch is process-wide, and another engine may have run meanwhile). The CLI passes no gate and nothing changes there.

What a join checks

The join carries, beyond the container identity and the plan's fingerprint, what changes the computation without changing the plan's geometry (TpComputation):

What How A difference
the build the assembly's informational version (it carries the commit), also in the query refused: "this node runs AMQL X and the coordinator Y: every node of a cluster must run the same build"
positions and rotary settings, the context the system graph as it opened, after the context extension, hashed; the extension itself is sent and every node opens the container with it (ContextExtension.AsTrained when there is none, whatever the node's --max-context) refused: the graph differs
KV format, planned context, sequences in the plan (as before) refused: another plan
prefill precision mirrored with every change (ExactPrefill), as before —
settings that change a node's sums AMQE_GEMM_FROM (--batch-bf16), AMQE_ATTN_ROWS, AMQE_SIDE, AMQL_ATTENTION_SCRATCH_MB, AMQL_RESIDENT_BF16, AMQL_GPU_FORMAT, AMQL_GPU_FORMAT_HEAD refused, naming each with both values
the weights the container's identity; a patch's SHA-256 and length refused: "the weight patch arrived damaged"

The protocol's magic was then AMQLTP02 (the second round's is AMQLTP03), so a node of the first version refuses the hello ("not a tensor-parallel hello of this protocol").

Bytes on the device. The planner counted the stored bytes; it now counts what the engine uploads (TpCluster.DeviceBytes): raw 4-bit tensors as stored with their block scales, BF16 as stored, and every other form as f32 (FP8 projections are widened: 4 bytes an element, not 1), a patched tensor as f32 too. StoredBytes stays for what the file holds.

Weight patches

TpClusterOptions.PatchPath (and --patch with --tp on generate): the coordinator reads the patch file, runs its own shard under it, and sends it to every node right after the join, in setting-up messages of up to 1 MiB (TpMessage.PatchChunk); the node reads it whole, checks its SHA-256, loads it and slices it with its shard (WeightLoader(store, patch).WithSlices, as patched tensors already were). amql-server has no weight patches: a model's adapters are Entail programs that run on the coordinator over tokens and logits, so a distributed model runs them as a local one does.

Captured segments

A decode step (StepInPlace, on the coordinator and on each worker) is cut at its host work: the sync and send of an operator's input, the wait for each partial, a worker's wait for its input and its reply. The launches between two such points are a segment, captured with amqe_pass_begin/end the first time a batch steps (StepSegments records passes and host actions in order) and replayed with amqe_pass_run after, the host actions run between them. They are stale when the local step graph would be (_graphReady false: a cache grown, a rope chosen, row-invariance or the kept hidden state changed, another batch), and the shard paths now report KV growth there. Prefills and verifies run uncaptured, as before. AMQL_TP_GRAPHS=0 turns it off. No native change.

Measured on the one RTX 5090 (bench --prompt-tokens 64 --steps 128 --repeat 3, best of 3, each configuration twice, interleaved):

Off (AMQL_TP_GRAPHS=0) On
qwen3.5-0.8b, 2 processes (--tp-local 0) 48.8 / 49.2 tok/s, 324 / 321 µs an exchange 51.8 / 52.2 tok/s, 315 / 304 µs
qwen3.5-4b, 2 processes 32.3 / 32.3 tok/s, 421 / 420 µs 33.8 / 35.3 tok/s, 421 / 397 µs
qwen3.5-0.8b, 2 nodes in one process (a test harness, one CUDA context) 72.6-81.6 tok/s, 174-202 µs 72.5-86.1 tok/s, 165-202 µs
qwen3.5-4b, 2 nodes in one process 50.2-52.3 tok/s, 230-243 µs 50.2-55.8 tok/s, 213-239 µs

It pays, but little: 3-9%, not the ~280 µs of launches the first version's timing suggested. With AMQL_TP_TIMING=1 and the segments on, the worker's FFN exchange is ~155 µs waiting for its input, ~151 µs from its segment's launch to the end of its sync, ~105 µs for the reply's write; the coordinator ~103 µs to stage its input and ~265 µs waiting. A few kernels of a shard take a few microseconds on the device; most of the time is two processes taking turns on one GPU (a context switch each way) and the loopback link, which no capture removes. In one process (one context) an exchange is ~180 µs either way. It stays on: it is safe under the tests (every GPU test steps batches, marks, rewinds and verifies through it) and it is a gain; a link with lower latency or a GPU per node is where the rest is.

The local path, again

scripts/tp-local-path-check.sh, the base commit (2ee3fab) built from its own tree, then this build, then the base again: the same four checksums (61903d9638b2ebf0, 0ba346f870114499 decode; ce620150700a31e1, 70918af478f94c89 profiled). Decode tok/s, 5 runs: 0.8B before 648-662, after 638-653, before again 649-668; 4B before 168-170, before again 165-170, after 134-168 in the scripted run (disturbed: two runs at 134 and 138), re-run twice 169.8-171.0 and 163-170. Batches of 1/2/4/8: 0.8B 684/1273/1886/1727 before, 686/1265/1879/1753 after, 679/1263/1832/1704 before again; 4B 173.0/320.4/573.5/689.4, 173.4/322.4/574.0/692.3, 173.1/322.4/577.7/688.5. The local path's code is unchanged but for one line freeing a distributed engine's passes at dispose.

End to end through amql-server (RTX 5090, 2026-12-02)

Server A (--model small=qwen3.5-0.8b --cluster-listen 127.0.0.1:7101) and server B (no model, --cluster-listen 127.0.0.1:7201) as two processes on the one GPU, key from AMQL_CLUSTER_KEY, --kv-format f32; PUT /v1/models/dist with qwen3.5-4b and "cluster": {"nodes": ["127.0.0.1:7201"], "context": 8192} on A:

  • formed in 6.3 s: node 0 4.36 GB, node 1 4.64 GB (linear attention whole on one node or the other, attention and FFNs split); GET /v1/models/dist reports speculation: false, kv_disk: false, images: false and the list; B's GET /v1/cluster the membership (model, key default, bytes).
  • 60 greedy tokens of "Explain in two sentences why the sky is blue." through the cluster, with a request to the local 0.8B at the same time: the same text, byte for byte, as A gave after the distribution was removed and the 4B ran on A alone, and again after the cluster was formed anew.
  • DELETE /v1/models/dist/cluster: GPU memory 15,856 → 7,002 MiB (both shards freed; B's membership gone); four unload/load cycles after: 7,002-7,004 MiB unloaded, 16,016 MiB loaded, every time. (Windows reports no per-process figure, so this is the card's total.)
  • a key B does not hold: 503 "node 1 (127.0.0.1:7201) did not prove the cluster key (it holds another key)"; B's key cleared at run time: 503 "… refused: this node has no cluster key set and refuses every join"; set again with PUT /v1/cluster/key: the next load formed.
  • B killed 5 s into a 1,500-token reply: the request failed with the link's error, the model went failed with "cluster ended: …"; the next request failed 503 (B cannot be reached); with B started again the next request formed the cluster and was answered; the local model served throughout.

Checks

  • TensorParallelTests (CPU): several named keys and keys changed at run time; a node of another build refuses with both versions; differing settings are named; the planner counts device bytes (an FP8 tensor 4 bytes an element, a patch widening BF16).
  • TensorParallelGpuTests: a patch and a context extension (linear, 4x) reach every node: the cluster's logits equal a single engine's under the same patch and extension, and differ from the unpatched.
  • ServerClusterTests (GPU, in-process servers): two servers each coordinating a model the other holds a shard of, with a local model beside, 36 greedy requests at once, every reply equal to a local server's (deadlocks with the gate's release removed); no key, a wrong key and a named key; a member leaving marks the model failed with the reason and the next request forms it again; removing the distribution frees the member's shard and the model serves alone; making room unloads idle models in turn or refuses with the numbers.

Training, built (2026-12-02)

amql-cli train <container> … --tp host:port[,…] | --tp-local d|cpu[,…] [--tp-key K] [--tp-capacity GB[,…]] [--tp-plan] trains across tp-worker processes (a worker trains on --train-device auto|cpu|cuda); train check … --tp-local … compares the gradients across the nodes with one node's and prints which operators divide. The invariants, the wire, the order of a step, the tests and their tolerances, and what is not verified are in tensor-parallel-training-review.md. In short:

  • the coordinator's tape has one operation per exchange (TrainCluster.Pending); each worker keeps a tape per recorded operator until its backward; recomputation, accumulation, --freeze and --train-only (applied by every node from the same patterns), and evaluation work as on one node;
  • the capacity plan is ShardPlanner with training costs (16 bytes an element trained, 4 frozen; no KV); activations are not planned;
  • a step sums each node's Σg² for the clip and the finite check, and every node applies the coordinator's clip scale, learning rate and bias corrections; a non-finite step is dropped on every node;
  • checkpoints are the single-node files (every weight and moment whole, assembled by the coordinator) plus shard-plan.json; a resume is planned on the checkpoint's capacities (unless --tp-capacity is given) and needs the same number of nodes, each able to hold its share;
  • the export is one ordinary patch;
  • a training join gets the same checks as an inference join (the build, the container's identity, its system graph, the arithmetic settings); it carries no weight patch, and train --patch with --tp is refused by name; requests and answers carry a sequence number and the answer the kind of its request, and any failure between them fails the run.

Deviations from the design above: every layer norm stays on the coordinator, including a routed FFN's on a worker (inference sends such a worker the residual; training sends it the normed input, and the residual too when the experts sit beside a dense FFN), so no layer norm is held by two nodes; per-head q/k norm weights of a divided attention are replicated (each holder has them whole; their gradients are summed into the lowest holder before the clip and its value and moments copied to the others after the step), which the design did not mention; each node's state crosses the wire to the coordinator for a checkpoint rather than being written by each node, so the checkpoint is one atomic directory in the single-node format and works without a shared file system.

Second round (design, 2026-12-02)

A review of the first version found that whole operators are the ceiling for the models this is meant for (linear attention, indexed attention and routed experts in most layers: little divides, and one layer's expert stack can exceed a node), that KV paging and speculative decoding are refused, that the head and embedding are fixed on the coordinator, and four smaller points. This section is the design for all of it. Nothing here names a model family.

One rule: the coordinator decides, the holders compute

A routed FFN and an indexed attention are sums over an inner dimension once a selection is fixed (which experts with what weights; which blocks of the past each query reads). The selection is computed once, on the coordinator, by the kernels that compute it today, and travels with the operator's input as side data of the exchange. Every holder computes its part under that selection, so no two nodes can choose differently (different cards, different builds of the arithmetic), and there is no extra round trip.

An exchange therefore carries: the input rows (f32), and optionally side data (a typed block of int32/f32 whose size is fixed by the operator and the row count). The partial comes back as now.

Routed experts, by expert

  • Units: experts. A node holds experts [e0, e0 + n): for packed stacks, the matching row ranges of the gate/up and down tensors (and their 4-bit scales and companions); for stacks stored one tensor per expert, those tensors whole. A cut that a stored format cannot take (a block boundary) makes the planner place the stack whole, with the reason printed; it never fails at load.
  • Coordinator: holds the router, its scale, the expert scale and selection bias, and every norm of the layer (as training already does; inference no longer sends the residual to a worker and lets it norm). It runs the routing kernel as now and sends each holder the experts' input and the selection: per row, TopK expert indices and their final weights (every policy's normalisation and scale applied).
  • Holder: runs the expert kernel over its own stack with the selection restricted to its range (indices re-based, pairs outside its range skipped, not computed at weight zero) and returns Σ weight · expert(x) over its pairs, before the routed-out norm. Rows that select none of its experts give zero.
  • Join: the coordinator adds the partials, then the routed-out norm, the dense branch and the post norm as on one engine.
  • A dense FFN beside the experts, a shared expert: the dense FFN is its own divisible operator (rows, as any dense FFN) with its own exchange; a shared expert and its gate are one whole piece placed with the experts' first unit.
  • A layer has up to three operators in the plan: mixer, dense FFN, experts.
  • A holder none of whose experts were selected in a pass may be skipped for it; do this only if it is measured to pay and stays exact (a captured step's segments assume the same holders each step).

Linear attention, by head

Every head's recurrence is independent and the output projection sums over heads.

  • Units: key heads, each with its value heads (NumVHeads / NumKHeads).
  • A node's shard: its heads' rows of the q, k and v blocks of the input projection (three row ranges of one tensor), of the z, a and b projections, its channels of the depthwise conv, its entries of the per-head vectors, the columns of the output projection for its value heads; the per-head-dim norm weight whole on every holder. Its state: its heads' recurrent state and its channels' conv history only.
  • TensorSlice becomes a list of ranges along one axis (one range is the present case); a row slice of several ranges is that many direct reads into one device allocation.
  • The kernels are unchanged: a shard is the operator with fewer heads.

Indexed attention, by head

The indexer (its projection, norms and pooled keys) stays whole on the coordinator, which runs it and sends the selected blocks as side data; holders run their heads' attention over those blocks and keep only their heads' KV. This needs the attention kernel to take a selection it did not compute; if selection and attention are one kernel today, the selection is split out without changing the single-engine path's launches (the local-path check below applies).

Attention that is whole for other reasons (a norm over every head, sinks, a relative bias, conditioning) stays whole.

The head and the embedding, by vocabulary

  • Head: a divisible operator, units of 1,024 vocabulary rows (stored rows; a padded table's unused rows are not scored). The coordinator sends the final-normed rows that need logits (one a step; a verify's rows; a prefill's last) and each holder returns its logits (f32), which the coordinator places at its offset. Softcapping and the multiplier are applied once, on the coordinator, to the assembled row. Samplers, adapters and constraints see the same full row as now.
  • Tied tables: the head's row slices serve both uses.
  • Embedding lookups: a few rows a step. When the coordinator holds the table whole they run on the device as now. Otherwise the coordinator reads the rows on the host through the page-cached map (the path lean mode uses), provided that is shown bit-equal to the device kernel for every stored format; a format where it is not takes an exchange with the row's holder instead.
  • Planner: the fixed pieces become the norms, the router-side tensors and indexers, and an untied embedding only when the coordinator's share has room for it (otherwise host rows, zero device bytes). "The fixed pieces exceed node 0" can then only happen for a few megabytes.

KV paging across nodes

Saving a mark writes each node's own KV (and recurrent state) to that node's own disk, under an id the coordinator chooses; the coordinator's record lists the nodes, the plan's fingerprint and each node's byte count. Restoring asks every node for that id and fails by name on the node that lacks it (or whose plan differs) before any node has changed state. Dropping a mark drops it everywhere; a membership's end removes its files. The server's KV-on-disk feature then reports available for a distributed model. Built: see Built: KV paging across nodes.

Speculative decoding across nodes

Verify and accept already span the nodes. A drafter is its own small model on the coordinator and needs only the refusal lifted and the rewinds mirrored. An extra prediction head that reads the model's last hidden state is a fixed piece on the coordinator; where it uses the shared embedding or head it goes through the vocabulary exchange. Every node keeps the state a rewind needs.

Smaller points

  • Sliced patches: ApplySlicedPatch applies a delta by rows (span operations), not element by element.
  • Partials: each node's partial is staged to the device as it arrives; the sum is still taken in node order, so results do not depend on arrival order.
  • Captured segments and receive buffers: a captured segment holds the addresses of the receive buffers. They are allocated once at the join; this is now stated at the allocation and checked (segments record the buffers they captured and are discarded if one differs).
  • Quantised models: which of exact prefill and f32 KV removes the 3-node divergence is measured; a distributed model with 4-bit weights then defaults to that setting unless the user set one, and the plan says so.

Rules for this round

  • The local path is still untouched: scripts/tp-local-path-check.sh before and after, same checksums and speed.
  • Every division is checked against the single engine at exact prefill and f32 KV (2 and 3 nodes, uneven capacities, a node with no share), plus mark/rewind, verify/accept and a batch.
  • Training plans do not change in this round: ShardOptions says which divisions are allowed and training allows none of the new ones, so its assignments, tests and checkpoints are as reviewed. Dividing experts, linear attention and the vocabulary in training is separate work, done under the training review rules after the inference side is accepted.
  • The protocol's magic becomes AMQLTP03.

Built: the smaller points (2026-12-02)

Sliced patches add by row spans (a test keeps the old element loop and compares bit patterns). Partials of an operator with two or more worker holders are staged as they come (ReceiveAny) and added in node order; the copies are launched by the host action, so captured segments hold the same launches whatever the order (a GPU test: arrival in node order and in reverse give bit-identical logits). Measured on three processes on the one RTX 5090 (--tp-local 0,0, bench pp64/tg128, two rounds interleaved), it gains nothing beyond noise: 0.8B tg128 43.5 / 42.7 tok/s before, 44.5 / 41.2 after, an exchange 421 / 420 µs before, 395 / 428 after; 4B 25.6 / 27.6 before, 24.9 / 27.6 after, 561 / 510 µs before, 575 / 496 after. On one GPU the workers' partials come close together, so there is little to overlap. Captured segments record the link buffers' addresses and are captured again if one differs (a GPU test moves an inbox). The 4-bit default is in Measured.

Built: linear attention by head (2026-12-02)

What exists.

  • TensorSlice is a list of ranges along one axis (Ranges, SliceRange); one range is the old case (new TensorSlice(columns, start, count), Start, Count), read exactly as before. Ranges keep their order and adjacent ones are joined (a node holding every head reads one range). Start of a slice of several ranges throws; At(i) maps a slice index to the whole tensor's.
  • Every slicing read path takes several ranges (WeightLoader.Slices.cs): stored BF16 and raw NVFP4/MXFP4 rows are that many direct reads (elements and block scales) into one allocation, in order; columns are gathered side by side a block of rows at a time; the managed path (f32, FP8, patched) reads each row range, or cuts each block's columns; vectors and the conv weight (a vector of channels × taps, its slice the channels' taps) are cut from the widened vector. ApplySlicedPatch keeps its signature; its loop maps indices through At (two lines changed).
  • WeightLoader.SliceRefusal(operand, slice): why a stored tensor cannot be served as a slice (a 4-bit column cut off a block boundary, FP4 in a block layout), or null. ShardOptions.SliceRefusal carries it to the planner; TpCluster and the node's join set it from the store and patch.
  • ShardDivisions (Experts, IndexedAttention, LinearAttention, Vocabulary; flags) and ShardOptions.Divisions, every one by default. Only LinearAttention is used here. TrainShard.PlanOptions passes Divisions = 0: training's plans are unchanged (all 183 Train* tests pass as they were).
  • Planner: a linear attention is divisible, a unit a key head with its value heads (linear attention, 16 key heads of 2 value heads); bytes per unit are the operator's weights, recurrent state and conv history at the planned sequences, divided by the key heads. It stays whole, with the reason in its label (and so in --tp-plan), when the division is not allowed (labelled linear attention exactly as before), with one key head, value heads that do not group over the key heads, or a cut the store refuses (each key head's cut is checked; a run of heads is then a run of aligned cuts). ShardPlanner.WholeLinearAttentionReason is the check.
  • Slicer (ShardSlicer.LinearSlices): key heads [k0, k0+kn) own value heads [k0·r, (k0+kn)·r) (r = NumVHeads / NumKHeads); the node holds the q, k and v rows of the in-projection (three ranges of one tensor), its z rows, a and b rows, its channels of the conv (the same three ranges, times the taps), its A_log and dt-bias entries, the output projection's columns for its value heads; the per-head-dim norm weight whole. Its plan is the operator with NumKHeads = kn, NumVHeads = kn·r. There is no output-projection bias in this operator.
  • Engine: no change. StateBytes, ConvHistoryBytes, the per-sequence state, mark/rewind copies, the verify snapshots (rows × StateBytes), fork, reset and the batch tables are all sized from the sliced plan's head counts, so a node holds its heads' state and its channels' history only. Linear attention has no window. The kernels are unchanged.

Checked before building (native source and CPU reference). amqe_gdn/amqe_gdn_batch and the CPU RunLinearAttention: the in-projection row is [q (nk·kd) | k (nk·kd) | v (nv·vd) | z (nv·vd) | b (nv) | a (nv)]; value head h reads key head h / (nv/nk) (the reference's repeat-interleave); the q/k L2 norm is per key head (one block of kd channels); decay and β per value head from its own a, b, A_log, dt bias; the recurrent state is [nv, kd, vd], per value head; the gated RMS norm is over each value head's vd with a weight shared by all heads; the conv is depthwise, its weight and history channel by channel. No term crosses heads before the output projection. The chunked prefill's tile width (16 or 32 value columns, chosen from nv·vd/32 against the SM count) changes with fewer heads, but each column's sums run in the same order, so a head's output does not depend on it.

Checks.

  • No GPU (TensorParallelTests): a slice of three row ranges and one of two column ranges of BF16 (the stored bits read straight, and the widened values), f32, raw NVFP4 and MXFP4 (elements and scales, the direct read and the managed one), block-scaled FP8, BF16 and f32 under a patch, a vector and a [24, 1, 4] conv weight: each equal, bit for bit, to the same rows/columns cut from the whole read; off-block 4-bit columns refused in advance and at the read. Planner: linear attention divided over 2, 3 and 5 nodes (more nodes than heads: some hold none of a layer), the slices of a head range exactly, whole when not allowed or when a cut is refused (the reason in Describe), the same bytes either way. The shard-reading tests now cover qwen3_5-gdn's divided layers (and at NVFP4). 39 CPU tests pass.
  • GPU (TensorParallelGpuTests, exact prefill, f32 KV, tolerance 2e-3), qwen3_5-gdn (2 key heads, 4 value heads) with linear attention divided: 2 nodes 2.6e-5, 3 nodes (0.6,1,1: the coordinator holds no head of layer 0, node 2 none of layer 2) 2.5e-5, uneven (3,1) 2.6e-5, NVFP4 2 nodes 2.9e-5 — the largest logit difference over prompts of 5 and 700 tokens (two chunks, the chunked recurrence), 4 greedy steps, mark and rewind, a 3-row verify and accepting 2, a fork stepped apart from its source (new), a batch of 3, a DecodeSession. The other shapes as before (qwen3 7e-6 to 9e-6, gemma4-moe 5.8e-5, llama-bias 7.5e-6). All 12 pass.

Real models (RTX 5090, one GPU, workers by --tp-local, loopback TCP, scripts/tp-check.ps1 with defaults — BF16-rounded prompt GEMMs, FP16 KV; bench --prompt-tokens 64 --steps 128 --repeat 3, best of 3). Before is the base commit's build (001f28f, linear attention whole), after this one; per-node bytes are the same in both (the planner balances bytes either way):

Model Nodes Node GB Greedy 60, before / after Top logit, before / after pp64 / tg128 tok/s, before after µs an exchange (bench), before / after
qwen3.5-0.8b 2 0.81 + 0.81 60 / 60 0.026 / 0.040 826 / 50.2 861 / 52.1 318 / 300
3 0.54 × 3 60 / 60 0.020 / 0.050 691 / 42.9 867 / 40.4 411 / 433
3 uneven (-,2,1) 1.48 + 0.10 + 0.05 60 / 60 0.031 / 0.049 1,126 / 74.1 846 / 51.4 466 / 402
qwen3.5-4b 2 4.37 + 4.37 60 / 60 0.020 / 0.026 401 / 33.1 433 / 32.7 424 / 384
3 2.91 × 3 60 / 60 0.013 / 0.036 354 / 28.3 281 / 28.1 503 / 660
3 uneven (-,2,1) 7.96 + 0.52 + 0.26 60 / 60 0.061 / 0.047 586 / 46.1 346 / 32.7 528 / 490

With AMQL_GPU_PREFILL=f32 AMQL_KV_FORMAT=f32 (this build, the same six shapes, greedy only): 60 of 60 tokens equal everywhere and the top logit within the printed 1e-4, so the larger default differences after are a different split rounding BF16 prompt GEMMs and FP16 KV differently, not an error in the division.

The plans: before, every linear-attention layer is whole on one node (the 4B's 24 of 32 layers, the 0.8B's 18 of 24); after, each is divided (0.8B: 16 key heads of 1 value head, [0, 4) | [4, 16) on two nodes; 4B: 16 key heads of 2, [0, 14) | [14, 15) | [15, 16) on the uneven three). On one shared GPU dividing does not pay and should not be expected to: every node now takes part in every layer's exchange, so the uneven clusters, whose small nodes held whole layers of few operators before, now run 2,562 exchanges for 60 tokens instead of 1,525 (0.8B) and are slower (74 → 51 tok/s on the 0.8B, 46 → 33 on the 4B). The division is for a model whose linear-attention layers do not fit, or should not sit whole, on one card. Forming the 3-node 4B took 11.9 s against 4.0 s before (the column slices' host gathers; since measured and fixed: 4.3-4.9 s, see Loose ends).

The local path (scripts/tp-local-path-check.sh, base build then this build): the same four checksums (61903d9638b2ebf0, 0ba346f870114499 decode; ce620150700a31e1, 70918af478f94c89 profiled). Decode tok/s, 5 runs: 0.8B 637-665 before, 639-666 after; 4B 168.5-169.5 before, 169.0-170.0 after. Batches of 1/2/4/8: 0.8B 686/1268/1870/1721 before, 684/1273/1876/1727 after; 4B 171.7/319.5/575.1/685.8 before, 172.4/320.4/574.6/688.6 after. Profiled step 2.75 / 2.76 ms (0.8B), 6.65 / 6.68 ms (4B). Only distributed code changed.

Deviations. When this was built the protocol magic stayed AMQLTP02 and ShardDivisions was not carried in the join; both changed later in the round: the join carries Divisions (and whether the head is divided, with its unit) and the magic is AMQLTP03, set with the last of the wire changes (see the vocabulary section). Dividing linear attention in training is not done (as the rules say).

Built: side data, experts by expert (2026-12-02)

Piece Where
ShardDivisions (Experts, IndexedAttention, LinearAttention, Vocabulary) in ShardOptions and TpClusterOptions (all by default); amql-cli … --tp-divide all|none|experts,… ShardPlan.cs, TpCluster.cs, Program.TensorParallel.cs
The experts slot: ShardPlan.Experts(layer, node), ExpertsDivided, Shard(layer, slot, node), Holders(layer, ShardSlot); ShardOperator.Experts, FirstBytes ShardPlan.cs, ShardPlanner.cs
A node's experts: a RoutedFfnOp of fewer experts (FirstExpert, StackOnly) ShardSlicer.cs, Plan.cs, GpuEngine.UploadExperts
Side data on the wire: the header carries the operator's slot and the side bytes after the rows; buffers sized at the join (TpWire.SideBytes, checked by the node) TpTransport.cs, TpLinks.cs, TpNode.cs, TpCluster.cs
The coordinator's routing and join (ShardExperts), a holder's part (ExpertsPartial, WorkerExperts) GpuEngine.Shard.cs
amqe_moe_experts_range: the expert kernels over a node's share under a given selection native/amql_cuda/amql_moe.cu

The plan. With Experts allowed, a routed layer has up to three operators: its mixer, the dense FFN beside the experts (an ordinary dense FFN in the FFN slot, by 32 rows), and the experts (units are experts; a shared expert and its gate go with the first unit, FirstBytes). The router, its scale, the experts' scale, the selection bias and the norms around the experts are the coordinator's fixed pieces. The fingerprint, JSON and Describe show the experts slot only where experts are divided, so a plan without (training's, or --tp-divide none) reads exactly as the first version's: same canonical text, fingerprint, JSON and layout. Training passes ShardDivisions.None (TrainShard.PlanOptions), so its plans keep routed FFNs whole.

The pass. The coordinator norms, routes with amqe_moe_route exactly as one engine does (the input norm of experts beside a dense FFN fused into the routing, as there), and sends each holder the experts' input with the selection as side data: per row, TopK int32 expert indices then TopK f32 final weights. A holder runs amqe_moe_experts_range over its stack: a small kernel re-bases the indices to its experts and marks the others -1; the grouping kernel leaves those pairs out, the decode kernels (gemv, mix) skip them through a template variant, and their slots are zeroed where the mixture is not taken in the kernel; then amqe_moe_finish (no norms, replace) gives Σ weight · expert(x) over its pairs. The coordinator adds the parts in node order, then the routed-out norm, the dense branch (its own exchange before the routing) with its norm, the post norm and the residual: the single engine's unfused path. A worker never receives the residual where experts are divided.

Deviations and limits.

  • No norm on a worker (as the design says): the first version's "routed experts whole on a worker get the residual" path remains only for ShardDivisions.None.
  • Packed expert stacks (one 3-D tensor a projection) are not sliced: such layers are row-only, so their plans run by visit, which ShardPlanner.Build refuses before anything is planned; the planner would place such a stack whole in the experts slot with the reason ("a packed stack the slices cannot serve"). A stack stored one tensor per expert can always be cut, so no stored format makes a per-expert stack whole.
  • Shared experts are planned (with the first unit) but the device engine refuses models with a shared expert altogether (GpuEngine.Unsupported), so that part is not exercised on a device.
  • The dense FFN beside the experts and the experts share one exchange where every worker holds part of both or of neither (ShardPlan.ExpertsFolded, the usual case): the coordinator routes first, then sends the dense input with the experts' input and the selection as side data, and each holder replies with its dense partial followed by its experts' partial. The two are summed apart, each in node order (the routed-out and dense-out norms come after the sums and are not linear, so one plain sum before them would not be exact): the sums are exactly the two exchanges'. Otherwise (a worker holding one and not the other) the layer takes two exchanges, as first built.
  • The join carries the divisions (TpJoin.Divisions), and the node plans with them.
  • Skipping a holder none of whose experts were picked is not done: the captured segments assume the same holders every step, and nothing was measured to show it would pay.
  • Bytes: the first version's count of a whole routed FFN left out the router's and the experts' scale vectors and a shared expert's gate; the fixed pieces now count them (a few KB a layer).
  • amqe_moe_experts itself is unchanged in what it launches; its body moved into a function that both entries call, the new one with skipping on. The kernels it shares with the new entry gained a skip check only in instantiations the local path does not use, and one if (idx < 0) in the grouping kernel.

Indexed attention by head: not built. The single engine has no indexed attention: GpuEngine.Unsupported refuses any layer with a sparse indexer ("block-sparse attention"), and the only implementation is the managed one (GenericRuntime.SparseAttention.cs, where selection, SelectSparseKeys, is already separate from the attention over the kept keys). Dividing it by head therefore first needs it on the device: a kernel for the indexer (its q/k projection, norms and rotary, pooled block keys kept per sequence beside the KV cache, the per-query block scores and top-k), an attention kernel that reads a per-query list of blocks (plus the tail) instead of the whole past, and the planner/slicer/side-data work above (the selection as side data, holders with their heads' KV only). That is a native addition comparable to the attention kernels themselves, so per the instructions for this round it stopped there: indexed attention stays whole (and is not run on the device at all). (Since built, both: see Built: indexed attention by head.)

Checks (RTX 5090, 2026-12-02).

  • TensorParallelGpuTests (in-process nodes over loopback, exact prefill, f32 KV; prompts of 5 and 700 tokens, 4 greedy steps, mark and rewind, a 3-row verify and accepting 2, a batch of 3, a DecodeSession): all 19 pass. Experts divided: gemma4-moe (experts beside a dense FFN) over 2, 3, uneven (3:1), a coordinator holding few (0.4:1:1), a small node holding none of some layer's experts (1:1:0.15), and NVFP4 experts; qwen3_moe (experts alone, normalised over the picks) over 2 and 3; mixtral over 3; gemma4-moe whole (ShardDivisions.None) over 3 as before. Largest difference from the single engine, relative to the largest logit: 1.0e-6 to 1.9e-5 for the expert shapes (1.9e-5 the worst, the small node), against the 2e-3 the tests allow.
  • TensorParallelTests (CPU): an expert stack larger than any node's capacity is refused whole ("fits on no node") and now plans, every expert of every layer on exactly one node; units and bytes add up (UnitsBytes over the holders gives each experts operator's bytes, a shared expert with the first unit); fingerprint, Describe and JSON deterministic and round-tripping; sliced plans hold their experts and no router or layer norm; training's options (None) give whole routed FFNs, no experts slot in the JSON and the first version's text. All 37 pass.
  • TrainTensorParallel* (58) and ServerClusterTests (3) pass unchanged.

gemma-4-26b-a4b-nvfp4-gptq over local workers on the one GPU (scripts/tp-check.ps1, --tp-local, chat prompt, 60 greedy tokens against the single engine; bench --prompt-tokens 64 --steps 128 --repeat 3; --tp-divide none is the first version's plan):

Nodes Plan Bytes per node Greedy, defaults Top logit, defaults Exact prefill, f32 KV bench pp64 / tg128, tok/s Exchanges (60-token generate), µs each
2 experts whole 7.48 / 7.46 GB 60/60 0.433 423 / 40.3 2,745, 660
2 experts divided 7.47 / 7.47 GB 60/60 0.461 60/60, 0 231 / 22.8 5,490, 522
3 experts whole 4.97 / 4.99 / 4.98 GB 57/60 0.428 388 / 33.6 3,050, 889
3 experts divided 4.98 / 4.98 / 4.98 GB 57/60 0.477 60/60, 1e-4 221 / 17.8 5,490, 770

With room to spare the whole placement already balanced this model's bytes, so dividing changes little there; what it changes is that no single piece is a layer's whole stack any more (it now plans where a stack exceeds a node, the CPU test above). It costs speed on one GPU: every layer now exchanges both its dense FFN and its experts with every holder (twice the exchanges of the whole plan, where a layer's FFN was on one node), and a step here is bound by exchanges between processes taking turns on one device. Sending the dense FFN's input and the experts' input in one exchange (both are known before the experts run; the routing could run before the dense exchange) would bring the count back to the first version's; that is now done (below). Greedy text at the defaults diverges at the same place with experts whole or divided (3 nodes: 57/60 both); at exact prefill and f32 KV it is 60/60 on 2 and 3 nodes.

One exchange for the dense FFN and the experts (after merging main 04cb140; the same model, shapes and bench, AMQL_GPU_PREFILL=bf16 as above since a 4-bit cluster now defaults to exact prefill; both plans measured on this build, the divided one folding all 30 layers):

Nodes Plan Greedy, BF16 prefill Exact prefill, f32 KV bench pp64 / tg128, tok/s Exchanges (60-token generate)
2 experts whole 60/60 (0.433) 426 / 43.2 2,745
2 divided, two exchanges (before) 60/60 (0.461) 60/60, 0 231 / 22.8 5,490
2 divided, folded 60/60 (0.461) 60/60, 0 348 / 32.6 3,660
3 experts whole 57/60 (0.428) 332 / 34.7 3,050
3 divided, two exchanges (before) 57/60 (0.477) 60/60, 1e-4 221 / 17.8 5,490
3 divided, folded 57/60 (0.477) 60/60, 1e-4 175 / 25.0; again 161 / 24.2 3,660

Decode gains 40-43% from folding; the divided plan still makes a third more exchanges than the whole one (every layer's FFN exchanges with every worker, where whole a layer's FFN is on one node and a third of the layers need no exchange at all), and stays 25-30% slower on one GPU. The 3-node prompt figure fell (221 to 161-175 in three runs), which was not investigated then: a prompt's experts on each holder run the tensor-core path, which synchronises the host to size its GEMMs, once a layer. (Measured since: run-to-run noise, not the folding; see Loose ends.)

Tests after the merge and the folding, each class alone: TensorParallelTests 46/46, TensorParallelGpuTests 23/23 (gemma4-moe folds every layer over 2, 3 and 3:1 nodes, 5 of 6 at 0.4:1:1 and 2 of 6 at 1:1:0.15, so both the folded and the two-exchange paths run, each with several worker holders; qwen3_moe and mixtral exchange experts alone with two workers; largest absolute logit difference 1.1e-4 against the 2e-3 tolerance), TrainTensorParallelTests 26, …FaultTests 6, …StateTests 8, …StepTests 12, TrainLocalIdentityTests 1, ServerClusterTests 3: all pass. The local path for gemma-4-26b-a4b-nvfp4-gptq (the base 001f28f against this build, alternately twice, a quiet machine): checksums 88d5ae41f91b3872 / 8f08516872ed4837 everywhere; decode 270.1-273.0 and 271.4-272.8 tok/s before, 271.6-273.6 and 270.9-273.1 after; batches 1/2/4/8 275-278 / 455-457 / 590-591 / 695-696 both.

The local path (scripts/tp-local-path-check.sh, the base 001f28f built from its own tree with its own native library, then this build, then the base again; checksums of prefill and last-step logits):

Model before after before, again
qwen3.5-0.8b checksum (bench / profile) 61903d9638b2ebf0 / ce620150700a31e1 the same the same
decode tok/s, 5 runs 597-659 650-667 603-628
batch 1/2/4/8 687 / 1273 / 1890 / 1720 666 / 1234 / 1831 / 1715 654 / 1215 / 1793 / 1671
qwen3.5-4b checksum 0ba346f870114499 / 70918af478f94c89 the same
decode tok/s, 5 runs 170.3-170.8 127.6-163.3
batch 1/2/4/8 173 / 318 / 568 / 681 159 / 297 / 534 / 636
gemma-4-26b-a4b-nvfp4-gptq (routed experts: the kernels this round touched) checksum 88d5ae41f91b3872 / 8f08516872ed4837 the same the same
decode tok/s, 5 runs 270.5-272.9 233.5-236.1 258.0-260.8
batch 1/2/4/8 277 / 455 / 593 / 694 277 / 446 / 585 / 689 272 / 449 / 578 / 675
profiled step 6.23 ms 6.35 ms 8.31 ms

Every checksum is the same. The speeds moved by up to 15% between runs of the same build (the base's own two runs differ by 5% and its profiled step by a third), so the machine was not quiet (other work shared the GPU and CPU); the gemma decode was then measured interleaved, base and this build alternately, best of 5 each: base 242.0, this 271.6, base 272.2, this 269.6 tok/s. Nothing here shows a change in the local path's speed beyond that noise, and its arithmetic is bit-identical.

Built: the head and the embedding, by vocabulary (2026-12-02)

What exists.

Piece Where
ShardDivisions (Experts, IndexedAttention, LinearAttention, Vocabulary; all by default) and ShardOptions.Divisions, VocabularyUnitRows (1,024) Distributed/ShardPlan.cs
The head as a divisible operator: ShardPlan.Head (ShardHead: its shards, the scored rows, where the embedding is), HeadShard, HeadRows, HeadHolders; HoldsAny counts it; fingerprint, JSON and Describe carry it only when the head divides ShardPlan.cs, ShardPlanner.cs
Each holder's rows of the projection (a tied table's rows serve both uses) ShardSlicer.cs
The head exchange, the coordinator's and the workers' rows of the head, lookups on the host GpuEngine.Vocabulary.cs
A matrix's rows in the form the device holds it, read one at a time through the page-cached map WeightLoader.Rows.cs
Reply buffers sized for the logits (TpWire.ReplyBufferBytes), ITpWorkerLinks.ReplyBytes TpTransport.cs, TpLinks.cs, TpCluster.cs, TpNode.cs
Tests TensorParallelTests.cs (planner), TensorParallelVocabularyTests.cs (GPU)

The plan. With Vocabulary allowed (inference; training passes no division and plans exactly as before, fingerprints included) the head is a divisible operator of VocabularyUnitRows rows of the scored vocabulary, the last unit shorter; a padded table's unused rows are in no unit, never read and never scored. It is placed after the layers' operators, by the same largest remainder over what each node still lacks of its target: its units are much finer than a layer's, so placed last it takes up what the layers' units left and the nodes end nearest their targets. The fixed pieces are the norms; an untied embedding joins them on the coordinator's device by this rule: with the embedding counted in the total, node 0's target is total × capacity₀ / Σ capacity, and the table is on its device when the norms and the table fit within that target; otherwise its rows are read on the host and it has no device bytes. A tied table is the head's rows and in no fixed piece. "The fixed pieces exceed node 0" can now only be a coordinator offering less than its norms.

The exchange. The coordinator sends the rows that need logits (a step: one a sequence; a verify: its rows; a prefill: its last) to every other holder, computes its own rows meanwhile, and places each holder's logits (f32) at its offset in the logits buffer every reader uses, a row at a time; the multiplier and softcapping are then applied once, to the assembled rows, with the single engine's kernel (amqe_logit_post). It is host work between a captured step's segments like the other exchanges (the coordinator's sync and send, its wait; a worker's wait and reply), so steps stay captured. Every node keeps the receive buffer it had (with the experts' side data after the rows) and one rule sizes the reply buffers, the worker's outbox and the coordinator's inbox for it (TpWire.ReplyBufferBytes): DataAt + max(4 × chunk rows × hidden + a folded second partial, 4 × 8 × the vocabulary rows the node holds) bytes, the folded second partial being a layer's experts' partial when they share the dense FFN's exchange (ReplyExtraBytes), 8 being the most rows a pass scores (a batch of MaxBatch, or a verify of the chosen token and MaxDrafts drafts); both sides size it from the plan at the join (a node holding all of a 248k vocabulary: 7.9 MB). These are the same per-node buffers the layers' partials use, so the captured segments' buffer guard (TpBuffers) covers the head too. With two or more worker holders the coordinator takes their logits in the order they come (ReceiveAny, as Exchange stages partials), launching the copies from the host action; each holder's rows have their own place in the row and nothing is summed, so the order cannot change the result. Before dividing the head the planner asks SliceRefusal for every unit's row cut of the projection; if one is refused the head and the embedding stay on the coordinator as in the first round (the same plan and fingerprint) and ShardPlan.HeadWhole gives the reason (printed with the plan).

The embedding. When the coordinator holds the table whole on its device (an untied table with room, or every row of a tied one) the lookup is amqe_embed as before. Otherwise the coordinator reads each token's row through the page-cached map (SegmentRead.Repeated) in the form the device would hold the table in (WeightLoader.RowForm: the stored BF16 bits; raw NVFP4/MXFP4 elements and block scales with the tensor scale; f32 for anything widened, a patch's delta added), stages them in pinned memory and runs amqe_embed itself over the staged rows with the ids 0, 1, … — the same bytes into the same kernel, so the same bits by construction, and a test checks it for every form (below). So no format needs the exchange with the row's holder that the design allowed for, and none was built. A 4-bit table whose block layout the engine converts at load (not raw NVFP4/MXFP4) is refused by name. The other users of the table on the coordinator are the drafter and the MTP head (then never loaded on a distributed engine; since, they run on the coordinator and look rows up the same way, see Built: speculative decoding) and images (refused by name on a distributed model), so nothing else reads it.

Deviations from the design.

  • The rows sent are the residual, not the final-normed rows: every holder runs the final norm itself, exactly as the single engine runs the whole head (fused into the projection when it can be), so a holder's logits are the single engine's dot products. Every node has the final norm's weights (a few KB).
  • The join carries the head's state: beside Divisions, VocabularyUnitRows and whether the head is divided (HeadDivided); a node whose own plan disagrees refuses the join by name (the fingerprint would differ too). With the routed experts' merge the protocol's magic became AMQLTP03 (side data, the experts slot and the head's logits are all on the wire).
  • The unit is an option (VocabularyUnitRows, carried in the join): the test fixtures' vocabularies are 128 rows, so the GPU tests divide them in units of 32.
  • The device engine now scores a padded table (it refused one before): the head is uploaded with all its stored rows and projected over the scored ones (n: vocab), which for every unpadded model is the same call with the same arguments as before. This was needed to test a padded table against the single engine.

Tests. TensorParallelVocabularyTests (GPU): rows looked up on the host give the device kernel's bits for stored BF16, BF16 under a patch (f32), F16 and F32 (widened), raw NVFP4 with a tensor scale of 0.375, a quantised container's NVFP4 and MXFP4, a checkpoint's MXFP8 (widened) and NVFP4 experts, each with and without an embedding scale; and clusters with a divided head (units of 32 rows over the fixtures' 128) against the single engine at exact prefill and f32 KV — 2 and 3 nodes, uneven (3:1), a coordinator holding nothing but its norms (no head rows, every operator on the workers, embedding rows on the host), tied tables (gemma4-moe, gemma2: both with softcapping) on the device and on the host, a multiplier and softcapping added to an untied model, a padded table (100 of 128 rows scored), NVFP4 rows of the head; for each, prompts of 5 and 700 tokens, 4 greedy steps, mark and rewind, a 4-row verify and accepting 2, a batch of 3 stepped 6 times (captured segments replaying), and a DecodeSession over the cluster. The largest logit difference over every compared row was 3.4e-6 to 1.0e-5 for qwen3 and gemma2, 5.8e-5 for gemma4-moe (the attention and FFN splits sum in another order; the head's own rows are the single engine's dot products, but a holder's GEMV may split its rows' sums differently when it has few rows, so they are not claimed bit-equal). After merging main (04cb140): TensorParallelTests (CPU, 47), TensorParallelVocabularyTests (14), TensorParallelGpuTests (14, with the head divided by default), ServerClusterTests (3), GpuEngineTests (42) and every Train* class (183) pass, each class run alone. The real-model runs below are from before that merge.

Real models (RTX 5090, every node a process on the one GPU over loopback TCP, scripts/tp-check.ps1: 60 greedy tokens of the chat prompt against the single engine with the defaults, bench pp64 / tg128 best of 3; before is the design's base commit 001f28f, which keeps the head and the embedding on the coordinator). All three tables are tied. A coordinator capacity below the table (0.3 GB for the 0.8B's 0.51 GB table, 1.0 GB for the 4B's 1.27 GB and the 26B's 1.48 GB) plans now, its embedding rows read on the host; before, it is refused (run for the 4B's 2-node shape: "the coordinator's fixed pieces (embedding, head, norms) need 1.27 GB but it offers 1.00 GB"; the others follow from the same rule and were not run).

Model Nodes (--tp-capacity) Greedy Top logit Head rows (units of 1,024) by node Bytes by node tg128 before tg128 after
qwen3.5-0.8b 2 60/60 0.032 121 / 122 0.81 / 0.81 GB 53.1 57.9
3 60/60 0.032 81 / 80 / 82 0.54 ×3 GB 43.8 44.7
2 (0.3,-) 60/60 0.032 3 / 240 0.01 / 1.61 GB — 41.6
3 (0.3,-,-) 60/60 0.035 1 / 121 / 121 0.01 / 0.81 / 0.81 GB — 41.6
qwen3.5-4b 2 60/60 0.023 121 / 122 4.37 / 4.37 GB 34.7 34.7
3 60/60 0.038 79 / 81 / 83 2.91 ×3 GB 29.4 31.4
2 (1.0,-) 60/60 0.032 13 / 230 0.27 / 8.46 GB refused 30.1
3 (1.0,-,-) 60/60 0.026 7 / 118 / 118 0.14 / 4.30 / 4.30 GB — 27.0
gemma-4-26b-a4b-nvfp4-gptq 2 60/60 0.41 128 / 128 7.47 / 7.47 GB 44.0 41.7
3 57/60 0.47 84 / 94 / 78 4.98 ×3 GB 33.8 35.0
2 (1.0,-) 60/60 0.46 70 / 186 0.47 / 14.47 GB — 32.8
3 (1.0,-,-) 60/60 0.40 50 / 103 / 103 0.24 / 7.35 / 7.35 GB — 29.4

(The before runs agree with the first round's table: gemma's 3 nodes gave 57/60 there too, with the head on the coordinator; the top-logit differences are the defaults' BF16 prompt GEMMs and FP16 KV, as before.) On the default shapes the head's division costs nothing measurable on one GPU: the step's time is the layers' round trips, and tg128 moves by run-to-run noise in both directions.

What the head exchange costs (AMQL_TP_TIMING=1, 3 nodes with the small coordinator, so both workers hold nearly all of the head): the coordinator waits 690 µs (26B), 830 µs (0.8B) and 1,060 µs (4B) for the head's logits against ~250 µs for a layer's partial. That wait is the workers' head GEMVs (each ~120k rows; on the 4B 0.6 GB of BF16 read a step, run in the workers' processes taking turns on the one GPU) and the replies (0.5 MB of f32 each, ~1 MB a step); on one engine the same GEMV runs inside the step graph, so on a shared GPU the head costs one round trip more per step, and on GPUs of their own its rows would be read in parallel.

The local path (scripts/tp-local-path-check.sh: the base commit 001f28f, this build, the base again): the same four checksums every time (61903d9638b2ebf0, 0ba346f870114499 decode; ce620150700a31e1, 70918af478f94c89 profiled). Decode tok/s, best of 5: 0.8B 671.8 / 673.3 / 674.2, 4B 171.4 / 171.4 / 171.4; batches of 1/2/4/8: 0.8B 690/1279/1883/1751, 689/1276/1886/1753, 694/1275/1889/1757; 4B 173.8/322.4/578.2/690.8, 173.8/323.1/579.4/693.2, 173.7/322.7/578.8/693.3. After merging main, again (base, the merged build, base): the same four checksums; decode best of 5: 0.8B 672.2 / 652.7 / 663.0 (runs 5 of each: the merged build's best is the lowest of the six runs here, and 673.3 in the run above; the profiled tg64 662.5 against 659.3 / 654.4), 4B 169.9 / 171.4 / 171.4; batches of 1/2/4/8: 0.8B 692/1282/1887/1755, 686/1249/1900/1757, 689/1277/1890/1760; 4B 172.5/319.8/572.2/683.9, 173.4/322.5/578.7/692.9, 173.9/322.5/578.0/692.6. The local path's changes are a null check before the lookup and before the head, and the head uploaded with its stored rows and projected with n: vocab (the same arguments for an unpadded model).

After the routed experts' merge (main dea36e2, the rebuilt native library b3cd9722…; the base build keeps its own library). The local path, base / merged / base, then the 0.8B alone merged / base / merged: the same four checksums every time; 0.8B decode best of 5: 668.3 / 673.4 / 676.3, then 674.8 / 671.7 / 673.9 — the 652.7 above was a slow run, not a change; 4B 171.2 / 170.9 / 171.7; batches of 1/2/4/8: 0.8B 681/1259/1877/1751, 687/1279/1887/1756, 690/1271/1886/1754; 4B 173.0/321.8/576.0/693.0, 173.3/322.9/577.8/694.2, 173.5/323.0/577.3/694.2. Tests, each class alone: TensorParallelTests 53, TensorParallelVocabularyTests 14, TensorParallelGpuTests 23, ServerClusterTests 3, ClusterOperationsTests 4, ClusterProcessTests 3, GpuEngineTests 42, Train* 183, ServerModelRegistryTests 17, all passing.

gemma-4-26b-a4b-nvfp4-gptq with everything divided (attention by KV head, the dense FFN beside the experts by rows, the experts by expert, the head by vocabulary; exact prefill by default, the coordinator at 1.0 GB, its embedding rows read on the host), against the single engine at AMQL_GPU_PREFILL=f32, 60 greedy tokens: 2 nodes 60/60, top logit within 0.0031 (bytes 0.47 / 14.47 GB, head units 10 / 246); 3 nodes 60/60, within 0.020 (0.24 / 7.35 / 7.35 GB, head units 5 / 126 / 125). Bench pp64 / tg128: 287 / 29.4 tok/s on 2 nodes, 282 / 24.6 on 3 (one RTX 5090, every node a process; exact prefill costs the prompt rate against the defaults' BF16 GEMMs).

Built: KV paging across nodes (2026-12-02)

GpuEngine.Paging.cs, Distributed/TpPages.cs.

  • Save. SaveMark on a coordinator picks a page id (a counter of the engine), writes its own part and has every worker write its own (TpCallKind.SavePage), each with the single engine's own save (SaveMarkCore, unchanged) over its shard, behind a short header: magic, the plan's fingerprint, the node's MarkGeometry, the node, the id, the payload's length. The stream gets the record: the engine's formation (a random id per engine), the fingerprint, the id, the mark's position and each node's bytes (~90 bytes). A worker that cannot write declines; the page is then dropped everywhere and SaveMark throws IOException naming the node, and the cluster runs on.
  • Asked operations. The new kinds are sent with ITpCoordinatorLinks.Ask, which gathers each worker's acknowledgement with its status: 2 an answer (its bytes), 3 declined (TpDeclinedException on the worker: it changed nothing and stays in step). Status 1 (a failure) fails the links as before. The magic, buffer sizes and planner are unchanged.
  • Restore. The record must be this formation's and plan's (else InvalidDataException). Then the coordinator checks its own page and asks every worker (PreparePage: the file exists, its header names this plan, node, id and geometry, and its length is the header's) and compares each node's bytes with the record's; any refusal throws InvalidDataException naming the node ("node 2 (127.0.0.1:51469): holds no page 1 (missing from …)", "… page 2 is truncated: 86,956 of its 87,056 bytes", "… page 3 was saved under plan 0292…; this node runs 9292…") before any node has changed. Then the coordinator restores its part (quietly: no mirrored calls) and every worker restores its own under the new sequence's id (RestorePage). A worker failing at that point leaves the nodes out of step: like any failure mid-pass it fails the cluster (its acknowledgement is a failure). A coordinator failing on its own part first has changed no worker and only throws.
  • Drop and end. DropSavedMark(record) deletes the page on every node (no-op on a single engine; quiet on an ended cluster). Each membership (and the coordinator's cluster) has a folder {lineage}~{model}~{cluster}~n{node} under its page root (TpNodeOptions.PageRoot, TpClusterOptions.PageRoot, tp-worker --page-dir, amql-server <--kv-dir>/_cluster-pages, else amql-tp-pages in the temp folder) holding a .live file opened exclusively for its life; the folder is removed when the membership ends (released, left, link gone, coordinator silent). A join removes folders of the same lineage and model that nobody holds; a node's start (and a cluster's formation) removes any unheld folder unchanged for a day. A held folder is never removed.
  • Bytes. PagedBytes(record) is the nodes' bytes; amql-server's page store counts them in its disk budget beside the record (KvPageStore.Put(…, elsewhere)). DeviceBytes on a coordinator counts every node's per-sequence memory (each worker's from its sliced plan, worked out on the coordinator), so the GPU budget does too; at f32 and FP16 KV it equals the single engine's.
  • amql-server. The disk tier is no longer turned off for a distributed model and kv_disk reports whether it has one. The store tells the batch thread of records it lets go of (budget, expiry, replaced, failed write), whose pages are then dropped; a restored or refused record's pages are dropped; a cancelled request's taken record too. A distributed model's MarkGeometry names the formation, so records of an earlier formation are deleted as stale at load, and its kept sequences are not paged out at shutdown (the pages would go with the release).

Deviations. The coordinator's own part is a page in its own folder, like a worker's, not in the record (one format, one prepare). Each node's file is the single engine's save behind a header; a node that holds nothing of the model still writes its 16-byte mark header. The drop of a record the store lets go of runs on the batch thread (queued), not at once. KV downloads and the rest stay refused (the drafter has since loaded on the coordinator, whose page then carries its state: see Built: speculative decoding).

Checks (RTX 5090, in-process nodes over loopback, exact prefill; TensorParallelPagingTests, TpPagesTests, all 15 pass): prefill 600 tokens, mark, 100 more, three steps, save, two more steps, restore; the restored sequence's 100-token prefill, four steps and a rewind are bit for bit those of the same cluster's sequence rewound to the mark (gemma4-moe's windowed layers to 1e-3, as on one engine), and within 2e-3 of the single engine (largest relative difference 6e-6): qwen3 over 2 and 3 nodes (two KV heads over three: one holds none of a layer) at f32, FP16 and NVFP4; qwen3_5-gdn (linear attention divided) over 2, and 0.6:1:1 (the coordinator holds no head of a layer) at f32 and NVFP4; gemma4-moe (experts divided) over 2 and 3 at f32 and FP16. Pages on disk are the single engine's save plus ~200-350 bytes a node (qwen3 f32: 614,842 bytes on 2 nodes against 614,416). Refusals (missing, truncated, another plan's on a worker; missing and truncated on the coordinator) name the node, leave the cluster running and the sequence continuing bit for bit, and a later save and restore works. Three sequences with their own marks save, step on as a batch, restore and step as a batch bit for bit. Dropped pages and, at release, every membership's folder are gone. ServerClusterTests (in-process servers, GPU budget 0, --kv-dir): a two-turn conversation through a distributed model is paged out after the first turn (the record in the model's folder, a page in each node's folder), restored for the second (1,125 tokens restored, 73 prefilled), and both replies equal a local server's without eviction; removing the distribution removes the pages.

qwen3.5-4b over 2 nodes (bench --page --prompt-tokens N --steps 16 --repeat 3 [--tp-local 0]: two processes on the one RTX 5090, loopback TCP, pages in the temp folder on the system SSD; the mark after N−1 tokens, saved, restored, then the last prompt token and 16 greedy steps compared with the sequence rewound; times include each node's device download and file write, and the asked round trips):

KV Mark at Bytes Save, ms (3 runs) Restore, ms (3 runs) After the restore
one engine FP16 4,095 203.7 MB 77 / 88 / 100 59 / 44 / 47 bit for bit
2 nodes FP16 4,095 186.9 MB 81 / 75 / 89 62 / 60 / 65 bit for bit
2 nodes FP16 2,047 119.8 MB 63 / 55 / 58 48 / 48 / 48 bit for bit
one engine f32 4,095 354.6 MB 114 / 137 / 158 83 / 73 / 74 bit for bit
2 nodes f32 4,095 321.1 MB 131 / 122 / 125 105 / 96 / 100 bit for bit

The cluster's pages are smaller than the single engine's save because the single engine also saves its MTP drafter's cache (the distributed engine loaded no drafter then; since, the coordinator's page carries it too): one attention layer's KV, 16.8 MB at FP16 and 4,095 tokens. The two nodes write in parallel; on one GPU and one disk that gains nothing, and a restore costs ~15-30% more than one engine's (the prepare round trip, two processes taking turns on the device).

The local path (scripts/tp-local-path-check.sh, the base dea36e2 built from its own tree, then this build, then the base again): the same four checksums (61903d9638b2ebf0, 0ba346f870114499 decode; ce620150700a31e1, 70918af478f94c89 profiled). Decode tok/s, 5 runs: 0.8B 657-678 before, 655-673 after, 651-675 before again; 4B 170.9-171.7, 169.9-171.1, 169.7-171.3. Batches 1/2/4/8: 0.8B 686/1279/1889/1755, 689/1270/1891/1756, 683/1268/1889/1755; 4B 173.4/321.4/575.1/693.4, 173.6/322.7/577.0/693.1, 173.0/323.0/578.7/694.5. Profiled step 2.78 / 2.64 / 2.74 ms (0.8B), 6.71 / 6.64 / 6.67 ms (4B). The single engine's save and restore are the same code moved into SaveMarkCore/RestoreMarkCore; KvPagingTests (13) and KvFormatTests (13) pass, TensorParallelGpuTests (23), TensorParallelTests (46) and ServerClusterTests (4).

After merging main (c6a029c, the head divided by vocabulary) the paging tests also run a cluster whose coordinator holds none of the head nor any operator (qwen3 at f32 and qwen3_5-gdn at FP16, 0:1:1): 16 of 16 pass.

gemma4-moe at FP16 KV is not held to the single engine in the paging test (it is held to the unpaged cluster, bit for bit): see the next section for why.

KV formats across nodes: FP16 and NVFP4 against the single engine (2026-12-02)

The question: gemma4-moe at FP16 KV (the default format) over 2 and 3 nodes was 0.12, 0.47 and up to 2.29 (largest logit ~4.6) from the single engine on its first decode steps after a 700-token prompt, while the prompt agreed and f32 KV agreed to 6e-6. A defect or rounding? It is rounding, amplified by this fixture and turned into a discrete jump by a near-tied expert pick. No code changed. (Measured later with the router's scores, below: it is a near tie, but not where this section first placed it: the tie that matters is a prompt row's pick in layer 4, and the jumps on the steps follow from it.)

How it was found (a temporary, environment-guarded tap of every layer's residual and every routed layer's selection on both engines, steps taken as 1-row prefills so both run uncaptured; removed after):

  • Bisected by division, 700 tokens, 2 nodes: --tp-divide none (attention by head, routed FFNs whole) 0.12 / 0.47 on steps 0 / 1; all divided 0.004 / 0.002; none with the second node a sliver (it holds one layer's half attention, the coordinator everything else) 9e-6 / 2.5e-5. At 100 tokens (no window slides) none 2 nodes 0.015 / 2.36. At 5 tokens 8e-4 / 3e-3. No division and no kind of layer (windowed or global) is the source alone: the size follows how much of the model is summed in another order, not one operator. Captured segments off (AMQL_TP_GRAPHS=0) and a 1-row prefill in place of a step give the same; a step alone and in a batch are bit-identical on the single engine.
  • The single engine's own sensitivity: the same engine at FP16 against f32 KV is 0.0295 / 0.237 on those steps (700 tokens): the fixture's last layer (global attention, then 8 experts top 2) moves its logits by a tenth of the largest for a change of storage format. An f32-rounding-size perturbation inside the single engine (the prompt read in two pieces instead of one: 8.7e-6 at f32 KV) grows at FP16 KV to 1.8e-4 / 5.6e-4 on layers 3 / 4's residual, the size of the cluster's own gaps there (1.9e-4 / 6.4e-4).
  • Layer by layer at the first jump (100 tokens, 3 nodes, step 1; 700 tokens, 3 nodes, step 1): layers 0-4 differ from the single engine by 1e-6 to 1.2e-3 in the residual (the single engine's own FP16-against-f32 gap on the same layers: 1e-3 to 1.3e-2), every expert pick of every layer is the same, and then layer 5 picks another second expert ([3,4] for [3,5]; [3,2] for [3,6]) and its residual is 1.47 / 1.73 apart. On the next step all picks agree again and the logits are back to 1e-2. The first pick and its weight (within 0.2% / 0.7%) agree; for a residual difference of 1e-3 to change the second pick, the second and third candidates' scores must be all but tied (the router's scores themselves were not dumped). Superseded: this tap read the step's row only. With every row's picks and scores read, the prompt's rows already differ (layer 4, row 23: margin 3.2e-5), and the step's router input in layer 5 is 13% apart, not rounding-sized; see below.
  • Why FP16 and not f32: each node rounds its own heads' K and V to FP16 exactly as the single engine does, but the f32 value it rounds differs by summation order (~1e-6 relative). Where that crosses a rounding boundary the stored entry moves by one FP16 step (~5e-4 relative), the same kind of move the format makes everywhere, on few entries: the cluster's FP16 run is a small perturbation of the single engine's FP16 run of the kind FP16 itself is. At f32 KV nothing is rounded and the difference stays at 1e-6.

Every fixture at FP16 and NVFP4 (TensorParallelKvFormatTests, 23 shapes, 700-token prompt and 8 steps, 2 and 3 nodes): the cluster's largest distance from the single engine at the format, as a share of the format's own largest distance from f32 KV on the single engine: qwen3 0.002-0.003, qwen3_5-gdn 0.03, llama-bias 0.03, qwen3_moe 0.005, mixtral 0.04 (FP16); 1e-6 to 8e-3 at NVFP4 (whose own distance from f32 KV on these 16-wide-head fixtures is 0.8 to 5.4); gemma4-moe at FP16 over 2 nodes 0.048. All but gemma4-moe and mixtral at NVFP4 are within the f32 tests' 2e-3 relative anyway. The test holds the cluster to 2e-3 relative plus a tenth of the format's own distance over the run. (It first left gemma4-moe at FP16 over 3 nodes out by name, and later gave node 0 1.25 times its staging so that 2 nodes kept a split without a flip; both are gone: see below for what the test does now. Per step rather than over the run the share reached 1.25 on gemma4-moe over 2 nodes: a step's sensitivity to the two perturbations differs.)

A real model: gemma-4-26b-a4b-nvfp4-gptq, 60 greedy tokens of the chat prompt, exact prefill everywhere (AMQL_GPU_PREFILL=f32), local workers on the one GPU, top logit ~20 per step:

tokens equal top logit, largest / median difference
one engine, FP16 against f32 KV 57 of 60 0.073 / 0.0013
2 nodes against one engine, FP16 KV 60 of 60 0.020 / 0.0008
3 nodes against one engine, FP16 KV 60 of 60 0.005 / 0.0005
2 nodes against one engine, f32 KV 60 of 60 0 / 0 (4 decimals printed)
3 nodes against one engine, f32 KV 60 of 60 0.0001 / 0

The cluster at FP16 is nearer the single engine at FP16 than FP16 is to f32 KV, by 4-15 times.

The near tie, measured: router scores on both engines

The account above was inferred from picks; the router's scores were never read, and the 0.47 on the 2-node split that 1x staging plans had not been looked at. Measured with a temporary, environment-guarded tap (removed; what stayed is the internal GpuEngine.SelectionProbe, below): at every routing of both engines, every row's router input, the scores computed from it and the router's weights on the host as the router kernel computes them, and the picks. Prompt rows and steps, every layer. gemma4-moe, FP16 KV, the test's 700-token prompt, 8 steps, exact prefill, 4,248 routed rows per run (6 layers x 708).

Reproduced: 2 nodes, equal capacities, node 0 given 1x its staging (plan 03fb645c): prompt 0.002, steps 0.12, 0.471, then 0.0015-0.011 (bound 0.0354). 3 nodes with 1.25x staging (1b995c78, the plan the test left out): 0.12, 2.29, then <= 0.011.

Where the engines first pick differently (every layer, every prompt row and step compared; the same on both shapes): no row of layers 0-3 ever picks differently. The first is layer 4, prompt row 23:

expert 3 expert 4 margin (3 minus 4)
single engine 0.1098897 0.1098577 +3.20e-5 (picks [2,3])
2 nodes 0.1098573 0.1098852 -2.79e-5 (picks [2,4])
3 nodes 0.1098527 0.1098776 -2.49e-5 (picks [2,4])

The router input of that row (the residual entering layer 4's FFN) is 1.19e-3 apart over a norm of 12.2 (relative 9.8e-5, largest element 3.5e-4) on 2 nodes, 9.8e-4 on 3; after the router's own norm and scale, |dxs| = 9.8e-5 / 8.2e-5 over 0.94. The perturbation of the margin this implies, (W3 - W4) . dxs from the router's weights and that difference, is -5.99e-5 (2 nodes) / -5.68e-5 (3 nodes): about twice the margin, so the pick swaps. That perturbation is rounding: the largest router-score difference on any row before this one is 2.5e-4 (2 nodes) / 2.4e-4 (3 nodes). 3 nodes also swap layer 4's row 290 (margin 4.0e-5, perturbation 1.1e-4). It is a near tie.

What follows from it: row 23's FFN output changes by the swapped expert, so its keys and values in layer 5 (full attention) do too. Every later prompt row reads them, and layer 5 then picks differently on rows 30, 58 and 118 (and 406, 692 on 3 nodes) with margins of 3e-3 to 3e-2 against score differences of the same size: consequences, not rounding. The steps read those keys and values: their layer-5 router inputs are 13% apart (3 nodes, step 1: |dx| 1.50 over 11.6). On 2 nodes every step picks the same experts as the single engine: the 0.47 is the prompt's changed keys and values, not a pick on that step. On 3 nodes step 1 also picks [3,2] for [3,6] (margin 1.75e-2 against a perturbation of 1.77e-2 from that 13% difference), which takes the gap to 2.29. So the earlier account had the location wrong (not a rounding-sized difference flipping the last layer's pick on the step) and the mechanism right (a near tie).

No defect besides: the cluster given the single engine's picks wherever its own differ (weighted from its own scores), the same runs, and a sweep of splits and prompts (node 0 with 1x its staging; seed 0 is the test's prompt, seeds 1 and 2 are 700 random tokens of the fixture's golden ids). Largest distance from the single engine over the run, own picks / picks held equal, and the rows whose set of picks differed in the run with its own picks (prompt / steps; later ones include consequences of the first):

capacities seed 0 (bound 0.035) seed 1 (bound 0.137) seed 2 (bound 0.407)
1:1 0.471 / 0.0114 (4 / 0) 1.25 / 0.0058 (1 / 1) 0.0071 / 0.0071 (1 / 0)
2:1 0.470 / 0.0065 (7 / 0) 0.0035 / 0.0035 (0 / 0) 0.0126 / 0.0126 (0 / 0)
1:2 0.471 / 0.0107 (4 / 0) 1.25 / 0.0048 (1 / 1) 0.0083 / 0.0083 (1 / 0)
3:1 0.469 / 0.0058 (4 / 0) 0.0045 / 0.0045 (0 / 0) 0.0100 / 0.0100 (0 / 0)
1:1:1 0.471 / 0.0106 (7 / 0) 1.25 / 0.0051 (1 / 1) 0.0053 / 0.0053 (1 / 0)
2:1:1 2.29 / 0.0112 (7 / 1) 1.25 / 0.0057 (1 / 1) 0.0082 / 0.0082 (1 / 0)

Also: 1:1 with 1.25x staging (78db7285, the split the test had been tuned back to) has no differing pick and is 0.0114; 1:1:1 with 1.25x is 2.29 / 0.0112. f32 KV (1:1 and 1:1:1): no differing pick, 2.7e-5 / 3.3e-5. Every first difference is a prompt row in layer 4 with a margin of 1e-5 to 4e-5 against a perturbation of 2e-5 to 1.1e-4 (seed 1: row 591; seed 2: row 638, which moves nothing visible). With the picks held equal every shape is 0.0048-0.0126, the same as the runs where nothing flipped (0.0035-0.0126), under every bound: the only source of the large gaps is the swapped picks. Each forced run still has 2-7 rows whose margin is under twice their own score difference; 0-2 of them swap.

What the test does now (TensorParallelKvFormatTests, 24 shapes, 2 and 3 nodes, node 0 given exactly its staging beside its share, none left out): GpuEngine.SelectionProbe (internal, test-only; every routing's scores and picks, steps run uncaptured while it is set; returned picks replace the engine's own) is set on the single engine and the cluster's coordinator. Each routing of the cluster is matched with the single engine's (in order, per layer; the test fails if the coordinator did not see every routing); where a row's set of picks differs, the cluster is given the single engine's and the row is checked to be a near tie: the single engine's margin between the swapped experts is below the cluster's perturbation of it, and that perturbation is no larger than twice the largest router-score difference on rows where the picks agreed in the same run. Both engines' picks are checked to be the top k of their own scores. The logits are then held to the same bound as before. Run: 24/24; gemma4-moe FP16 2 nodes 0.0114 (1 row given the single engine's picks: layer 4, row 23, margin 3.2e-5, perturbation 6.0e-5), 3 nodes 0.0106 (rows 23 and 290); gemma4-moe NVFP4 3 nodes 5 rows of layer 5 (margins 1.3e-3 to 3.0e-2 against perturbations 5e-3 to 4.2e-2, under twice that run's 3.5e-2 where the picks agreed: NVFP4's one-step moves are larger) and 0.0098; every other shape no differing row. Steps run uncaptured in this test while the probe is set; captured steps are covered by the other tensor-parallel tests.

On a real model: gemma-4-26b-a4b-nvfp4-gptq, FP16 KV (the default), exact prefill on both, a 30-token chat prompt and 200 greedy tokens of the single engine, fed to the cluster (local workers on the one GPU, every layer's experts and the head divided: the coordinator routed all 6,030 routings, 30 layers x 201), picks compared at every routing, nothing forced:

steps with another selection that step logits there: largest / top-token difference other steps: largest (median) / top-token largest (median) argmax differs
2 nodes 1 of 200 (prompt: 0 rows) step 46, layer 27: expert 71 for 2, margin 1.0e-4, perturbation 1.2e-4 0.47 / 0.097 of 22.6 0.077 (0.003) / 0.008 (0.0004) 0 of 201
3 nodes 2 of 200 (prompt: 0 rows) step 26, layer 19: 113 for 65, margin 1.5e-5, perturbation 2.8e-5; step 46 as on 2 nodes (perturbation 2.6e-4) 0.25 / 0.049; 0.47 / 0.100 0.090 (0.004) / 0.018 (0.0008) 0 of 201

The largest router-score difference where the picks agreed was 0.028 / 0.031 (of 128 experts, top 8). So on this model and prompt a near tie swaps one of the 8 experts on 1-2 steps in 200; the logits move by up to 0.47 on those steps (the top token's by 0.1 of ~22), every greedy token is the same (so the free-running greedy text is too), and no prompt row swapped (a 30-token prompt; the fixture's 700-row prompts are where swaps reached later steps through the keys and values). One prompt and 200 tokens: how often a swap changes a token on other text was not measured.

Built: speculative decoding (2026-12-02)

Why it was off. The engine's constructor loaded no MTP layer and no drafter when it had a shard role ("it would need a pass of its own over every node"), so HasDrafter was false, Draft returned nothing and the server reported speculation: false. Beyond that one refusal, three things stood in the way: the coordinator's prefill and verify did not keep the final-normed rows the drafter reads (hidden:) nor catch it up; the MTP layer's lookup and head used _embed and _head directly, which a divided vocabulary leaves partial or null on the coordinator; and the drafter for Gemma 4 (the assistant) is not a model of its own: it reads the keys and values of the model's last sliding and last full layer, which are divided by KV head over the nodes.

What exists.

Piece Where
The MTP layer and the drafter loaded on the coordinator, shaped by the full plan; workers load none GpuEngine.cs (constructor), GpuEngine.Speculation.cs
Lookups for the drafter: the device table, or rows read on the host (the vocabulary work's HostEmbedding), a drafted token read back first (EmbedRows) GpuEngine.Speculation.cs
The MTP layer's head over a divided head: the coordinator's rows, and TpCallKind.DraftHead to the holders of rows below the draft vocabulary (DraftHeadRows, WorkerDraftHead) GpuEngine.Speculation.cs, ShardRole.cs, TpLinks.cs
The coordinator's prefill and verify keep the final-normed rows and catch the drafter up, as one engine does GpuEngine.Shard.cs
The planner: the drafter a fixed piece of node 0 (ShardOptions.DrafterBytes), the mixers a drafter reads whole on node 0 (CoordinatorMixers); both in the join ShardPlanner.cs, ShardPlan.cs, TpCluster.cs, TpNode.cs (TpJoin)
What the drafter costs the coordinator (GpuEngine.DrafterPieces) GpuEngine.Speculation.cs
The server: speculation: true, the load note, TextGenerator.Speculates / SpeculationCounts ModelHost.cs, ServerApp.cs
Tests TensorParallelSpeculationTests.cs, ServerClusterSpeculationTests.cs

Room on the coordinator. The coordinator's capacity is what it gives the cluster (its free device memory less the 1.5 GB reserve, or --tp-capacity); the drafter is planned inside it as a fixed piece, like the norms: its weights as the planner counts any tensor, an MTP layer's own KV cache at the planned context and sequences, and the scratch the engine allocates for drafting (a prompt chunk's final-normed rows, the MTP layer's input, the draft logits, and the wider scratch its layer needs on a coordinator that holds few heads). The coordinator's target share includes it, so it takes that much less of the divided operators; a capacity below the fixed pieces is refused with the drafter named. AMQL_MTP=0 on the coordinator plans none and loads none. On the real models at the CLI's planned context (--tp-plan, f32 KV): the 0.8B's MTP layer with its cache and scratch 0.13 GB, the 4B's 0.42 GB, Gemma's drafter 0.25 GB, beside its layers 28 and 29's attention held whole (the plan prints the drafter X GB among the fixed pieces).

The drafter that reads the model's caches. Its layers attend over the caches of the model's last layer of each kind; those mixers are placed whole on the coordinator by the planner (CoordinatorMixers, first, before any other operator; --tp-plan says "whole on the coordinator: the drafter reads its cache"), so the drafter runs on the coordinator's own caches with no exchange. Those layers' attention then needs no exchange either. The engine loads the drafter only when the plan holds them so.

What crosses the wire. A verify of n rows is one pass with n rows, as before (the head's holders score n rows). An accept and a rewind are one mirrored call each (they were already); the drafter's own state (an MTP layer's cache, the pending hidden state, its mark) lives on the coordinator alone, and each worker keeps what its own rewind needs (its caches, recurrent states, verify snapshots, marks). Drafting adds nothing on the wire unless the MTP layer's head is divided and the coordinator holds fewer than the draft vocabulary's rows (AMQL_MTP_VOCAB, 32,768 by default; the coordinator holds the first rows of the head): then each draft is one DraftHead pass, its normed row out and the holders' logits below the draft vocabulary back. A drafter that reads the caches has its own head and needs none. Prompt rows read on the host for lookups need the tokens there, so a drafted token is read back from the device (a sync) when the table is not on the coordinator's device.

Wire. One new call kind, TpCallKind.DraftHead (value 40, fixed so other kinds added later do not move it), and its data labelled layer -2; two JSON fields in the join (DrafterBytes, CoordinatorMixers, absent or zero without a drafter). A node of an older build is refused at the join anyway (the build is checked), so the magic stayed AMQLTP03 (it is now AMQLTP04, for the refusal codes; see Loose ends). A plan without a drafter keeps its fingerprint.

Deviations from the design. The design calls the drafter its own small model that needs only the refusal lifted; the one this codebase has for Gemma reads two of the model's layers' caches, so those layers' attention is kept whole on the coordinator (a few MB of weights and their cache). Verifies still run uncaptured on a cluster (as before: only steps are captured), which is most of a verify's cost on one GPU (below).

Tests. TensorParallelSpeculationTests (in-process nodes over loopback, exact prefill and f32 KV): an MTP layer (qwen3_5-gdn with one fitted by GenerateMtp) and a drafter that reads the caches (gemma4-moe with the assistant fixture), each over 2 nodes, 3 nodes, and 3 with the head divided and the coordinator holding none of it (its norms, the drafter and the layers it reads; embedding rows on the host, the MTP head's rows from both workers). For each: greedy replies of 48 tokens after a short prompt and one of two chunks, drafting 1, 3 and 7 a step, equal to the cluster's plain replies and the single engine's; the same drafts as the single engine after a prompt, rejected drafts (a corrupted last row every verify), accepts of 1 to 5 rows and a rewind; the drafter's logits (Gemma's) and every verify row's within 2e-3 (largest 1.6e-5 to 1.0e-4); a batch of three stepped together, then one of them verified and drafting again. The fixtures' drafters are poor (0 to 2 drafts in ~50 held), so the replies are mostly rejections; the partial accepts are forced. The planner (CPU): the drafter in the fixed pieces and the fingerprint, the layers it reads whole on node 0, the plan's JSON and a worker's join giving the same fingerprint, refusals. ServerClusterSpeculationTests: a chat model with an MTP layer across two in-process servers reports speculation: true, speculates when a reply runs alone (149 speculative steps over four replies, as many as the local server's) and gives the local server's greedy replies alone and eight at once. Each class run alone after the change: TensorParallelTests 53, TensorParallelGpuTests 23, TensorParallelVocabularyTests 14, SpeculativeDecodingTests 6, ServerClusterTests 3, MtpTests 3, GpuEngineTests 42, KvPagingTests 13, ServerModelRegistryTests 17, ClusterOperationsTests 4, all passing.

Real models (RTX 5090, bench --draft 3 --steps 256 --chat "Explain in a short paragraph why the sky is blue, then list three facts about Mars.", AMQL_GPU_PREFILL=f32 AMQL_KV_FORMAT=f32; a cluster is --tp-local 0, its worker a second process on the same GPU over loopback TCP). Every row: 256 of 256 tokens as plain decode, and the plain reply's token hash the single engine's (0.8B d8109a2450caac13, 4B c8c808734f83229d, 26B 657db5e15d1cacdb). Drafts kept are identical on one engine and on the cluster, draft for draft.

Model plain 1 draft 2 drafts 3 drafts auto best gain kept (1 / 2 / 3)
qwen3.5-0.8b one engine 697 800 814 698 760 1.17x 63 / 52 / 43%
2 nodes 44.1 63.4 76.5 79.0 64.8 1.79x the same
2 nodes, coordinator 0.3 GB (head rows on the worker: each draft a DraftHead pass) 47.5 65.5 74.4 79.1 68.6 1.67x the same
qwen3.5-4b one engine 175 269 286 274 285 1.63x 78 / 57 / 47%
2 nodes 27.5 40.2 46.7 49.2 48.1 1.79x the same
3 nodes 26.1 40.3 43.6 44.5 45.9 1.76x the same
gemma-4-26b-a4b-nvfp4-gptq (drafter) one engine 272 327 364 321 325 1.34x 61 / 69 / 52%
2 nodes 30.8 41.6 53.9 53.1 43.6 1.75x the same

(tok/s.) It pays on one GPU, more than on one engine: a cluster's step is bound by its round trips (two exchanges a layer, 350-500 µs each), and a verify of n rows is the same round trips with n rows, so every draft held is nearly a free token. A verify costs a plain step and a little more (the 4B over 2 nodes: 38.4 ms for one row against 36 ms a captured step; 46 ms for four rows); drafting is 0.3-0.5 ms a draft on the coordinator, 1 ms when the MTP head's rows come over the links and the drafted token is read back for a lookup on the host. A rejected draft costs only its row in the verify and the accept's mirrored call. The pace the server uses (auto, at most four, cut at a 45% chance) is tuned for one engine, where a row costs more than on a cluster; on a cluster a fixed 2 or 3 drafts does better (0.8B 79 against 65, 26B 54 against 44): a cluster's pace is not tuned here.

With KV paging across nodes (after merging main ae44068). The coordinator's page is the single engine's own save over its engine, so with the drafter loaded it carries the drafter's state as one engine's save does: an MTP layer's cache, its pending hidden state and whether it had kept up; a drafter that reads the caches keeps nothing of its own but reads layers the coordinator holds whole, which are in the coordinator's page. A page is good only on the formation that saved it, and a formation with the drafter has another plan (the drafter is in the fingerprint) and another mark geometry (mtp… against mtp-), so a page saved without the drafter is refused on a formation with it and the reverse, by name ("the mark was saved on another formation of the cluster"), before anything changes. TensorParallelSpeculationTests.A_Paged_Mark_Carries_The_Drafter_And_Speculates_On_As_Unpaged (MTP layer and Gemma's drafter, 2 nodes): saved after a 40-token prompt, the sequence speculates on, the mark is restored and the unpaged sequence rewound, and both take the rest of the prompt and 8 speculative cycles: the drafts equal (and one engine's restored mark's), the logits bit for bit for the MTP model (Gemma's fixture has windows of 4, whose restored caches start at another row: within 2e-3, as TensorParallelPagingTests holds windows), one engine's within 2e-3. The pages hold 174,775 and 61,912 bytes against one engine's marks of 174,352 and 61,456 (the drafter's state is there; the rest is each page's header).

Device bytes. A sequence's DeviceBytes on a cluster counts every node (the paging work); the coordinator's part, counted as on one engine, now includes the drafter's per-sequence memory: an MTP layer's cache and its two hidden states (already counted for an engine with one), and the one hidden state of a drafter that reads the caches (now counted on every engine, distributed or not; it was missing). The test above checks a cluster sequence's bytes equal one engine's, drafter included; the server's KV budget reads DeviceBytes.

The draft pace on a cluster is left as it is. A fixed 2 or 3 drafts beat auto on the cluster here, but measured per row the costs are alike on both: a verify row beyond the first costs ~0.07-0.08 of a step on one engine (4B: a verify of 5.70 ms with no drafts, 7.02 ms with three, of a 5.7 ms step) and on two nodes (38.4 → 46.3 ms of a 36 ms step), while a draft costs ~0.07 of a step on one engine and ~0.013 on the cluster. What differs is the cost of drafting, and the pace's cut (verify a draft only at ≥45% chance) is not derived from either cost; a rule that derived it would change one engine's speculation too, which was tuned on real replies and is held unchanged by this work. Left for a measured change of its own.

The plan prints it. --tp-plan (with any --tp-divide) and the server's GET …/cluster (plan_text, and DrafterBytes/CoordinatorMixers in plan) show the drafter among the fixed pieces and the layers held whole for it, e.g. the 26B: "fixed on node 0: 0.27 GB (norms, routers, the drafter 0.25 GB)" and layers 28 and 29 "whole on the coordinator: the drafter reads its cache"; with --tp-divide none, "fixed on node 0: 0.67 GB (embedding, head, norms, the drafter 0.25 GB)" and the same two layers (ServerClusterSpeculationTests checks the route).

After the merge (main ae44068 into this work, 2a37e40), each class alone: TensorParallelTests 53, TensorParallelGpuTests 23, TensorParallelVocabularyTests 14, TensorParallelSpeculationTests 10, TensorParallelPagingTests 16, TpPagesTests 1, TensorParallelKvFormatTests 23, SpeculativeDecodingTests 6, MtpTests 3, ServerClusterTests 4, ServerClusterSpeculationTests 1, ClusterOperationsTests 4, ClusterProcessTests 3, KvPagingTests 13, KvFormatTests 13, GpuEngineTests 42, ServerModelRegistryTests 17, all passing. The local path, ae44068 / the merged build / ae44068 again: the same four checksums; decode best of 5, 0.8B 675.4 / 669.5 / 665.7, 4B 171.3 / 170.9 / 170.9; batches of 1/2/4/8, 0.8B 690/1276/1888/1748, 682/1274/1886/1755, 684/1271/1882/1758; 4B 173.4/322.7/577.0/693.4, 173.0/321.9/576.5/692.4, 172.7/321.0/576.7/694.3; profiled step 0.8B 2.75 / 2.79 / 2.66 ms, 4B 6.65 / 6.65 / 6.63 ms; the 4B speculating on one engine (3 drafts) 309.9 / 310.7 / 310.8 tok/s, 55% of drafts kept each time.

The local path (scripts/tp-local-path-check.sh, the base c6a029c built from its own tree, this build, the base again): the same four checksums every time (61903d9638b2ebf0, 0ba346f870114499 decode; ce620150700a31e1, 70918af478f94c89 profiled). Decode best of 5: 0.8B 673.1 / 671.9 / 672.4, 4B 171.4 / 171.4 / 171.3; batches of 1/2/4/8: 0.8B 688/1275/1889/1730, 688/1266/1884/1754, 684/1266/1884/1750; 4B 173.0/321.9/575.8/693.2, 173.7/322.9/577.4/693.0, 173.6/323.1/575.3/693.8; profiled step 0.8B 2.67 / 2.71 / 2.70 ms, 4B 6.63 / 6.64 / 6.65 ms. Speculation on one engine (the 4B's MTP layer, bench --draft 3, defaults): plain 173.9 / 173.1 / 173.6, 3 drafts 311.6 / 311.9 / 309.9 tok/s, the same drafts kept (55%) and 256 of 256 tokens each time. The local path's code changes are a null check before the MTP layer's and the drafter's lookup and before the MTP head (the same calls with the same arguments).

Built: indexed attention by head (2026-12-02)

First, the single engine. Block-sparse attention now runs on the device engine (gpu-performance.md, Block-sparse attention): amql_sparse.cu, a translation unit of its own, with selection (amqe_index_prep, amqe_index_select) and attention (amqe_block_attention) as separate launches and the block list ([rows × topK] int32) an explicit buffer between them. The local path's launches did not change (scripts/tp-local-path-check.sh, base 3f143f3 then this build then the base again: checksums 61903d9638b2ebf0 / ce620150700a31e1 (0.8B) and 0ba346f870114499 / 70918af478f94c89 (4B) everywhere; decode 640-671 / 642-669 / 640-667 tok/s on the 0.8B and 167-171 / 169-170 / 167-171 on the 4B; batches 1/2/4/8 within 1.2% of the base's two runs).

The division, as the design says:

Piece Where
ShardDivisions.IndexedAttention: an attention with an indexer divides by KV heads (…, blocks selected on the coordinator); its projection, norms and per-sequence rows (planned context and sequences) are node 0's fixed pieces. WholeAttentionReason(attn) without options still answers "a sparse indexer" (training's question), and so does a plan without the flag ShardPlanner.cs
ShardPlan.SelectsOnCoordinator(layer, full) ShardPlan.cs
TpWire.SideBytes makes room for the block lists, TpWire.BlockListBytes TpTransport.cs
The coordinator uploads the indexer of such a layer whatever heads it holds (ShardUploadIndexer), runs it before the mixer exchange, sends the lists after the input rows, and attends with its own heads (if any) under them; a worker copies them from its inbox and runs its heads' KV prep and amqe_block_attention; it holds no indexer and keeps no indexer rows GpuEngine.Indexed.cs, GpuEngine.Shard.cs

The slicer needed no change: a node's attention keeps the indexer's geometry (Heads copies it), and the engine reads it for the attention while uploading nothing of it on a holder. Only the coordinator grows, forks and pages indexer rows (in its own part of a saved mark).

Checks (TensorParallelIndexedTests, in-process nodes over loopback TCP, exact prefill, f32 KV, against the single engine; tolerance 2e-3 of the largest logit): the plan divides only where allowed and counts the indexer on node 0; qwen3 with indexers over 2 nodes 1.3e-6, 3 nodes (one holding no head of each layer) 1.1e-6, the coordinator holding no head at all (0.3:1:1, every layer's heads on the workers, the coordinator selecting for them) 1.1e-6, uneven 3:1 1.1e-6, whole on a node (ShardDivisions.None, the indexer with it) 1.2e-6, qwen3_5-gdn (output gate split per head, linear attention by key head beside) over 2 nodes 9.3e-6 — each over prompts of 5 and 700 tokens (two chunks, most blocks dropped), 6 steps across block boundaries, mark and rewind, a 4-row verify across a block boundary and accepting 2, a fork, a batch of 3, a mark saved to every node's pages and restored (bit-equal to the live sequence). FP16 KV over 2 and 3 nodes: 1.6e-4 and 3.7e-4 from the single engine at FP16 (FP16 itself 5.6e-3 from f32; bound 1.2e-2); NVFP4: 6.4e-6 and 4.5e-6 (bound 0.39). After the change: TensorParallelTests 67, TensorParallelGpuTests 24, …KvFormatTests 23, …PagingTests 16, …SpeculationTests 10, …VocabularyTests 14, TrainTensorParallel* 52, ServerClusterTests 4, GpuEngineTests 42, KvPagingTests 13, GpuBatchTests 10, ArchZooTests 93, Qwen4ExpTests 11: all pass.

Limits. No checkpoint on this machine has indexed attention the device engine can run: the Qwen4 family's also carry a multi-stream gated residual and the n-gram embedding, which it refuses; the checks run on arch-zoo fixtures with indexers added, and the speed on Qwen3.5-0.8B with a random one. Dividing it in training is not done (training passes ShardDivisions.None). Not measured across real nodes.

Operating a cluster: start order, recovery, the manager and the GUI (design, 2026-12-02)

A cluster must survive being started in any order and a node being restarted, without anybody calling the API again and without any process exiting. The rule is desired state: a model that was asked to be loaded across nodes stays wanted until someone unloads it or removes its distribution, and the coordinator keeps trying to bring it to that state.

The coordinator

  • A distributed model never fails the start. If its nodes cannot be reached, refuse, or lack room when the server starts (or when the model is loaded), the model goes to the state waiting with the reason, and the server carries on serving everything else.
  • Retry: while a model is wanted and not formed, the coordinator tries again in the background: 1 s, doubling to 30 s, with jitter; a change in any node's reachability (the probe below, run with each attempt) is logged once, not every attempt. A request for a waiting model gets 503 model_waiting_for_cluster with Retry-After and the reason; it does not block for the retry.
  • A cluster that ends (a node lost or restarted, a pass failed) fails the requests in flight as now, frees every shard it can reach, and puts the model back to waiting: the same retry forms it again when every node is back. No request is needed to trigger it.
  • Refusals that cannot heal by waiting (another build, a container that differs, a key the node does not hold) are retried at the 30 s rate and reported as such, since an operator may fix the node; they never stop the server.
  • Explicit actions end the wanting: unload, delete, or removing the distribution. POST /v1/models/{id}/cluster/retry tries now.

The member

  • A restarted node holds nothing and needs nothing but its listen address and key (its start settings); it is joined again by the coordinator's retry.
  • A join for a model from a coordinator replaces a membership the node still holds for the same model from that coordinator's previous life (the old link is dead or silent): the old shard is freed first. A restarted coordinator therefore does not have to wait out the 60 s silence.
  • A shard that cannot load (no room after making room) refuses the join; nothing on the node stops.

Nothing crashes

Every cluster thread (links, heartbeats, the node's accept loop, a worker's run loop, the retry) contains its failures: they end that cluster or membership and are logged with the node named. Tests kill and restart each side at each point (while idle, mid-prefill, mid-step, during a join, during a shard load) and assert the surviving process serves its other models throughout and the model returns without intervention.

Settings that survive a restart

Models and distributions given in --config are there at every start. Those made at run time (a model added, a distribution set, loaded or not) are written to the server's state file when it has one (--state <file>; the manager gives each server one) and applied at the next start, after the config. Keys are never written to the state file; a key comes from the start settings.

What the API reports

  • GET /v1/models/{id}: state gains waiting; cluster gives state (forming, ready, waiting), attempts, next_attempt_in_s, last_error, since, and per node address, state (ready, lost, unreachable, refused, failed), error, capacity, bytes.
  • POST /v1/cluster/probe {"nodes": [...], "key_name"?, "container"?}: for each node, without joining: reachable, key_ok, version, same_build, device, free_bytes, has_container, error.
  • POST /v1/models/{id}/cluster/plan with a distribution: the shard plan it would get (JSON and text, bytes per node) and the probe's result, changing nothing.

The manager and the service

The manager's configuration gives a host its cluster settings (listen address, the key by reference to a protected file or the environment, capacity) and a model its distribution; it passes them to the servers it runs, gives each a state file, and reports each model's cluster state in its own API. The service installers (scripts/service/install-windows.ps1, install-linux.sh) take the listen address and key, store the key readable only by the service account, and print the firewall rule the cluster port needs (they add it only when asked with a switch). A server the supervisor restarts (a crash, an update) comes back into its clusters by the rules above.

The GUI

In the server page (the window and the terminal view):

  • Servers: a saved list of other AMQL servers (name, address); each shows reachable, build, device, free memory (the probe).
  • Run across servers: on a model: tick servers, optionally give capacities and a context, see the plan (bytes per node, what divides, what is whole) and any problem per node before applying; Apply sets the distribution and loads. Defaults need no typing beyond the ticks.
  • Status: each distributed model shows its state, per-node state and bytes, and while waiting the reason and the time to the next attempt; actions: retry now, run locally again (remove the distribution), unload.
  • This server: accept cluster joins (listen address), the key (set, never shown), capacity.

Built in AMQL Studio's Server page and its terminal twin; how to use it: AMQL Studio.

Built (2026-12-02, everything above but the GUI)

  • Coordinator (ModelRegistry): the state waiting; a distributed model is wanted from its first load until unload, delete or the distribution's removal; background retry 1 s doubling to 30 s, ±20% jitter, a refusal that cannot heal at 30 s at once (ClusterException.Lasting: another build, container or key, no key here, a model that cannot batch); each attempt probes the nodes first and forms only when all are reachable and accept; reasons and reachability logged on change. A request for a waiting model: 503 model_waiting_for_cluster with Retry-After. An ended cluster frees what it can and goes back to waiting. POST …/cluster/retry; POST …/load on a waiting model tries now. A distributed model never stops the start; the node endpoint now opens before the models load.

  • Member (TpNode): a join replaces a membership with the same lineage (TpJoin.Lineage, the server's --cluster-name, default machine name and --urls), model id, proved key name and link address (the node's own socket's view, Link.Remote, new in Amql.Cluster); the old shard is freed (its run loop is stopped) before the new one loads, or the join is refused after 30 s. The key is proved before this runs, and the address cannot be claimed, so a coordinator elsewhere holding the key cannot evict another's membership. It does not wait to see the old link silent: a live coordinator with the same lineage on the same host is a misconfiguration (two servers given one --cluster-name), and the two would take the membership from each other.

  • Probe (TpProbe, TpQuery.Probe): hello, key both ways, a query marked as a probe, answered with an offer carrying build, device, free and total memory and whether the container resolves; nothing joined. A node no longer logs a coordinator that asks and goes (a probe, a plan) as a failure.

  • Containment: every free in a member's thread is separate and contained; a cluster's Ended handlers, the links' fault callback and watch timer, and the retry can no longer throw out of a pool thread.

  • State file (ServerStateFile, --state), the routes (POST /v1/cluster/probe, POST …/cluster/plan, cluster in GET /v1/models/{id}), the manager (cluster in manager.json, cluster/cluster_node on a model, ServerLaunch: state file per server, key in the environment, a node-only server when no model takes the port, cluster state in /v1/manage/models) and the installers as in server.md and manager.md.

  • A request that reaches a cluster in the moment between a node's death and the coordinator noticing it (the links are watched every second) gets 503 cluster_failed with Retry-After: 1, not a 500; the cluster then ends and the model waits as above.

Deviations, as settled with the GUI: cluster.state is unloaded (or unloading) for a model that is not wanted; cluster adds refused; per-node entries keep the distribution's nodes array (with node, state, error, bytes) and node_states stays, deprecated; the probe adds capacity, state and build, takes key, and its container is a model id or a folder; the plan answers {plan, plan_text, nodes[{address, node, bytes, capacity, error}], probe, error} and is also POST /v1/cluster/plan for an unlisted container; retry answers 202 at once. A refusal was first classified from the engine's own words; it is now classified by a code on the wire (see Refusal codes).

Loose ends (2026-12-02)

Measured on the one RTX 5090, every node a process (--tp-local), 2026-12-02; before is c6a029c built from its own tree.

Tests and the local path after all of it. Each class alone: TensorParallelTests 67, TensorParallelVocabularyTests 14, TensorParallelGpuTests 24, ServerClusterTests 3, ClusterOperationsTests 13, ClusterProcessTests 4, ServerModelRegistryTests 17, GpuEngineTests 42, every Train* class 183: all pass. scripts/tp-local-path-check.sh, c6a029c / this build / c6a029c: the same four checksums every time (61903d9638b2ebf0, 0ba346f870114499 decode; ce620150700a31e1, 70918af478f94c89 profiled); decode best of 5: 0.8B 670.5 / 662.0 / 668.7 tok/s (runs 650.7-670.5 across all three), 4B 171.5 / 171.6 / 171.2; batches of 1/2/4/8: 0.8B 683/1279/1886/1740, 689/1269/1894/1755, 686/1282/1893/1751; 4B 173.6/321.8/578.3/692.8, 173.0/320.9/580.0/693.4, 173.7/322.4/580.7/693.4.

After merging main 7d90dad (KV paging and speculative decoding across nodes): each class alone, TensorParallelTests 67, TensorParallelGpuTests 24, TensorParallelVocabularyTests 14, TensorParallelSpeculationTests 10, TensorParallelPagingTests 16, TpPagesTests 1, TensorParallelKvFormatTests 23, SpeculativeDecodingTests 6, MtpTests 3, ServerClusterTests 4, ServerClusterSpeculationTests 1, ClusterOperationsTests 13, ClusterProcessTests 4, KvPagingTests 13, KvFormatTests 13, GpuEngineTests 42, ServerModelRegistryTests 17, ManagerClusterTests 4, StudioClusterTests 22, every Train* class 183: all pass. The local path, main 7d90dad / the merge / main: the same four checksums; decode best of 5 0.8B 670.3 / 666.8 / 668.4, 4B 171.5 / 172.0 / 171.5 tok/s; batches of 1/2/4/8 0.8B 688/1272/1900/1767, 689/1273/1903/1772, 686/1276/1887/1765; 4B 173.8/323.0/577.5/689.7, 173.3/322.1/579.2/691.0, 173.0/322.6/577.8/692.3. scripts/tp-check.ps1 on the merge (defaults; greedy 60 of the chat prompt against the single engine at its defaults; bench pp64 / tg128 best of 3):

Model Nodes Greedy Top logit Formed Bytes by node pp64 / tg128 tok/s
qwen3.5-4b 2 60/60 0.022 11.6 s (loads 5.8 s and 5.1 s, the first cluster after the single engine's read) 4.56 / 4.56 GB 543 / 34.3
3 60/60 0.071 4.4 s 3.05 / 3.04 / 3.04 GB 338 / 26.1
gemma-4-26b-a4b-nvfp4-gptq 2 57/60 0.34 5.1 s 7.60 / 7.60 GB 410 / 32.7
3 57/60 0.34 5.6 s 5.07 / 5.07 / 5.07 GB 206 / 25.2

The 26B's 57/60 is the comparison described under Measured: the cluster defaults to exact prefill for 4-bit weights and the single engine here ran at its own default (BF16 prompt GEMMs), which diverge from token 57. scripts/cluster-memory-check.ps1 -Cycles 3, as committed, ran and wrote its curve (managed after GC 134 MiB after the first form, 264-280 MiB after; native buffers, threads and handles flat).

Column slices gathered on the device

Cause. With AMQL_LOAD_TIMING=1 and a count added around the gathers, the 3-node qwen3.5-4b (generate --tp-local 0,0, three runs each): every node's column slices (64 tensors: the attention and linear-attention output projections and the FFN downs) read 2.18 GB of stored rows a block at a time on the building thread, one read in flight, and cut them on the host: 3.0 s of node 0's 4.0-4.3 s load and 3.8-4.8 s of each worker's 6.4-6.8 s; the 2.8 GB of row slices read straight to the device were already done by then (0.00 s waiting). The coordinator loads its own shard after the workers' joins, so the cluster formed in 11.5-11.8 s (before: 11.5, 11.5, 11.8 s). It is not the division by head: --tp-divide none (1.68 GB of column gathers) formed in 10.2-10.7 s. Reading the rows through the page cache instead (so three processes on one machine read the drive once) was slower: page faults held each worker to ~0.25 GB/s (formed in 14.1-15.2 s).

Fix. A column slice whose segment reads directly and whose destination is device memory (WeightLoader.DeviceColumns): the whole stored tensor is read straight into a device buffer of its own (the storage engine's direct read, left in flight with the engine's other reads), then each range's columns are copied into the allocation by a pitched device-to-device copy (cuMemcpy2DAsync, new in GpuStream), and the buffer is freed. The bytes are moved, not computed, so the device holds what the host gather wrote; the buffers in flight are held to 512 MiB together. BF16 and raw NVFP4/MXFP4 (elements and scales) take it; f32, FP8 and patched tensors keep the managed path, and a host destination the host gather (with AMQL_TP_HOST_GATHER=1 every column slice does, to compare). No CPU work is added: the copies are on the device.

After. Shard loads 2.2-2.4 s on the workers and 1.2-1.9 s on node 0; formed in 4.3, 4.3, 4.9 s (before 11.5-11.8). Each node still reads its column-sliced tensors whole (2.18 GB here), now at the direct read's rate. Test: TensorParallelGpuTests.Column_Slices_Gathered_On_The_Device_Are_The_Host_Gathers_Bytes (BF16, NVFP4 and MXFP4 elements and scales, one column range and three: the device's bytes equal the host gather's, byte for byte).

The 3-node prompt speed with experts folded

Not reproduced as a regression. gemma-4-26b-a4b-nvfp4-gptq over --tp-local 0,0, AMQL_GPU_PREFILL=bf16 (the setting of the 161-175 figure), bench pp64 / tg128 best of 3: c6a029c (folded) gave pp64 177.9, 229.9 and 262.3 tok/s in the three runs of one bench, best 262; this build 225-228, best 228; then, interleaved, before (this build without the change below) 260.6 and 304.1, after 281.9 and 291.8, and with AMQL_TP_TIMING=1 303.0 and 296.8. The runs of one bench differ by up to half, so 161-175 against 221 was the shared GPU's noise, not the folding. The host sync is real: with AMQL_TP_TIMING=1 (which now times the experts' call on the host, "experts call on the host") a prompt's call holds the host 0.4-0.5 ms on the coordinator and 0.7-0.8 ms on a worker on average (first calls included), mostly waiting for the queued work to drain so the grouping's counts can size the GEMMs. Launching a worker's experts before its dense FFN, so that wait would not cover the FFN, changed nothing measurable (above: the "after" runs) and was not kept; removing the wait needs the GEMM table built on the device, a native change. Exactness was checked for that reorder: the GPU tests now print a checksum of every cluster logit row they compare (cluster logits checksum), equal before and after on all 19 cluster shapes, and 60 greedy tokens of the 26B gave the same printed logits.

The coordinator's host memory over form/end cycles

Not a leak: it plateaus. scripts/cluster-memory-check.ps1 runs A (coordinator of qwen3.5-0.8b over B) and B (a node) as two amql-server processes, kills and restarts B 30 times (each time x goes to waiting, forms again and answers a request), then deletes and puts x's distribution 30 times. A test hook, AMQL_TEST_MEMORY_LOG_SECONDS (TestMemoryLog; no route), has A write every 2 s its working set, private bytes, managed heap after a forced full collection, the native buffers Amql.Cluster holds by kind (NativeBuffer.Live, new: counts and bytes of the buffers allocated and not freed), threads and handles; the last line after each cycle is kept.

After Working set, MiB Private, MiB Managed after GC, MiB Pinned buffers Host buffers Threads Handles
the first form 1,070 2,148 134 3 (138.5 MiB) 5 (259.0 MiB) 125 947
restart 1 1,235 2,321 264 the same the same 125 988
restarts 2-30 1,238-1,355 2,301-2,471 248-296 the same the same 117-125 972-992
redistributions 1-30 1,357-1,438 2,475-2,554 264-297 the same the same 119-123 977-1,002

The first cycle adds a step (+165 MiB working set, +130 MiB managed: something built once, at the first end or re-form, and then reused), and switching to delete/put another (+~100 MiB working set); within each phase the figures wander and do not climb (private bytes 1.6 MiB a cycle by a least-squares line over the restarts, inside a 170 MiB spread; 0.2 MiB a cycle over the redistributions). The managed heap after a full collection stays 248-297 MiB from the second cycle on, the cluster's native buffers (link and staging buffers) are the same three pinned and five host buffers after every cycle, and threads and handles do not grow. The reported 1,098 → 1,268 MiB over five restarts is the first cycle's step plus that wander. What the one-time 130 MiB of managed memory is was not identified.

A kill that lands mid-load

The tiny test model loads at once, so ClusterProcessTests' "killed during a join" never landed in a shard load. A test hook, AMQL_TEST_SHARD_LOAD_DELAY_MS (read only by a node's join, TpNode.ShardLoadDelay; not a setting), holds a join open that many milliseconds after the shard is on the device and before the node answers; the node logs tp: shard loaded; the join's answer waits … ms when it does. The process test now starts B with the hook, waits for that line, checks A's cluster.state is forming (the join unanswered), kills B, and asserts A stays up and serves its local model, x goes to waiting, and x forms when B returns (without the hook). A new test, A_Join_Whose_Coordinator_Dies_Mid_Load_Frees_What_It_Loaded, does the other side with qwen3.5-0.8b (a shard large enough to see; skipped when the container is absent): B holds its loaded shard, A is killed, and B's membership must go and the card's used memory return to within 256 MiB of B idle (B notices at its answer, when the hook's wait ends). Measured in that test: 3,889 MiB with B idle, 6,148 MiB with A up and B's shard (1,452 MiB planned) loaded and held, 3,888 MiB after A was killed. The class's device figures now come from nvidia-smi (the card, every process): the CUDA runtime's free memory as the test process saw it did not move when the servers allocated (it read 1,754 MiB idle, formed and formed again), so the class's earlier memory checks could not fail; they pass with the card's figures (formed 4,690 MiB, formed again after a coordinator restart 4,688, A gone 3,888 = idle). All four ClusterProcessTests pass.

Replies compared by token ids

The test model's replies decode mostly to U+FFFD (byte-level pieces alone), so comparing their text compared little. The chat route now takes return_tokens_as_token_ids (as vLLM has it) with logprobs: every logprob's token is token_id:N. ServerClusterTests, ClusterOperationsTests and ClusterProcessTests ask for it and compare replies as their token ids (ServerClusterTests.TokenIds), asserting there are some.

A plan ends politely

[worker 1] tp: … peer closed the connection during --tp-plan was noise from a build before c9bd6d5: a node then logged every conversation that ended on a dropped link, and a plan only asks (hello, key, query, offer) and closes. Since c9bd6d5 a node that answered a query and then loses the link returns without a word; the message did not appear in 14 plan runs (generate --tp-plan: qwen3.5-0.8b over --tp-local 0,0 five times on c6a029c and three on this work's build, qwen3.5-4b over 0 and gemma-4-26b-a4b-nvfp4-gptq over 0,0 three times each on c6a029c). Nothing was closed uncleanly: the node's thread frees its control channel and link either way. The close is now explicit as well: a coordinator that only asked (a plan, TpCluster.PlanAsync; a probe, TpProbe) sends TpMessage.Done before it closes the link (best effort, two seconds), and the node ends the conversation on it rather than on the dropped link. Test: TensorParallelTests.A_Plan_Or_A_Probe_Ends_Politely_And_The_Node_Says_Nothing (three plans and three probes, nothing in the node's log, no membership).

The coordinator's staging buffers, counted

ShardSettle allocates, on the coordinator's device, a buffer of a prompt chunk's rows × hidden × 4 bytes for each worker partial of an operator beyond the first (one less than the most worker holders of any operator), and where a layer's dense FFN and experts fold into one exchange a second scratch and a second set. The planner counted none of them (it counts no activations or scratch at all, so there was no counted scratch to take them from). They are now counted in node 0's fixed bytes (ShardPlanner.StagingBytes): ExchangeBytes × (nodes − 2), plus (nodes − 1) more when experts may fold (divided experts beside a dense FFN in any layer): the most there can be, from the node count, the model and the options alone, so the coordinator and every node's join (which both set ShardOptions.ExchangeBytes from the chunk rows and hidden size the join already carries) plan the same and their fingerprints agree. Training never sets ExchangeBytes (zero counts none), so its plans are unchanged; the Train* tests pass as they were. Sizes: 5 MiB a buffer for the 4B (512 rows × 2,560); the 3-node 4B's plan moved by one unit (node 1 2.92 GB, was 2.91). With the head divided, an untied embedding goes to node 0's device only when it fits within node 0's target beside its fixed bytes, the staging included. On the test fixtures (hidden sizes of 64 or so) the buffers are as large as the weights, so the GPU tests now give node 0 its staging on top of its share, and two shapes changed to keep what they test: the small node of the experts' 1:1:0.15 is now 1:1:0.1 (so it still holds none of some layer's experts), and the vocabulary tests' small coordinator gets 1.5 times its fixed bytes beyond its share. Test: TensorParallelTests.The_Coordinators_Staging_Buffers_Are_Counted_On_Node_0 (2, 3 and 5 nodes; with experts beside a dense FFN; training's options count none).

With the drafter merged (main 7d90dad), node 0's fixed pieces are the norms (and routers), the drafter (DrafterBytes) and the staging buffers (ShardPlan.StagingBytes, carried in the plan's JSON beside DrafterBytes, not in the fingerprint); the untied embedding goes to node 0's device only when it fits beside all of them, and Describe and the "fixed pieces exceed node 0" refusal name both ("norms, routers, the drafter … GB, staging buffers … GB"). The tests merged with them that size node 0 from its fixed bytes give it its staging on top: TensorParallelSpeculationTests (the drafter's clusters; the "none" variant's node 0 is its fixed pieces, the drafter's mixers and the staging), TensorParallelPagingTests (every rig; "none" likewise) and TensorParallelKvFormatTests, whose coordinator gets 1.25 times its staging beside its share: with just the staging, gemma4-moe at FP16 over 2 nodes planned another split, on which the logits were 0.47 from the single engine against a bound of 0.035 (main's split passes; whether this one is a near tie between experts, as its summary describes for 3 nodes, was not examined), and 1.25 times gives back the split it tested before, checked by fingerprint (78db7285…). No shape changed in these three. (Since replaced: the 0.47 is a near tie in a prompt row's pick, measured with the router's scores, and the KV format test now holds the expert selection equal and checks each difference is a near tie, with node 0 given exactly its staging; see the near tie, measured.)

Refusal codes

A refusal carries a code beside its text (TpRefusal: other build, container differs, graph differs, settings differ, key, no room, already member, plan differs, other) in a new setting-up message, TpMessage.Refusal (an int32 code, then the text, UTF-8); TpException.Refusal carries it to the caller, and TpClusterBackend.Classify decides "cannot heal by waiting" from the code alone (TpException.Lasting: other build, container, graph, settings, key, plan) or the failure's type (an unsupported model, a broken container), no longer from the words (LastingMarks is gone). The messages are unchanged. Because the payload changed, the magic is now AMQLTP04: a peer of AMQLTP03 would read the new refusal's code as four bytes of text. The only refusal still sent as text alone (TpMessage.Refuse) is the hello of another protocol, so an older peer can read why; a new peer that receives one reads it as another build (a probe then reports same_build: false). Old and new nodes therefore meet only at the hello, and each says why it refuses in words the other can read. A node-side failure that is not a refusal (a shard that fails to load, say) is Other and is retried at the usual rate; before, a node's "cannot run this model" counted as lasting by its words (the coordinator refuses such a model itself before any join, so nothing reaches a node that way). Tests: TensorParallelTests (every code through the wire, a hello of AMQLTP03 answered in text) and ClusterOperationsTests.A_Refusal_Is_Lasting_By_Its_Code_Not_Its_Words.

Not in the first version

Finding nodes automatically (addresses are given to the API; the key decides who may be joined); encrypted links; dividing routed experts and linear attention inside a layer; visit plans; CPU inference workers; weights streamed to a node without the container; a shared-memory link for local workers; half-precision activations on the wire; capturing prefills and verifies between exchanges.