Repository navigation
feat: serving-role KV handoff scheduler entries (B2b) - #189
Merged
Merged
Conversation
…entry Part of #126 (epic #116), B2b foundation. The serde layer now carries the prefill node's first sampled token across the handoff, and the scheduler gains the prefill-role extract entry. The decode-role entry, the coordinator role loops, the worker serving-mode branch, and the in-crate real-model E2E follow; this increment compiles and passes the serde/handoff unit tests, but the end-to-end prefill -> handoff -> decode parity is verified by the (pending) B2c test. - SerializableCacheState gains `generated_tokens` (serde default, bounded by the existing frame cap). extract_sequence_handoff injects it before serializing so a decode node seeds its continuation from the first token. serialize_cache_pool_sequence / serialize_sequence_cache_set signatures stay the same (default-empty), so their callers are untouched. - BatchScheduler::prefill_request_for_handoff (option C, reuse then extract): drives the standard execute_full_prefill path verbatim (identical first-token sampling, structured output, thinking budget, logprobs), then lifts the finished sequence out of the active batch before any local decode, extracts its pool-backed KV, and releases the local caches. The hot run() loop is untouched; speculative burst and chunked-prefill handoff are out of scope here. Verified: cold clippy -D warnings clean (metal,accelerate and +test-utils, --all-targets); 47 serde/handoff/coordinator unit tests pass; rustfmt clean.
Part of #126 (epic #116), B2b. Adds the decode-side scheduler entry points that complement the prefill-role extract, plus a deserialize-once split so the decode node reuses the parsed handoff for both the paged restore and the request context. Compiles and is cold-clippy clean; end-to-end prefill -> handoff -> decode parity is verified by the (next) in-crate real-model B2c test. - handoff_impl: split ingest into a bytes entry and a pre-deserialized-state entry (ingest_sequence_handoff_state), so a scheduler that also needs the handoff's prompt history and generated tokens does not parse the frame twice. - BatchScheduler::ensure_handoff_geometry factors the probe-once geometry out of the ingest hook (shared by both ingest paths). - BatchScheduler::ingest_handoff_as_active: reconstruct the handed-off KV onto a fresh pool slot and register it as a live decode sequence in the active batch, seeded with the prefill node's generated token(s); max_tokens, sampling, and the response channel are coordination parameters from the decode node's request layer (the KV frame carries cache + prompt history + generated tokens). - BatchScheduler::decode_handoff_until_idle: drive the active batch to completion reusing the same execute_decode_step + finalize_completed the hot run() loop calls, without touching run(). Verified: cold clippy -D warnings clean (metal,accelerate, --all-targets); lib and tests compile; rustfmt clean.
Part of #126 (epic #116), B2c. Verifies the BatchScheduler serving-role entries end to end against a real model: a request is prefilled through prefill_request_for_handoff, the frame is shipped over an in-process ServingCoordinator pair (MockTransport), reconstructed with ingest_handoff_as_active, and decoded. The decode token ids are byte-identical to a single-node run of the same prompt through the same scheduler. In-crate because BatchScheduler is pub(crate) and cannot be constructed from an integration test (same constraint as tests/paged_scheduler_parity.rs). #[ignore] + soft-skip when the model is absent. Result on qwen3-0.6b-4bit (M1 Ultra): handoff decode == single-node, 16 tokens byte-identical. Verified: cold clippy -D warnings clean (metal,accelerate and +test-utils, --all-targets); 379 batch/serde/disaggregated unit tests pass; rustfmt clean.
This was referenced Jun 9, 2026
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
* feat: handoff carries the prefill first token + prefill-role extract entry Part of lablup#126 (epic lablup#116), B2b foundation. The serde layer now carries the prefill node's first sampled token across the handoff, and the scheduler gains the prefill-role extract entry. The decode-role entry, the coordinator role loops, the worker serving-mode branch, and the in-crate real-model E2E follow; this increment compiles and passes the serde/handoff unit tests, but the end-to-end prefill -> handoff -> decode parity is verified by the (pending) B2c test. - SerializableCacheState gains `generated_tokens` (serde default, bounded by the existing frame cap). extract_sequence_handoff injects it before serializing so a decode node seeds its continuation from the first token. serialize_cache_pool_sequence / serialize_sequence_cache_set signatures stay the same (default-empty), so their callers are untouched. - BatchScheduler::prefill_request_for_handoff (option C, reuse then extract): drives the standard execute_full_prefill path verbatim (identical first-token sampling, structured output, thinking budget, logprobs), then lifts the finished sequence out of the active batch before any local decode, extracts its pool-backed KV, and releases the local caches. The hot run() loop is untouched; speculative burst and chunked-prefill handoff are out of scope here. Verified: cold clippy -D warnings clean (metal,accelerate and +test-utils, --all-targets); 47 serde/handoff/coordinator unit tests pass; rustfmt clean. * feat: decode-role ingest entry and decode drive for serving-role handoff Part of lablup#126 (epic lablup#116), B2b. Adds the decode-side scheduler entry points that complement the prefill-role extract, plus a deserialize-once split so the decode node reuses the parsed handoff for both the paged restore and the request context. Compiles and is cold-clippy clean; end-to-end prefill -> handoff -> decode parity is verified by the (next) in-crate real-model B2c test. - handoff_impl: split ingest into a bytes entry and a pre-deserialized-state entry (ingest_sequence_handoff_state), so a scheduler that also needs the handoff's prompt history and generated tokens does not parse the frame twice. - BatchScheduler::ensure_handoff_geometry factors the probe-once geometry out of the ingest hook (shared by both ingest paths). - BatchScheduler::ingest_handoff_as_active: reconstruct the handed-off KV onto a fresh pool slot and register it as a live decode sequence in the active batch, seeded with the prefill node's generated token(s); max_tokens, sampling, and the response channel are coordination parameters from the decode node's request layer (the KV frame carries cache + prompt history + generated tokens). - BatchScheduler::decode_handoff_until_idle: drive the active batch to completion reusing the same execute_decode_step + finalize_completed the hot run() loop calls, without touching run(). Verified: cold clippy -D warnings clean (metal,accelerate, --all-targets); lib and tests compile; rustfmt clean. * test: in-crate real-model parity for serving-role handoff (B2c) Part of lablup#126 (epic lablup#116), B2c. Verifies the BatchScheduler serving-role entries end to end against a real model: a request is prefilled through prefill_request_for_handoff, the frame is shipped over an in-process ServingCoordinator pair (MockTransport), reconstructed with ingest_handoff_as_active, and decoded. The decode token ids are byte-identical to a single-node run of the same prompt through the same scheduler. In-crate because BatchScheduler is pub(crate) and cannot be constructed from an integration test (same constraint as tests/paged_scheduler_parity.rs). #[ignore] + soft-skip when the model is absent. Result on qwen3-0.6b-4bit (M1 Ultra): handoff decode == single-node, 16 tokens byte-identical. Verified: cold clippy -D warnings clean (metal,accelerate and +test-utils, --all-targets); 379 batch/serde/disaggregated unit tests pass; rustfmt clean.
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.
Part of #126 (epic #116). B2b of the disaggregated serving productionization: the BatchScheduler serving-role driver entry points that turn the in-process handoff mechanism (B1) into a scheduler-level prefill -> handoff -> decode path, with the hot
run()loop untouched. Real-model verified byte-identical to a single-node run.What
prefill_request_for_handoff(option C, "reuse then extract"): drives the standardexecute_full_prefillpath verbatim (identical first-token sampling, structured output, thinking budget, logprobs), then lifts the finished sequence out of the active batch before any local decode, extracts its pool-backed KV, and releases the local caches. Speculative burst is bypassed and chunked-prefill handoff is deferred.ingest_handoff_as_active: reconstructs the handed-off KV onto a fresh pool slot and registers it as a live decode sequence, seeded with the prefill node's generated token(s).max_tokens/sampling/response_txare coordination parameters from the decode node's request layer; the KV frame carries the cache, prompt history, and generated tokens.decode_handoff_until_idle: drives the active batch to completion reusing the sameexecute_decode_step+finalize_completedthe hot loop calls.SerializableCacheStategainsgenerated_tokens(serde default, frame-cap bounded) so the decode node seeds from the first token.ingest_sequence_handoffis split into a bytes entry and a pre-deserialized-state entry so the decode node parses the frame once.Verified (B2c)
In-crate real-model parity test (
serving_handoff_parity_tests.rs, in-crate becauseBatchSchedulerispub(crate);#[ignore]+ soft-skip). On qwen3-0.6b-4bit: prefill-role extract ->ServingCoordinatorpair over MockTransport -> decode-role ingest -> decode == single-node scheduler run, 16 tokens byte-identical.-D warningsclean (metal,accelerate and +test-utils, --all-targets)Scope boundary (B2 vs B3)
This delivers and proves the serving-role handoff mechanism. The live wiring (flipping the worker's
--node-rolebranch to spawn a role coordinator + therun_*_roledrive loops) folds into B3 with the real cross-process transport: the in-processMockTransportconnects two roles only within one process, so a per-process role coordinator needs B3's TCP transport + routing to connect. The B2a dormant worker branch stays dormant (and serving) until then. New entry points are#[allow(dead_code)]until B3 wires the live caller.