Skip to content

feat(server): serve per-request inference metrics under --enable-metr… - #504

Open
FantasticCode2019 wants to merge 1 commit into
FlashML-org:mainfrom
FantasticCode2019:feat/per-request-metrics
Open

FantasticCode2019 wants to merge 1 commit into
FlashML-org:mainfrom
FantasticCode2019:feat/per-request-metrics

Conversation

@FantasticCode2019

Copy link
Copy Markdown

…ics-report

  • the scheduler measures the prefill span itself (admission to the token sampled off the request's last prefill chunk) and ships it as a duration on that token's DetokenizeMsg: it is the one boundary a client timing SSE frames cannot see, and a duration keeps the wire free of any cross-process clock assumption
  • the remaining timings come off the raw ack stream, not the emitted GenEvents: a reasoning or tool-call parser holds text back, sometimes to the end of the stream, so an event-timed TTFT runs long, and acks are the one path the streaming and buffered generators share
  • cached_prompt_tokens reports the real prefix-cache hit whether or not --enable-cache-report is set; that flag governs the billing fields in usage, and gating the hit here would leave prefill_tokens_per_second computed over tokens that were never forwarded
  • decode_tokens_per_second divides by decode_tokens - 1, as vLLM's and sglang's serving benchmarks do: the first token falls out of prefill and spans no decode interval
  • served on /v1/chat/completions, /v1/messages and /v1/responses; /v1/completions does not go through the shared generation core and is left out

Closes #503

…ics-report

- the scheduler measures the prefill span itself (admission to the token sampled off the request's last prefill chunk) and ships it as a duration on that token's DetokenizeMsg: it is the one boundary a client timing SSE frames cannot see, and a duration keeps the wire free of any cross-process clock assumption
- the remaining timings come off the raw ack stream, not the emitted GenEvents: a reasoning or tool-call parser holds text back, sometimes to the end of the stream, so an event-timed TTFT runs long, and acks are the one path the streaming and buffered generators share
- cached_prompt_tokens reports the real prefix-cache hit whether or not --enable-cache-report is set; that flag governs the billing fields in usage, and gating the hit here would leave prefill_tokens_per_second computed over tokens that were never forwarded
- decode_tokens_per_second divides by decode_tokens - 1, as vLLM's and sglang's serving benchmarks do: the first token falls out of prefill and spans no decode interval
- served on /v1/chat/completions, /v1/messages and /v1/responses; /v1/completions does not go through the shared generation core and is left out

Closes FlashML-org#503
JUNQINGV587 added a commit to JUNQINGV587/FreeToken that referenced this pull request Sep 23, 2026
…-enable-metrics-report

Conflict resolution keeps both sides: our reply fields (moe_stats / mm_stats / host_tier_stats on the detokenize messages, logprobs on the choices) plus their prefill_ms plumbing, and the chat completion body keeps our logprobs-carrying choice while taking their response dict so the metrics object can be attached.

The new _prefill_start map and the ack.prefill_ms read reach every fake in the tree, so three test doubles gained the attribute: the two stubs in test_hybrid_cache_manager.py, the scheduler stub in test_abort_inflight_prefill.py and the ack builder in test_stream_cancellation.py. tests/server + tests/scheduler + tests/tokenizer: 1190 passed, 9 skipped.
gdevenyi added a commit to gdevenyi/FreeToken that referenced this pull request Sep 24, 2026
…ics under --enable-metrics

# Conflicts:
#	python/freetoken/scheduler/scheduler.py
#	python/freetoken/server/generation.py
#	python/freetoken/server/openai_api.py
gdevenyi added a commit to gdevenyi/FreeToken that referenced this pull request Sep 24, 2026
…etrics timing reads

Upstream FlashML-org#504 times the prefill span in Scheduler._prefill_start; the stubs from FlashML-org#222 and
FlashML-org#505's tests build the scheduler without it.

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
…ference metrics under --enable-metrics-report

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
…stub its prefill-start map

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
…nize endpoint for client-side token counting

Conflict: the generation import list gained build_metrics on main (FlashML-org#504) and
count_prompt_tokens here; kept both.

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
…ams and rebuild timeout at the API layer

Conflict: next added the metrics-report tests (FlashML-org#504) where this PR adds the
sampling-validation tests; kept both.

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
…livery on stream cancellation

Conflict: next's stream_with_cancellation already sends SSE keepalives while a
stream is silent (6e63b8f); kept that loop and moved the abort into the
finally, as this PR does, so it goes out however the stream dies. The PR's
ack stub gained next's prefill_ms field (FlashML-org#504).

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
…gprobs for chat and legacy completions

Conflicts, all kept on both sides:
- sampler: next's penalties (FlashML-org#527) and greedy mask (FlashML-org#471) next to the logprob
  rows; prepare() passes both, sample() keeps the greedy-mask path and the
  PR's compute_logprobs reads the raw logits.
- SamplingParams / ChatCompletionRequest: penalty fields stay as on next
  (None = model default); the logprobs fields are added.
- openai_api: next's default thinking mode and _resolve_sampling feed the
  logprobs fields; the legacy completions drain keeps FlashML-org#222's disconnect
  watch and collects the logprob entries.
- engine/scheduler/detokenizer/generation: next's MoE stats (FlashML-org#231) and
  metrics timings (FlashML-org#504) beside the logprob plumbing.

Assisted-by: Claude Opus 5.5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Expose per-request inference performance metrics in /v1/chat/completions

1 participant