从零实现 LLM Inference:060. KV append identity fast path(少做一次 index_select)
append_token_batch 里 fast_batch_idx 很多时候就是 [0..B-1];之前每层都会 index_select 把 key_new/value_new 重新拷一遍,还会构造 pos_t。这个小改动在 identity batch 时直接复用 key_new/value_new,并且...
append_token_batch 里 fast_batch_idx 很多时候就是 [0..B-1];之前每层都会 index_select 把 key_new/value_new 重新拷一遍,还会构造 pos_t。这个小改动在 identity batch 时直接复用 key_new/value_new,并且...
append_token_batch 之前只覆盖 len<block_size 的 fast path;一旦 last block 满了(len==block_size)就会退化成逐 request 的 append_token。这个点会制造 ITL 的尖刺。这版把 rollover 也塞回 batch:先...
prefix cache hit 时我们还在把 last_logits 从 CPU 拷回 GPU;这版把 entry 的 last_logits 直接存成 device 上的一份小 clone,hit 变成真正的零拷贝。
prefix cache 复用会让 decode 的最后一个 KV block refcount>1;之前 append_token_batch 直接退化成逐 request 的 append_token + copy-on-write,CPU/GPU overhead 都很明显。这版把 COW clone...
055 做了 longest-prefix reuse,但 longest-prefix 查询还是 O(N) 扫描;这版用 token trie 替换掉 scan,把 cache miss 的 longest-prefix 查找从 ms 级降到 us 级,减少 scheduler CPU overhead。