Skip to content

feat(metrics): time each reply's tokens, so a dashboard can show TPOT - #367

Closed
juliankang4 wants to merge 1 commit into
ashhart:mainfrom
juliankang4:request-tpot-histogram
Closed

juliankang4 wants to merge 1 commit into
ashhart:mainfrom
juliankang4:request-tpot-histogram

Conversation

@juliankang4

Copy link
Copy Markdown
Contributor

What this changes

/metrics gets request_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's decode_time / (num_generation_tokens - 1), where decode_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_seconds has 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:

  • The CUDA server already calls Request.saw() after every round's tokens land in out. 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 hand metrics.tpot(first, last, count) to note().
  • I used the server's clock rather than the engine's decode_s because of two ranks. There, rank 0 decodes on to max_tokens or EOS after a stop string or a disconnect (on_tokens is wrapped to return False), while out stops 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_seconds still uses the engine's figure and is unchanged.
  • A one-token reply has no gap and adds no sample. vLLM records 0 there. Leaving it out keeps short replies from pulling p50 down. docs/api.md notes the difference.
  • Histogram takes its edges as an argument, defaulting to BUCKETS, 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.
  • The family sits next to request_decode_seconds. Like time_to_first_token_seconds, it already carries vLLM's name, so it is a single family with no twin.

Receipt

  • Environment:

    • TensorFold 0.6.5 (609ca41) plus this commit.
    • CUDA: one GB10 (DGX Spark class), driver 595.84, CUDA 13.0, PyTorch 2.13.0+cu130, Triton 3.7.1. I ran it in the lmsysorg/sglang:v0.5.21 image that was already on the box rather than nvcr.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.
    • Mac: M4 Pro (24 GB) and M5 (32 GB), MLX 0.32.3, Python 3.12.
    • Checkpoints:
      • GB10: TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit @ d9d758fb83953437f7263256b0d96157e2a348b8, one rank, MTP drafts on.
      • M5: 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 at TENSORFOLD_MEMORY_LIMIT_GB=25.
  • Exactness:

    • GB10: tools/bench_concurrent.py --alone --serial at 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 same sha= each time.
    • M5: the same command, where the four streams share each round: 48/48 equal to solo, 10/10 equal to "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:

    Prompt Temperature main this branch
    fibonacci-raw 1.0 203.3 200.3
    gpu-chat-no-think 1.0 139.8 141.2
    fibonacci-raw 0 200.7 199.9
    gpu-chat-no-think 0 146.3 146.5

    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):

    Prompt tokens main tok/s (TTFT) this branch tok/s (TTFT)
    2,048 6,660 (0.307 s) 6,656 (0.308 s)
    8,192 6,531 (1.254 s) 6,544 (1.252 s)
    16,384 6,228 (2.631 s) 6,216 (2.636 s)
  • 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 /metrics and compared the family's sum delta with the client's (last token time - first token time) / (tokens - 1).

    • GB10: per request the server value was 0.9997 to 1.0002 of the client's. The median was 6.705 ms on both.
    • M5: 1.0000 on all 12. The median was 87.735 ms on both.
    • A max_tokens 1 request added no sample, a max_tokens 2 request added one, and a reply that a "\n\n" stop cut at one token added none.
    • On the M5, a "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.
    • On the GB10, /metrics and /v1/metrics returned 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') and test_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.py and the six test_cuda_server_*.py files gave 257 passed, 2 skipped, 1 failed. The failure is test_health_memory.py::test_health_reports_the_budget_and_the_process_footprint, a KeyError: '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.py fail:

      • the new TPOT test, which uses a fake clock and checks both servers, a round with nothing new, a token the server appends itself, and the engine's decode_s staying out of it;
      • the Mac route test, which now checks that the family is rendered;
      • the real Mac chat test;
      • the CUDA HTTP test with a paced engine, which now checks the TPOT count.

      All four pass here.

  • Not run, and why:

    • Two ranks. I have one GB10 free for this. The stop-string case that matters there is in the unit test: the engine reports 5 s of decode while the reply's arrivals span 24 ms.
    • The full CUDA suite. The change is in the server module and cuda/health.py, and touches no kernel or engine.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

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.
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]>
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @juliankang4. This landed in the Zig engine as 8debb38, with your credit.

/metrics now has request_time_per_output_token_seconds under vLLM's name, timed as you timed it: the server's clock from the first token to the last, over the tokens less one, with one-token replies adding no sample. A dashboard built for vLLM can read it with the usual prefix swap.

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.

@ashhart ashhart closed this Oct 6, 2026
@ashhart ashhart mentioned this pull request Oct 6, 2026
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]>
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.

2 participants