Repository navigation
Description
Problem
The disaggregated router (src/server/router_front.rs) derives completion_tokens (and the chat equivalent) by counting emitted text frames: one increment per ResultFrame text entry in the per-request on_token callback. This equals the worker's true generated-token count for byte-level-BPE tokenizers (e.g. Qwen), but can UNDER-COUNT for byte-fallback tokenizers (e.g. Gemma, which emit multi-frame <0xXX> byte sequences for a single token, or where one model token maps to multiple emitted text pieces).
Because finish_reason is computed as completion_tokens >= max_tokens ? "length" : "stop" (matching src/server/model_worker.rs ~line 1401), an under-count can also flip the reported finish_reason between "length" and "stop", and makes the router's usage diverge from the single-node /v1/completions and /v1/chat/completions responses for those tokenizers.
Scope / why it is a separate issue
PR #386 intentionally kept byte-identity for byte-level-BPE tokenizers (validated via the disaggregated_router_completions_match_single_node E2E test on qwen3-0.6b-4bit) and documented this limitation rather than expanding scope. A correct fix requires extending the disaggregated serving wire protocol to carry the worker's authoritative generated-token count (and likely the worker-computed finish_reason) from the decode node to the router, which touches src/distributed/disaggregated/serving_protocol.rs plus both the prefill and decode emit paths and the router demux. That is a protocol change, separate from the byte-parity feature PR (one PR, one logical change).
Proposed direction
Add the worker's true generated-token count (and optionally its finish_reason) to the result/serving protocol frames, and have the router use those authoritative values for usage.completion_tokens / finish_reason instead of frame-counting. Then extend the E2E parity test to a byte-fallback tokenizer (e.g. a small Gemma checkpoint) to assert usage + finish_reason parity with single-node.
Acceptance Criteria
- The router's
usage.completion_tokensandfinish_reasonfor/v1/completionsand/v1/chat/completionsmatch single-node for a byte-fallback tokenizer (e.g. Gemma), not just byte-level-BPE. - The disaggregated wire protocol carries the worker's authoritative token count.
- An E2E test asserts the parity on a byte-fallback tokenizer.
References
- Surfaced in PR feat(server): add /v1/completions to the disaggregated router #386 review (issue Disaggregated router: add the /v1/completions endpoint #200).
- Counting site and "Parity notes" are in
src/server/router_front.rs::route_completion. - Protocol:
src/distributed/disaggregated/serving_protocol.rs. - finish_reason:
src/server/model_worker.rs.
Activity
fix(router): use worker's authoritative token count for usage (#392)
test(router): cover the chat streaming include_usage default gate
fix(router): emit usage on the disaggregated /v1/chat/completions res…
fix(router): use worker's authoritative token count for usage (lablup…
fix(router): emit usage on the disaggregated /v1/chat/completions res…