Repository navigation
Description
Summary
prefill_throughput (tokens/s) is computed as input_tokens / ttft. Those two numbers describe different amounts of work whenever the pipeline reuses KV from a previous request, so the metric is systematically inflated on warm runs — by up to the full prompt length.
src/engine/ov_genai/llm.py:208-212src/engine/ov_genai/vlm.py:334-336
ttft_seconds = perf_metrics.get_ttft().mean / 1000
input_tokens = perf_metrics.get_num_input_tokens()
prefill_throughput = round(input_tokens / ttft_seconds, 2) if ttft_seconds > 0 else 0My proposed fix is verified for LLMs: the variable get_num_prefix_cache_hit_tokens exists in the current nightly, and it reports real hit counts. Subtracting it fixes the math (described below).
For VLMs, the same accessor always reads 0 in this build, even when reuse should occur. So, VLM prefill metrics are still incorrect. That half of the accuracy problem is upstream, not ours (see Not fixing the math for VLMs).
The math
Three quantities are involved. We use two of them; we never use K.
| quantity | accessor | meaning |
|---|---|---|
| N — prompt tokens as tokenized | get_num_input_tokens() |
length of the token sequence handed in |
| K — tokens whose KV was copied from a prior request | get_num_prefix_cache_hit_tokens() |
never read |
| T — time to produce the first token | get_ttft().mean |
covers only the N−K tokens actually recomputed |
T really is "time to process N−K tokens," but the current code treats it as "time to process N tokens." Thus, metrics from warm runs are accurate only when K = 0.
Evidence of KV cache use bleeding into prefill metrics
Warm runs — KV reused across requests:
- [LLM Worker: NousCoder-14B] Metrics: {'load_time (s)': 6.67, 'ttft (s)': 0.31, 'tpot (ms)': 45.48921, 'prefill_throughput (tokens/s)': 26754.5, 'decode_throughput (tokens/s)': 21.98323, 'decode_duration (s)': 26.14476, 'input_token': 8195, 'new_token': 569, 'total_token': 8764, 'stream': True, 'stream_chunk_tokens': 1}
- [VLM Worker: Ornith-9B] Metrics: {'load_time (s)': 40.26, 'ttft (s)': 1.28, 'tpot (ms)': 28.7935, 'prefill_throughput (tokens/s)': 9656.85, 'decode_throughput (tokens/s)': 34.73006, 'decode_duration (s)': 2.55946, 'input_token': 12334, 'new_token': 44, 'total_token': 12378, 'stream': True, 'stream_chunk_tokens': 1}
8195 tokens in 0.31 s and 12334 tokens in 1.28 s are far beyond what a 14B model should be able to do on my Intel Arc Pro B50, even when quantized to int4.
Cold runs, for contrast — same metric, believable values:
- [VLM Worker: Ornith-9B] Metrics: {'load_time (s)': 17.27, 'ttft (s)': 0.08, 'tpot (ms)': 27.96792, 'prefill_throughput (tokens/s)': 725.07, 'decode_throughput (tokens/s)': 35.75525, 'decode_duration (s)': 1.30692, 'input_token': 55, 'new_token': 45, 'total_token': 100, 'stream': False}
- [VLM Worker: Qwen3.6-35B] Metrics: {'load_time (s)': 76.95, 'ttft (s)': 4.36, 'tpot (ms)': 141.26666, 'prefill_throughput (tokens/s)': 122.15, 'decode_throughput (tokens/s)': 7.07881, 'decode_duration (s)': 384.09191, 'input_token': 533, 'new_token': 2689, 'total_token': 3222, 'stream': True, 'stream_chunk_tokens': 1}
What updated ovgenai offers
Recent updates to ovgenai provide PerfMetrics accessors beyond the seven we currently read:
get_num_prefix_cache_hit_tokens
get_inference_duration
get_ipot
raw_metrics
get_sampling_duration
get_tokenization_duration
get_detokenization_duration
get_chat_template_duration
get_grammar_compile_time
Upstream semantics for the hit count: K for a partial prefix match, N - 1 when the whole prompt is cached (the final token must still run to produce first logits), 0 when prefix caching is disabled or the pipeline cannot restore a prefix cache.
Note: The nightly wheels version I used here is openvino-genai 2026.5.1.0-3668.
Fixing the math for LLMs
With my proposed code edits, the prefill math is correct for LLMs. The following data are from runs that use the same shared ~1600-token system prompt sent to /v1/chat/completions. The route returns the metrics dict verbatim via src/server/routes/openai.py:438. I used max_tokens: 8, temperature: 0, and no tools:
| run | input_token |
prefix_cache_hit_tokens |
new_input_tokens |
ttft (s) |
|---|---|---|---|---|
| cold | 1639 | 0 | 1639 | 1.15 |
| warm (same system prompt, new user turn) | 1643 | 1616 | 27 | 0.12 |
| exact repeat | 1643 | 1632 | 11 | 0.12 |
| control (unrelated 21-token prompt) | 21 | 0 | 21 | 0.09 |
This is data from an LLM (NousCoder-14B, int4) served by OpenArc, but the finding is independent of OpenArc code. A similar data shape was reproduced with a bare ovgenai LLMPipeline(MODEL, "GPU.1", scheduler_config=sc, ATTENTION_BACKEND="PA") of the same model, with sc.cache_size = 1, enable_prefix_caching = True: 1630-token prompt, hit = 1616, new = 14, ttft 0.98 → 0.12 s.
Not fixing the math for VLMs
The identical probe against VLMPipeline reports no reuse at all:
| pipeline | model | identical prompt repeated | hit |
ttft |
|---|---|---|---|---|
LLMPipeline |
NousCoder-14B-int4_sym | yes | 1616 / 1630 | 0.98 → 0.12 s |
VLMPipeline |
Qwen3.5-9B-int4_asym-fp16_vision | yes, text-only | 0 | 1.06 → 0.54 s |
VLMPipeline |
Ornith-1.0-9B-int4 | yes, text-only | 0 | 1.45 → 0.54 s |
VLMPipeline |
Qwen3.5-9B | yes, with a 256×256 image (tagged + untagged) | 0 | ~0.6 s |
These data are independent of any OpenArc code, so are not influenced by the tool-call parsers (src/engine/ov_genai/tool_parse/* are output-side streamers and no tools were sent) or other unique OpenArc architecture. Importantly, vlm.py:413 passes **scheduler_config to VLMPipeline exactly as llm.py:289 does.
Consequence for this issue: the math is correct but unverifiable for VLMs until there's a fix upstream. VLM prefill_throughput is still inflated today because hit never rises above 0.
Changes proposed
1. Feature-detect the accessor and stamp the version
- Feature-detect via
getattr(already in the helper, step 2 below). - Stamp the version in the metrics dict so reported rates stay attributable across nightly bumps (precedent:
openarc.py:314usesimportlib.metadata.version;inspect_openvino_ir.py:133printsov.__version__; the Dockerfile already records versions inBUILD_INFO.txtat:219/:264):
'ovgenai_version': openvino_genai.__version__,Rationale: pyproject.toml and uv.lock keep a version floor for ovgenai at 2026.3.1. However, we deliberately track nightly wheels in all three install paths (setup.sh:16, setup.bat:16, .devops/openvino.Dockerfile:95), so the venv will use the nightly wheel instead of the version floor. That said, a hard call to get_num_prefix_cache_hit_tokens would crash a worker on an older nightly or a bare uv sync box, so this change accounts for such configurations.
2. De-duplicate the math
It is copy-pasted in llm.py:208-212 and vlm.py:334-336. Add one helper to src/engine/ov_genai/utils.py, where select_streamer / ensure_tool_call_parser / flatten_messages already live:
def prefill_metrics(perf_metrics) -> tuple[float, int, int]:
hit_fn = getattr(perf_metrics, "get_num_prefix_cache_hit_tokens", None)
hit = hit_fn() if hit_fn else 0
total = perf_metrics.get_num_input_tokens()
new_tokens = total - hit
ttft_s = perf_metrics.get_ttft().mean / 1000
return (round(new_tokens / ttft_s, 2) if ttft_s > 0 else 0.0), new_tokens, hit(This is just some code cleanup. It's not directly related to the issue, but it still feels good to do.)
3. Emit the new fields
In both collect_metrics() dicts (llm.py:218, vlm.py:342):
'prefill_throughput (tokens/s)': prefill_throughput, # now new_tokens / ttft
'new_input_tokens': new_input_tokens,
'prefix_cache_hit_tokens': prefix_cache_hit_tokens,
'ovgenai_version': openvino_genai.__version__,The metrics dict is an untyped Dict[str, Any] end to end (src/server/worker_registry.py:74-88, passed through at src/server/routes/openai.py:438), so new keys break nothing.
4. Tests to add
Both dummies are hand-rolled fakes, so they need the accessor added explicitly. Also, with feature detection (change #1) we now have three paths to cover:
tests/unit/test_ov_genai_llm_unit.py:22-47— keepDummyPerfMetricswithout the accessor (simulates an older nightly / bareuv sync; the existing== 100.0assertion at:139still passes withhit = 0). Add a newDummyPerfMetricsCacheHitclass withget_num_prefix_cache_hit_tokens() -> 20, and a new testtest_collect_metrics_prefill_throughput_cache_hitassertingprefill_throughput == 20.0,new_input_tokens == 5,prefix_cache_hit_tokens == 20.tests/unit/test_ov_genai_vlm_unit.py:23-48— same pattern:DummyPerfMetricswithout accessor (existing== 30.0at:153still passes),DummyPerfMetricsCacheHitwithget_num_prefix_cache_hit_tokens() -> 8, new test assertingprefill_throughput == 10.0,new_input_tokens == 4,prefix_cache_hit_tokens == 8.- The accessor-absent fallback path is covered by the existing
DummyPerfMetrics(no accessor →hit = 0, no raise).
5. Bench changes
src/cli/groups/bench.py:264 — read 'prefix_cache_hit_tokens' into the result dict (:270), add a column cache_hit after prefill(t/s) at :310, and its value str(result['prefix_cache_hit_tokens']) at :325. A warm row must be visible, not silently averaged with cold rows.
6. Server metrics database changes
src/cli/modules/benchmark.py:46 — add prefix_cache_hit_tokens INTEGER NOT NULL DEFAULT 0; follow the existing _ensure_* ALTER-TABLE pattern (:61-89, add _ensure_prefix_cache_column()); extend the column tuple at :111-112 and the value list at :137-138.
Environment
Intel Arc Pro B50 (GPU), Ubuntu 24.04 LTS, OpenArc main as of 11/16/2026, openvino-genai 2026.5.1.0-3668 (nightly index), openvino 2026.5.1.
Credits
- Code generated by Qwen-3.8-Flash-Next-Coder, served by llama.cpp, harnessed by maki, and guided & verified by me at every step.
- Issue text generated Qwen-3.8-Flash-Next-Coder in the same setup. I edited it heavily for style and content.
- That model somehow uses both too many words and too few words at the same time. Every verb has to be an action verb, even when you're talking about inanimate code; and every single caveat must be explicitly stated, even if it's extremely tangential.
Activity
fix prefill_throughput: subtract prefix-cache hit tokens from the num…