[GH-ISSUE #4724] [Engine] batch mode: per-request hit_rate/pcie_share are always null — BDONE carries no hits/lookups #2162

Open
opened 2026-11-04 01:57:09 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @xiguan99 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4724

Environment

  • Strata Control 0.1.52, engine 0.1.52 (CUDA 12, x86_64)
  • Model: Qwen3.8-Flash-Next IQ3_S (pack), 2 GPUs (one 8 GB, one 22 GB), layer split
  • --serve --batch 2 --mtp --max-context 262144 --kv-resident 16384
  • Requests arrive through the app's /v1 (stream and non-stream)

What I see

With --batch, every request record that serve/server.py keeps in history (and therefore everything GET /metrics returns under requests[]) has hit_rate: null and pcie_share: null, while the rest of the row is correct:

{"id":"…","prompt_tokens":45302,"reused":44919,"output_tokens":8182,
 "prompt_ms":612.4,"decode_tok_s":73.3,
 "hit_rate":null,"pcie_share":null,
 "drafts_offered":214,"drafts_accepted":153,"finish":"stop"}

14 out of 14 requests in one session were like this — not an occasional miss.

The engine does have the numbers: it prints them at the end of every request, e.g.

strata serve: decode expert cache hit rate: 99.5% (4868242 hits / 4892337 lookups); 733 more read by the GPU over PCIe or from another GPU (0.0% of all 4893070 routed)

(these counters are cumulative since engine start, which is why the percentages look right while the per-request figures are missing).

Why (static, then confirmed at runtime)

  1. The 16-field DONE line carries them — f[9]/f[10] are hits/lookups, f[15] is offloaded — and _parse_done() reads exactly those.
  2. In batch mode the engine reports a slot with BDONE <slot> <produced> <finish> <ms> (format string in the 0.1.52 binary: BDONE %d %lld %s %.1f). There is no hits/lookups field in it.
  3. serve/server.py _apply_bdone() merges only finish, decode_ms and generated into the request's figures, and request_stats() sums hits/lookups only when some segment actually carries them. So for a batched request last never has lookups, and the history row's
    hit_rate = round(last["hits"] / last["lookups"], 3) if last.get("lookups") else None
    is None by construction. Same for pcie_share (offloaded).

So this is not the GUI merge problem from #4289 — even after that is fixed there is nothing for a batched request to display. #1933 aggregated clocks and counters across DONE/BDONE, but the expert-cache counters were not part of it.

What I suggest

Extend BDONE with the same three counters and total them like the clocks:

BDONE <slot> <produced> <finish> <ms> <hits> <lookups> [<offloaded>]
  • in _apply_bdone(), add them to the request's last the way generated/decode_ms are added (sum over the request's BDONE segments, as request_stats() already does for the clock keys);
  • keep the trailing fields optional so older engines and the nonfinite variant (BDONE %d %lld nonfinite %.1f) still parse;
  • pcie_share needs offloaded (present since engine 0.1.39 in DONE), so it can ride along as the last field.

Per-request decode hit rate is the number people actually use to decide --kv-resident and expert-cache size, and right now --batch users can only get it from the log line, by differencing a global counter.

Workaround in the meantime

We parse the per-request log summary above and difference consecutive lines to get a single request's hit rate. That works, but it is a log-format dependency, it is ambiguous when two requests share a window (no slot attribution), and it breaks when the engine restarts and the counters reset — so a real field in the API would be much better.

Related: #4289, #1933, #588.

Originally created by @xiguan99 on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4724 ## Environment - Strata Control **0.1.52**, engine **0.1.52** (CUDA 12, x86_64) - Model: Qwen3.8-Flash-Next IQ3_S (pack), 2 GPUs (one 8 GB, one 22 GB), layer split - `--serve --batch 2 --mtp --max-context 262144 --kv-resident 16384` - Requests arrive through the app's `/v1` (stream and non-stream) ## What I see With `--batch`, **every** request record that `serve/server.py` keeps in `history` (and therefore everything `GET /metrics` returns under `requests[]`) has `hit_rate: null` and `pcie_share: null`, while the rest of the row is correct: ```json {"id":"…","prompt_tokens":45302,"reused":44919,"output_tokens":8182, "prompt_ms":612.4,"decode_tok_s":73.3, "hit_rate":null,"pcie_share":null, "drafts_offered":214,"drafts_accepted":153,"finish":"stop"} ``` 14 out of 14 requests in one session were like this — not an occasional miss. The engine *does* have the numbers: it prints them at the end of every request, e.g. ``` strata serve: decode expert cache hit rate: 99.5% (4868242 hits / 4892337 lookups); 733 more read by the GPU over PCIe or from another GPU (0.0% of all 4893070 routed) ``` (these counters are cumulative since engine start, which is why the percentages look right while the per-request figures are missing). ## Why (static, then confirmed at runtime) 1. The 16-field `DONE` line carries them — `f[9]`/`f[10]` are `hits`/`lookups`, `f[15]` is `offloaded` — and `_parse_done()` reads exactly those. 2. In batch mode the engine reports a slot with `BDONE <slot> <produced> <finish> <ms>` (format string in the 0.1.52 binary: `BDONE %d %lld %s %.1f`). There is no hits/lookups field in it. 3. `serve/server.py` `_apply_bdone()` merges only `finish`, `decode_ms` and `generated` into the request's figures, and `request_stats()` sums `hits`/`lookups` only when some segment actually carries them. So for a batched request `last` never has `lookups`, and the history row's `hit_rate = round(last["hits"] / last["lookups"], 3) if last.get("lookups") else None` is `None` by construction. Same for `pcie_share` (`offloaded`). So this is not the GUI merge problem from #4289 — even after that is fixed there is nothing for a batched request to display. #1933 aggregated clocks and counters across `DONE`/`BDONE`, but the expert-cache counters were not part of it. ## What I suggest Extend `BDONE` with the same three counters and total them like the clocks: ``` BDONE <slot> <produced> <finish> <ms> <hits> <lookups> [<offloaded>] ``` - in `_apply_bdone()`, add them to the request's `last` the way `generated`/`decode_ms` are added (sum over the request's `BDONE` segments, as `request_stats()` already does for the clock keys); - keep the trailing fields optional so older engines and the `nonfinite` variant (`BDONE %d %lld nonfinite %.1f`) still parse; - `pcie_share` needs `offloaded` (present since engine 0.1.39 in `DONE`), so it can ride along as the last field. Per-request decode hit rate is the number people actually use to decide `--kv-resident` and expert-cache size, and right now `--batch` users can only get it from the log line, by differencing a global counter. ## Workaround in the meantime We parse the per-request log summary above and difference consecutive lines to get a single request's hit rate. That works, but it is a log-format dependency, it is ambiguous when two requests share a window (no slot attribution), and it breaks when the engine restarts and the counters reset — so a real field in the API would be much better. Related: #4289, #1933, #588.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2162
No description provided.