Skip to content

kv-router: add block-weighted overlap counters (standalone) - #36

Open
Pernekhan wants to merge 1 commit into
mainfrom
claude/router-blockwt-metric-only
Open

kv-router: add block-weighted overlap counters (standalone)#36
Pernekhan wants to merge 1 commit into
mainfrom
claude/router-blockwt-metric-only

Conversation

@Pernekhan

Copy link
Copy Markdown
Collaborator

Single commit on top of main, +36 lines across 3 files, no behavior change. Supersedes #34, which carried this same commit on top of 11 unrelated ones.

The trap this closes

dynamo_component_router_kv_hit_rate is a histogram of per-request overlap_blocks / isl_blocks, so sum/count is a mean of ratios (request-weighted). The engine's vllm:prefix_cache_hits_total / queries_total is a ratio of sums (block-weighted). They are not comparable, and on a skewed ISL distribution they diverge badly.

On DeepSeek-V4-Flash-0731 — 44% of requests under 1800 tokens (≤7 blocks), mean ISL 14,211, tail past 130k tokens (~508 blocks) — the router read 0.320 against the engine's 0.767 and looked half blind.

It isn't. That mis-comparison consumed most of a debugging session and nearly triggered an unnecessary indexer rewrite on a subsystem that was working correctly.

The fix

Add router_kv_overlap_blocks_total / router_kv_isl_blocks_total, incremented at routing time from selection.effective_overlap_blocks and isl_blocks. Dividing them yields a block-weighted router hit rate directly comparable to the engine's.

Verified live, immediately after deploy

router BLOCK-weighted   = 0.790   <- new counters
engine  BLOCK-weighted  = 0.767   <- vllm:prefix_cache_hits/queries
router REQUEST-weighted = 0.320   <- the old, misleading number

Within 3% of the engine and slightly ahead, which is expected — some blocks are evicted between the routing decision and execution.

Independently corroborated: 10/10 paired requests sharing an 8k-token prefix showed 97.7% block-weighted reuse (range 96.0–98.5%), i.e. the router picked the prefix-holding worker every time.

Risk

None to serving. Two IntCounters and their increments; no routing logic touched. The code comment states the aggregation difference explicitly so the next person doesn't walk into it.

🤖 Generated with Claude Code

https://claude.ai/code/session_017rS1uFFKT2xV4x63Amfvtw

router_kv_hit_rate is a histogram of per-request overlap/isl, so sum/count is a
mean of ratios. The engine's vllm:prefix_cache_hits/queries is a ratio of sums.
On a skewed ISL distribution these diverge badly -- on DeepSeek-V4-Flash-0731
(44% of requests under 1800 tokens, mean 14211, tail past 130k) the router read
0.320 against the engine's 0.767 and looked half blind.

Add router_kv_overlap_blocks_total / router_kv_isl_blocks_total so the router's
predicted overlap can be compared with the engine directly. Measured on the same
fleet right after deploy: block-weighted router 0.790 vs engine 0.767, i.e. the
router's view was accurate all along.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants