feat: in-process paged KV serving-role handoff mechanism#187
Merged
Conversation
Add the in-process building block for disaggregated serving-role KV handoff (#126 step B1): the seam that joins the #125 paged KV serde layer to the transport layer, which previously never referenced each other in production. New `distributed::disaggregated::handoff_impl`: - `extract_sequence_handoff` serializes a finished pool-backed sequence (dense metadata, paged block table, and the referenced pool block contents) into a single wire frame. - `ingest_sequence_handoff` validates an incoming frame, allocates a fresh pool-backed sequence, and reconstructs its KV onto local pool blocks anchored to the decode model's real block geometry, releasing the slot on restore failure so a rejected handoff leaks nothing. - `probe_block_geometry` derives the decode model's exact (n_kv_heads, head_dim, dtype) with a one-token probe through a throwaway pool-backed sequence. This captures the runtime KV dtype (e.g. bf16 for a 4-bit checkpoint, not fp16), which no static model accessor exposes, with no per-model code. - `send_handoff_payload` / `recv_handoff_payload` move a frame over any `Transport` as a tagged message (the async serde/transport bridge). `BatchScheduler` gains thin `extract_sequence_handoff` / `ingest_sequence_handoff` hooks plus a probe-once geometry cache. They are additive: a live caller (the serving-role serve loop) lands in a later step, matching the additive-then-wired pattern used across this epic. Verified byte-identical to a single-node run for qwen3 and llama3 over the full prefill-extract, transport, probe, decode-ingest path (`tests/paged_handoff_parity.rs`, requires the test-utils feature), plus in-crate transport bridge round-trip and rejection tests. The synchronous scaffolding `HandoffProtocol` trait is intentionally left untouched: it predates the async `Transport` and would force a `block_on`, so the async byte bridge here is the primitive the real serve loop should build on. Part of #126
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In-process building block for disaggregated serving-role KV handoff (#126 step B1). This wires the #125 paged KV serde layer to the transport layer, which previously never referenced each other in production, and proves the mechanism byte-identical against real models.
What it adds
New
distributed::disaggregated::handoff_impl:extract_sequence_handoff(prefill side) serializes a finished pool-backed sequence (dense metadata, paged block table, and the referenced pool block contents) into a single wire frame.ingest_sequence_handoff(decode side) validates an incoming frame, allocates a fresh pool-backed sequence, and reconstructs its KV onto local pool blocks anchored to the decode model's real block geometry, releasing the slot on restore failure so a rejected handoff leaks nothing.probe_block_geometryderives the decode model's exact(n_kv_heads, head_dim, dtype)with a one-token probe through a throwaway pool-backed sequence. This captures the runtime KV dtype (bf16 for a 4-bit checkpoint, not fp16), which no static model accessor exposes, with no per-model code.send_handoff_payload/recv_handoff_payloadmove a frame over anyTransportas a tagged message (the async serde/transport bridge).BatchSchedulergains thinextract_sequence_handoff/ingest_sequence_handoffhooks plus a probe-once geometry cache. These are additive (#[allow(dead_code)]): the live caller, a serving-role serve loop, lands in a later step, matching the additive-then-wired pattern used across this epic.Verification
Orchestrator-local (Metal cannot run on CI runners):
tests/paged_handoff_parity.rs(requirestest-utils): qwen3-0.6b (28 layers) and llama3-1b (16 layers) over the full prefill-extract, MockTransport wire, probe, decode-ingest path produce a byte-identical 16-token decode versus a single-node run.handoff_impl_tests.rs: transport bridge round-trip plus two rejection paths.clippy -D warnings(metal,accelerate, with and withouttest-utils) andfmtclean.Correctness rests on #125's proven serialize/restore path plus the
Some(geometry)anchor, which only rejects a mismatch and does not alter a valid restore.Design notes
HandoffProtocoltrait is synchronous andPrefillHandoff-shaped, which fights the asyncTransport(it would force ablock_on) and only covers the send half. The async byte bridge here is the primitive the real serve loop should build on.Part of #126