Skip to content

feat: serving-role KV handoff scheduler entries (B2b) - #189

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-126-b2b-serving-role-driver
Jun 9, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-126-b2b-serving-role-driver

Conversation

@inureyes

@inureyes inureyes commented Jun 9, 2026

Copy link
Copy Markdown
Member

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 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. 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_tx are 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 same execute_decode_step + finalize_completed the hot loop calls.
  • serde: SerializableCacheState gains generated_tokens (serde default, frame-cap bounded) so the decode node seeds from the first token. ingest_sequence_handoff is 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 because BatchScheduler is pub(crate); #[ignore] + soft-skip). On qwen3-0.6b-4bit: prefill-role extract -> ServingCoordinator pair over MockTransport -> decode-role ingest -> decode == single-node scheduler run, 16 tokens byte-identical.

  • cold clippy -D warnings clean (metal,accelerate and +test-utils, --all-targets)
  • 379 batch / serde / disaggregated unit tests pass; rustfmt clean

Scope boundary (B2 vs B3)

This delivers and proves the serving-role handoff mechanism. The live wiring (flipping the worker's --node-role branch to spawn a role coordinator + the run_*_role drive loops) folds into B3 with the real cross-process transport: the in-process MockTransport connects 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.

inureyes added 3 commits June 9, 2026 15:00
…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.
@inureyes
inureyes merged commit b68e4f4 into main Jun 9, 2026
4 checks passed
@inureyes
inureyes deleted the feature/issue-126-b2b-serving-role-driver branch June 9, 2026 06:38
@inureyes inureyes self-assigned this Jun 10, 2026
@inureyes inureyes added status:done Completed type:enhancement New features, capabilities, or significant additions priority:medium Medium priority labels Jun 10, 2026
@inureyes inureyes added this to the 0.2 milestone Jun 21, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant