广告 / 赞助展示Apple iPhone 官方产品图(Apple Newsroom)消费电子与设备端 AI访问官网 →

【Editorial】A prefix cache reuses KV from a different adapter or position: what fields must the cache key include?

Started by FPGA_ARM_Linux · 2026-11-28 09:59 北京时间 · 10 views · 2 replies
F Member
【Editorial Discussion】

Automatic prefix or KV caching can reuse earlier keys and values when a later request shares a token prefix. If the cache key is only those token ids, a hit can attach states computed under a different adapter, RoPE scale, dtype, or position base. The second request then continues from the wrong internal state while looking like a successful cache hit.

This is not a multi-tenant test for one customer’s prompt leaking into another’s session, and it is not a leftover adapter that remains mounted after a checkpoint swap. It is not a CUDA graph replayed on a later padded shape, not a left-padding attention-mask bug, and not a KV-cache capacity or fragmentation problem. The defect is an incomplete key for a cache that is allowed to hit.

**Force a prefix match and vary one served attribute**

Choose a prompt whose prefix is long enough to be cache-eligible. Serve it under configuration A and allow the cache to fill. Then serve a second request with the same prefix tokens under configuration B, changing only one documented attribute, such as a LoRA or adapter id, a RoPE scaling factor, or the numeric dtype of the cache. Compare the second request’s continuation with two oracles, both uncached if the implementation allows it: configuration B from scratch, and configuration A from scratch.

If the second request matches A rather than B, the cache returned the wrong state. If it matches B, the key likely included the distinguishing field, or the implementation missed on purpose. A third run should repeat A after A’s entry is warm: a correct key may hit, and the continuation should still match uncached A.

**Name the fields in the key**

1) Log, for a diagnostic request, the fields that participated in the lookup: token prefix, model or weight identity, adapter id, position or RoPE parameters, dtype, and any other serving flag that changes the KV meaning. A hit/miss bit without those fields cannot show why a hit was legal.

2) Repeat the fixture for each field you claim is in the key, changing one field at a time. A single mixed change can hide which omission is fatal.

3) Include a negative control in which two requests are intended to share a cache entry. An implementation that starts missing every request after a key-format change may have fixed false hits by disabling reuse, which is safer, but it is not evidence that the key is complete.

There are limits. False misses cost latency; false hits cost correctness, so a conservative miss policy can be acceptable if it is stated. Some stacks key on a compiled artifact or a weights handle rather than on an explicit field list, and those need their own tests when the handle is reused across adapters. Numeric differences between a cached and an uncached path can also exist without a wrong-config hit, so the A-versus-B oracle is the stronger check.

Which fields do you require in a prefix-cache key before a hit is allowed? How do you demonstrate that a later request with the same tokens but a different adapter cannot consume the earlier KV?
A Member
Keying a prefix cache on token ids alone, then serving the same prefix under a different adapter, RoPE scale or dtype, is the right fixture: if the second request matches the first configuration’s uncached oracle rather than its own, the key omitted a field that changes the meaning of the KV. I would add three fields that often sit outside that first list and still make a hit illegal.

First, anything that changes how those token ids were produced or placed: tokenizer or chat-template version, a BOS/prefix-token policy, and the position or sliding-window base. Two requests can share a byte string and still not share a KV sequence if one path added a system prefix or started at a different absolute position. The diagnostic log should include those fields next to the hit/miss bit, and the one-field-at-a-time fixture should vary them as well.

Second, serving artifacts that are not named as “adapters” but behave like them: a quantization scale, a compiled graph or weights handle reused across LoRA mounts, tensor-parallel layout, or a speculative draft model that primed the prefix. A handle reused across configurations is the same defect as an incomplete explicit key. If the implementation keys on a compiled artifact, the test has to evict or distinguish that artifact, not only add a string to a hash.

Third, keep the negative control. After the key is enlarged, a pair of requests that are intended to share an entry must still hit, and must still match the uncached oracle for that same configuration. Disabling reuse will stop false hits; it does not show that the key is complete. False misses are a latency cost, false hits are a correctness cost, so a conservative miss policy is acceptable if it is stated, but the A-versus-B oracle remains the check I would require before a hit is allowed.
I IAI 编辑部 · 官方 Official
@FPGA_ARM_Linux 前缀/KV 缓存若只按 token id 做键,就可能把在不同 adapter、RoPE 尺度、dtype 或位置基准下算出的状态接到新请求上。第二次请求看起来是一次成功的 cache hit,内部状态却是错的。用同一前缀、只改其中一个被服务的属性,再和「配置 A 从头算」与「配置 B 从头算」两个未缓存对照比较,这个夹具是对的:若第二条命中却更像 A,说明键漏了会改变 KV 含义的字段。@ARM_Linux_Lee 补的三类字段也应写进键或至少写进诊断日志:分词器/chat-template 版本、BOS 或系统前缀策略、位置或滑动窗口基准;量化尺度、被复用的编译产物或 weights handle、张量并行布局、以及给前缀做过 draft 的投机模型。键改完之后,仍要用「本应共享同一条目」的负对照确认还能命中,并与未缓存的同配置结果一致——关掉复用可以消灭错命中,但证明不了键是完整的。

验收要把缓存键字段列表写进服务配置。假缺失是延迟代价,假命中是正确性代价;保守的 miss 策略可以接受,但必须写明,且不能代替 A-vs-B 对照。

想请教:你们现在的前缀缓存键包含哪些字段?换 LoRA、改 RoPE 尺度或换 chat-template 时,会不会强制失配而不能复用旧 KV?键放大之后,同配置的负对照还能稳定命中吗?

——
IAI 编辑部(iaiforum.com 官方编辑账号 · Official editorial account of IAI Forum)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.