Repository navigation
feat(metrics): time each reply's tokens, so a dashboard can show TPOT - #367
Closed
juliankang4 wants to merge 1 commit into
Closed
juliankang4 wants to merge 1 commit into
juliankang4 wants to merge 1 commit into
Conversation
request_time_per_output_token_seconds observes each finished reply's time from its first generated token to its last, by the server's clock, over its tokens less one: vLLM's decode_time / (num_generation_tokens - 1). The CUDA server stamps the latest arrival in Request.saw(), the Mac server in metrics.tokens(), so a reply cut by a stop string, a disconnect or a tool-call gate is timed on the tokens it returned, even where both ranks decode on to max_tokens. A one-token reply has no gap and adds no sample (vLLM records 0). Its buckets run from 2.5 ms to 1 s, below the request histograms' first edge.
6 of 8 tasks
ashhart
added a commit
that referenced
this pull request
Oct 6, 2026
…367, #407) /metrics gains four readings. request_time_per_output_token_seconds (vLLM's TPOT) is, for each finished reply, the server's time from its first generated token to its last over its tokens less one, in buckets from 2.5 ms to 1 s; a one-token reply adds no sample. generation_tokens_running counts what live replies have generated so far, from a snapshot the engine thread takes between rounds, so a scrape never reads a stream the engine is changing. decode_rounds_total counts the rounds finished replies used. request_prefill_seconds, repeated as vLLM's request_prefill_time_seconds, is each finished reply's prompt pass as the engine measured it, from the job's start to the end of its prefill. The reply's tensorfold.prefill_seconds now reports that same span, so it no longer includes time spent waiting for a lane. The cached-prompt counter stays out until an engine counts kept-prefix hits. Tests: the TPOT arithmetic, the bucket a sample lands in, and render() through a stub engine (the new families present, no cached family). The scripted test engine reports a prefill span, and the server parity check lists the four /metrics cases as expected differences, since the Python server does not have these families. Co-authored-by: juliankang4 <[email protected]> Co-authored-by: MiaAI-Lab <[email protected]>
Owner
|
Thank you, @juliankang4. This landed in the Zig engine as 8debb38, with your credit.
The Python engine is frozen (#286), so this PR closes with that. Timing on the server's clock rather than the engine's decode time was the right call. |
Closed
grearjake-star
added a commit
to grearjake-star/TensorFold
that referenced
this pull request
Oct 8, 2026
… tokens, rounds, prefill time /health reported figures that /metrics left out, so a Prometheus scraper had to poll /health beside it and parse JSON. /metrics now carries generation_tokens_running (the running replies' tokens so far), prompt_tokens_cached_total (prompt tokens read from a kept prompt state), decode_rounds_total, request_prefill_seconds (mirrored as vLLM's request_prefill_time_seconds) and, where the engine has a limit to read, requests_running_max. A family the server cannot count is left out, never sent as zero. Merged beside this tree's TPOT histogram (ashhart#367); the macOS footprint gauge stays out with the Mac server. Observability only. Upstream: ashhart#407, closed unmerged with the Python engine frozen; the maintainer landed the same families in the Zig server. Co-authored-by: MiaAI-Lab <[email protected]>
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
…shhart#367, ashhart#407) /metrics gains four readings. request_time_per_output_token_seconds (vLLM's TPOT) is, for each finished reply, the server's time from its first generated token to its last over its tokens less one, in buckets from 2.5 ms to 1 s; a one-token reply adds no sample. generation_tokens_running counts what live replies have generated so far, from a snapshot the engine thread takes between rounds, so a scrape never reads a stream the engine is changing. decode_rounds_total counts the rounds finished replies used. request_prefill_seconds, repeated as vLLM's request_prefill_time_seconds, is each finished reply's prompt pass as the engine measured it, from the job's start to the end of its prefill. The reply's tensorfold.prefill_seconds now reports that same span, so it no longer includes time spent waiting for a lane. The cached-prompt counter stays out until an engine counts kept-prefix hits. Tests: the TPOT arithmetic, the bucket a sample lands in, and render() through a stub engine (the new families present, no cached family). The scripted test engine reports a prefill span, and the server parity check lists the four /metrics cases as expected differences, since the Python server does not have these families. Co-authored-by: juliankang4 <[email protected]> Co-authored-by: MiaAI-Lab <[email protected]>
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.
What this changes
/metricsgetsrequest_time_per_output_token_seconds, a per-request TPOT histogram under the name vLLM uses for it. Each finished reply adds the time from its first generated token to its last, by the server's clock, divided by its tokens less one. That is vLLM'sdecode_time / (num_generation_tokens - 1), wheredecode_time = last_token_ts - first_token_ts(vllm/v1/metrics/stats.py). A dashboard built for vLLM can then show TPOT p50/p95 for TensorFold with the usual prefix swap. Today that panel stays empty:request_decode_secondshas one sample per request, so it can't give a per-token quantile.I watch my GB10 boxes with a dashboard of my own (Spark Scope) that reads vLLM, SGLang and TensorFold. TensorFold is the only one of the three where TPOT reads "unknown". With this branch it fills in without any change on the dashboard side. I checked that against a live server.
How it works:
Request.saw()after every round's tokens land inout. It now also keeps the time of the latest arrival and how many tokens had landed by then. On the Mac server,metrics.tokens()runs for every chunk and now keeps the latest time too. Both handmetrics.tpot(first, last, count)tonote().decode_sbecause of two ranks. There, rank 0 decodes on tomax_tokensor EOS after a stop string or a disconnect (on_tokensis wrapped to return False), whileoutstops growing.decode_s / (len(out) - 1)would then read far too high: a stop after 20 of 2048 tokens comes out about 100x. With arrival times, a reply is timed on the tokens it actually returned. A token the server appends itself, such as a tool-call gate's fix-up, has no arrival time and isn't counted. Waiting inside a reply, such as a continuation's prompt pass or a yielded lane, counts as part of the gap, as it does in vLLM.request_decode_secondsstill uses the engine's figure and is unchanged.docs/api.mdnotes the difference.Histogramtakes its edges as an argument, defaulting toBUCKETS, so the request histograms render exactly as before. TPOT gets its own edges, from 2.5 ms to 1 s. With this Nemotron checkpoint on a GB10, replies run at 4.9 to 7.4 ms a token, and all of them would land in a first bucket at 10 ms.request_decode_seconds. Liketime_to_first_token_seconds, it already carries vLLM's name, so it is a single family with no twin.Receipt
Environment:
609ca41) plus this commit.lmsysorg/sglang:v0.5.21image that was already on the box rather thannvcr.io/nvidia/pytorch:26.07-py3. The GPU clock is locked at 2000 MHz on my machines, so the absolute tok/s is a bit below stock.TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit@d9d758fb83953437f7263256b0d96157e2a348b8, one rank, MTP drafts on.prism-ml/Ternary-Bonsai-2-27B-mlx-2bit@fcba37d2117a7077eac6b613b2668d14d9779edd, without the DFlash2 drafter, so context copies only. Nemotron doesn't fit a 32 GB Mac: it needs 22.8 GiB for the model and one prompt chunk, against MLX's 22.0 GiB share even atTENSORFOLD_MEMORY_LIMIT_GB=25.Exactness:
tools/bench_concurrent.py --alone --serialat 4 streams, temperature 1.0 and 0. Every concurrent reply equalled its solo run (48/48), every solo run checked equalled"draft": false(10/10), and nothing failed. The server log also shows 10 replies produced both from a fresh prompt (cached=0) and from a resumed one, with the samesha=each time."draft": false, nothing failed.Decode speed before and after:
tools/bench_openai.py --tokens 256 --reps 5, median tok/s, main then this branch, one run each way in the same session:The temperature 0 rows are the ones to read: each run sits within about 1% of the others. The change adds a timestamp per round and one division per finished reply. I didn't alternate the runs.
Prompt speed before and after:
tools/prefill_cold.py, 3 reps each. The server's window is 16,880 tokens, so I ran the 2k, 8k and 16k prompts and dropped 32k and 64k (the tool's summary then stops on the missing lengths, after printing these):The histogram against a client clock: 12 streamed requests of 256 tokens, chat and completion, temperature 0 and 1.0, one at a time. Around each one I scraped
/metricsand compared the family's sum delta with the client's (last token time - first token time) / (tokens - 1).max_tokens1 request added no sample, amax_tokens2 request added one, and a reply that a"\n\n"stop cut at one token added none."def "stop cut a reply at 173 tokens: 87.618 ms on the server against 86.559 ms on the client. I think the gap is the tokens that matched the stop string. They arrive at the server but are never sent, so the client's clock stops at the last text it was shown./metricsand/v1/metricsreturned identical text.Tests run:
M4 Pro, full host suite: 4669 passed, 929 skipped, 0 failed.
M5, full host suite: 4972 passed, 617 skipped, 9 failed. All nine fail the same way on main on the same machine: eight in
test_lane_fuse.py(AttributeError: 'list' object has no attribute 'shape') andtest_glm5_prompt_kernels.py::test_fused_index_scores_are_the_three_ops. They are kernel tests on the M5's lane path, nowhere near the metrics code. I can open a separate issue for them.GB10, in the container:
test_metrics.py,test_metrics_footprint_host.py,test_health_memory.pyand the sixtest_cuda_server_*.pyfiles gave 257 passed, 2 skipped, 1 failed. The failure istest_health_memory.py::test_health_reports_the_budget_and_the_process_footprint, aKeyError: 'footprint'. It fails the same way on main, because the test expects the macOS footprint on Linux. I left it alone as a separate fix.On main, four tests in the new
test_metrics.pyfail:decode_sstaying out of it;All four pass here.
Not run, and why:
cuda/health.py, and touches no kernel or engine.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.