Skip to content

Fix prefill_throughput for prefix-cache hits - #203

Merged
SearchSavior merged 2 commits into
SearchSavior:mainfrom
atrebek07:prefill-metrics
Nov 21, 2026
Merged

SearchSavior merged 2 commits into
SearchSavior:mainfrom
atrebek07:prefill-metrics

Conversation

@atrebek07

Copy link
Copy Markdown
Contributor

Closes issue #202.

prefill_throughput (tokens/s) was computed as input_tokens / ttft. TTFT only covers the tokens the pipeline actually recomputed, so whenever KV is reused from an earlier request the numerator and the denominator describe different amounts of work, and warm runs are inflated by up to the full prompt length.

What's new

  • src/engine/ov_genai/utils.py — new prefill_metrics(perf_metrics) -> tuple[float, int, int] returning (rate, new_tokens, hit), where rate = (N - K) / ttft. The accessor is feature-detected with getattr, so a build without it leaves K = 0 instead of raising.
  • src/engine/ov_genai/llm.py, src/engine/ov_genai/vlm.py — the formula copy-pasted in both collect_metrics() bodies is replaced by one helper call; both metric dicts now emit new_input_tokens and prefix_cache_hit_tokens. total_token reads get_num_input_tokens() directly instead of a local that no longer exists.
  • tests/unit/test_ov_genai_llm_unit.py, tests/unit/test_ov_genai_vlm_unit.py — added DummyPerfMetricsCacheHit (accessor returns 20 / 8) and test_collect_metrics_prefill_throughput_cache_hit, asserting 20.0 / 5 / 20 and 10.0 / 4 / 8. The existing DummyPerfMetrics deliberately keeps no accessor, so it still covers the fallback path and the old == 100.0 / == 30.0 assertions are unchanged.
  • src/cli/groups/bench.py — new cache_hit column after prefill(t/s), so a warm row is visible rather than silently averaged with cold ones.
  • src/cli/modules/benchmark.py — prefix_cache_hit_tokens INTEGER NOT NULL DEFAULT 0 in the results table, _ensure_prefix_cache_column() following the existing _ensure_* ALTER pattern, and the INSERT extended.

Behavior / caveats

  • LLMs: verified. NousCoder-14B int4, running on a B50, shared ~1600-token system prompt: cold hit=0, new=1639, ttft=1.15s; warm hit=1616, new=27, ttft=0.12s; exact repeat hit=1632, new=11. Reproduced with a bare LLMPipeline + SchedulerConfig(cache_size=1, enable_prefix_caching=True), so the finding is independent of OpenArc.
  • VLMs: the math is applied, but the value is still 0. VLMPipeline reports hit = 0 even when reuse should occur — Qwen3.5-9B, Ornith-1.0-9B, text-only and with a 256x256 image. This is an upstream gap, not an OpenArc one: vlm.py:413 passes **scheduler_config to VLMPipeline exactly as llm.py:289 does to LLMPipeline, and the continuous-batching backend is demonstrably selected (m_batch_sizes populated, VLMContinuousBatchingAdapter present in the wheel). VLM prefill_throughput is therefore still inflated today.
  • hit == 0 is not proof of a cold run. The SDPA backend rejects scheduler_config (utils.py:77-79), so it never has a prefix cache, and older builds lack the accessor. That is why the count is surfaced in the metrics rather than used to suppress warm rows.
  • No version pin. We track nightly wheels on purpose (setup.sh:16, setup.bat:16, .devops/openvino.Dockerfile:95 all run uv pip install --pre -U openvino-genai), which is why the accessor is feature-detected instead of guaranteed by raising the pyproject.toml floor.

Development environment

  • Tested on an Intel Arc Pro B50 in Ubuntu 24.04 LTS
  • openvino-genai 2026.5.1.0-3668 (nightly index), openvino 2026.5.1
  • Code generated by Qwen-3.8-Flash-Next-Coder, served by llama.cpp, harnessed by maki, and guided & verified by me at every step.

…erator

N/ttft mismatched numerator and denominator whenever KV was reused. Shared
prefill_metrics() helper in utils.py now divides new_input_tokens = N - K, and
both LLM and VLM metric dicts report new_input_tokens, prefix_cache_hit_tokens
and ovgenai_version so warm rows are attributable across nightly bumps.
bench.py shows a cache_hit column; benchmark.py tracks prefix_cache_hit_tokens.

SearchSavior#202
…s dicts

The version stamp was only useful for us, not for the server response, so it
stays out of the LLM and VLM metrics dicts.
@atrebek07 atrebek07 changed the title Fix prefill_throughput for prefix-cache hits — #202 Fix prefill_throughput for prefix-cache hits Nov 18, 2026
@SearchSavior
SearchSavior merged commit f13da14 into SearchSavior:main Nov 21, 2026
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