vllm.compilation.passes.fusion.rope_kvcache_fusion
¶
Classes:
-
RopeKVCacheFusionPass–This pass fuses the rotary embedding and KV cache update operations
-
RopeReshapeKVCachePattern–This pattern matches the following unfused inplace ops:
-
RopeStaticQQuantKVCachePattern–Fuse rope + static Q fp8 quant while preserving explicit KV-cache update
Functions:
-
fused_rope_and_unified_kv_cache_update_impl–This impl fetches the KV cache and slot mapping from the forward context,
RopeKVCacheFusionPass
¶
Bases: VllmPatternMatcherPass
This pass fuses the rotary embedding and KV cache update operations into a single fused kernel if available.
It uses the pattern matcher and matches each layer manually, as strings cannot be wildcarded. This also lets us check support on attention layers upon registration instead of during pattern matching.
This fusion eliminates the need for separate kernel launches and intermediate memory operations between the RoPE and cache update steps.
RopeReshapeKVCachePattern
¶
This pattern matches the following unfused inplace ops
q, k = rotary_embedding(positions, q, k, head_size, cos_sin_cache, is_neox) kv_cache_dummy = unified_kv_cache_update(k, v, layer_name)
and replaces it with the fused inplace op
kv_cache_dummy = fused_rope_and_unified_kv_cache_update( q, k, v, positions, cos_sin_cache, is_neox, layer_name )
RopeStaticQQuantKVCachePattern
¶
Fuse rope + static Q fp8 quant while preserving explicit KV-cache update dependency ordering.
_accepts_rope_out_buffers(impl_type)
cached
¶
Whether do_rope_and_kv_cache_update takes query_out/key_out. Out-of-tree backends may still override it with the older in-place signature.
fused_rope_and_unified_kv_cache_update_impl(query, key, value, positions, cos_sin_cache, is_neox, layer_name)
¶
This impl fetches the KV cache and slot mapping from the forward context,
then calls the layer impl's AttentionImpl.do_rope_and_kv_cache_update method.
It also returns a dummy tensor, similar to Attention.unified_kv_cache_update,
that is passed to unified_attention to signal a side effect and
the data dependency between them to ensure torch.compile preserves ordering.