server: emit GPU ttft/generation/decode_tps in stream usage - #570
Conversation
Measure decode on the batch-engine worker around forward_token (excluding SSE backpressure) and expose timings on the final chat.completion usage chunk so UIs can show accurate tok/s without client-side wall-clock math.
71ba1e3 to
c10c9a9
Compare
skyrocket2026
left a comment
There was a problem hiding this comment.
Review
Nice additive change — streaming usage with ttft_ms / generation_ms / decode_tps is the right shape for the chat UI, and measuring around forward_token (before on_token) correctly excludes SSE backpressure.
Blocker: last_timing_ is racy under continuous batching
ModelEngine::complete_streaming writes last_timing_ after the job finishes, then sparkinfer_server reads engine.last_timing() on a later line. httplib serves concurrent requests and the batch engine interleaves them, so this can happen:
- Request A finishes → sets
last_timing_ - Request B finishes → overwrites
last_timing_ - Request A’s handler reads
last_timing()→ B’s timings
Worse: if the stolen values are >= 0, the per-request wall-clock fallback in sparkinfer_server.cpp is skipped, so the UI can show another session’s tok/s.
last_timing() also returns an unlocked reference (unlike last_error() which takes mu_).
Suggested fix: return timings with the completion result (extend the return of complete_streaming, or an out-param / pair), and use that local value in the stream handler. Avoid a process-global “last timing” side channel.
Non-blocking notes
- Non-stream
/v1/chat/completionsstill emits standard usage only (fine if intentional). - Single-token completions fall back to wall-clock decode_tps (
decode_forwards == 0); OK. - Prefill seed token correctly excluded from
decode_forwards(decode tok/s after first token).
Please fix the timing handoff, then this looks good to merge.
|
Maintainer |
Closed — RTX 5090 checkbox not tickedThis PR was auto-closed because the template includes Tested on RTX 5090 as To submit for review:
If this PR does not need GPU eval (e.g. docs-only), remove the proof-of-speedup section from the description instead of leaving an unchecked box. Automated by eval bot / rtx5090-required CI. |
|
closed |
|
Reopened + |
Summary
forward_token(excluding SSE/network backpressure).ttft_ms,generation_ms, anddecode_tpson the final streamingusagechunk so UIs (e.g. sparkinfer-web) can show accurate tok/s.prompt_tokens/completion_tokens/total_tokensunchanged.Pipeline impact
steady_clocksample around each decode forward.kMaxOutputTokensat the upstream default (4096); deployment max-out remains an init/CLI concern.Test plan
sparkinfer_serverand stream a short chat; confirm usage includesdecode_tps/ttft_ms/generation_msbench_api_vs_native.py)/v1/chat/completionsstill returns standard usage