Conversation
Signed-off-by: Jinjie Shao <shaojinjiesjj@gmail.com>
|
Hi @skajre — thanks for working on this. Emitting Are you planning to continue this PR? I’d be happy to help with testing or follow-up changes if useful. |
Thanks for reaching out! Yes, I plan to continue working on this PR and move the feature forward. I’ve already run the relevant tests around the BlockRemoved behavior, and the results look good so far. I’d be very happy to collaborate—additional testing or help with follow-up changes would be greatly appreciated. I’ll keep the PR updated as I make progress. |
Purpose
A prefix-cache block hash can map to multiple physical KV cache blocks. For example, when an identical block-aligned prompt is served repeatedly, vLLM may reuse earlier prefix blocks but recompute the final prompt block to obtain next-token logits. The recomputed blocks have the same hash while retaining different physical block IDs.
Previously, evicting any one of these physical copies emitted a
BlockRemovedevent. An external KV event consumer could therefore invalidate the hash even though another physical copy was still resident and available for prefix-cache lookup.For example, consider two cached requests:
Suppose
H3is backed by two physical blocks,P3-AandP3-B. EvictingP3-Apreviously emittedBlockRemoved(H3)even thoughP3-Bremained resident. The external cache view could then appear as:Because block hashes form a prefix chain, a new request matching
H1 -> ... -> H7would be scored as a two-block cache hit rather than the seven-block hit actually available in the engine. A prefix-aware router could consequently choose the wrong engine, or trigger unnecessary recomputation or remote loading ofH3throughH7.This PR makes
BlockRemoveda logical cache-key disappearance event:BlockHashToBlockMapand determine how many copies remain under the sameBlockHashWithGroupIdkey.BlockRemovedwhile at least one same-hash physical copy remains.BlockRemovedevent only after the last physical copy in that KV cache group disappears.BlockPool; the event schema and ZMQ wire format remain unchanged.(block_hash, group_idx).The internal removal result remains available to hash relocation paths such as
move_block_hashes, so all hashes formerly owned by the source physical block are re-pointed correctly.Test Plan
End-to-end test:
prompt_logprobs, producing three physical copies of the final block hash.BlockRemovedschema.Test Result
End-to-end result:
Observed target event stream:
No documentation update is required because this change preserves the public event schema and strengthens the existing
BlockRemovedsemantics.