Skip to content

feat: the CUDA server publishes live token totals on /health - #79

Closed
MiaAI-Lab wants to merge 1 commit into
ashhart:mainfrom
MiaAI-Lab:feat/cuda-health-token-counters
Closed

MiaAI-Lab wants to merge 1 commit into
ashhart:mainfrom
MiaAI-Lab:feat/cuda-health-token-counters

Conversation

@MiaAI-Lab

Copy link
Copy Markdown
Contributor

TL;DR: GET /health on the CUDA server now reports cumulative token counters while a request is running, so a poller can show live tok/s. Stock /health was {"ok": true} and had nothing to diff.

The problem

The CUDA server has no /metrics. Per-request timing (prefill_s, decode_s) is only on the chat completion body, which a monitor that is not the client never sees. While a generation is in flight, /health stays {"ok": true}, so decode and prefill rates read as 0 for the whole run.

The change

/health and /v1/health now return:

  • prompt_tokens_total and prefill_seconds_total — updated when the first output token arrives (prompt length, and the time from the start of generation until that token)
  • completion_tokens_total — updated as each emitted token batch arrives, not when the request finishes
  • busy and requests_running — in-flight requests
  • context_length — the server's prompt/reply window, when it is set
  • backend: "tensorfold"

Idle is busy: false and the counters stop moving, so a diff over the poll window returns to 0. The first sample a poller sees should be treated as a baseline, not a rate.

Tests

tests/test_cuda_server_health.py: a request held before its first token reports busy with unchanged counters; after four tokens the completion counter has moved by 4, the prompt counter and prefill time have moved, and the server is idle again.

tests/test_cuda_server_health.py and tests/test_cuda_server_disconnect.py: 18 passed locally.

Live check on one DGX Spark (tensorfold serve Qwen3.8 Flash Next, 0.3.6.2 plus this patch): during a short generation /health advanced the counters and a 2s poll read about 25 tok/s decode and the prefill rate as prompt tokens ÷ prefill time, then both returned to 0.

Made with Cursor

A poller can diff these counters into tok/s. Completion tokens move as they are emitted; prompt tokens and prefill time move when the first output token arrives.

Co-authored-by: Cursor <[email protected]>
@Acermax

Acermax commented Sep 29, 2026

Copy link
Copy Markdown

Nice — while touching this, would you also publish cumulative cached prompt tokens (e.g. prompt_tokens_cached_total)? The data already reaches run(): every CUDA family engine with a prefix cache returns stats["cached"] from generate() — qwen3_5/cuda/engine.py:208,245, qwen3_5_moe/cuda/engine.py:107, qwen4_exp/cuda/engine.py:262, glm5_next/cuda/engine.py:378, nemotron_h/cuda/app.py:207 (gemma4/deepseek_v4/bonsai don't report it; the counter would just stay put there).

So it's one line next to the existing note_prefill/add_completion hooks — _LIVE.note_cached(stats.get("cached", 0)) after stats = generate_gated(...) — plus the field in snapshot().

That lets a poller diffing /health split the prompt side into cached vs computed prefill, matching what the OpenAI usage body already exposes per request (prompt_tokens_details.cached_tokens).

@ashhart

ashhart commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Landed in 0.5.0 as 51b098d. Thank you! /health now publishes live token totals on the CUDA server. On our side it reads them from the lane engine's own stats, off the rounds, and answers before an engine exists (c4bf25f). More like this is very welcome.

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

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants