Skip to content

vllm.compilation.passes.fusion.qk_norm_rope_kvcache_fusion

Classes:

QkNormRopeKvCacheFusionPass

Bases: VllmPatternMatcherPass

Fuse QK-norm + RoPE/MRoPE + KV cache update into an AITER HIP kernel.

Supersedes both QKNormRoPEFusionPass and RopeKVCacheFusionPass for attention layers that support the combined operation, eliminating two separate kernel launches and the intermediate memory traffic.

QkNormRopeKvCachePattern

Match the unfused sequence

q, k, v = split(qkv, ...) q = rms_norm(q.view(heads), q_weight).view(flat) k = rms_norm(k.view(heads), k_weight).view(flat) q, k = rotary_embedding(positions, q, k, cos_sin_cache, is_neox) q = q.view(num_heads, head_dim) k = k.view(num_kv_heads, head_dim) v = v.view(num_kv_heads, head_dim) v = rms_norm(v, None) # only with v_norm (weightless, e.g. Gemma4) dummy = unified_kv_cache_update(k, v, layer_name)

Replace with

q_out = empty(...) k_out = empty(...) dummy = fused_qk_norm_rope_and_unified_kv_cache_update( q_out, k_out, qkv, positions, q_weight, k_weight, eps, cos_sin_cache, is_neox, layer_name) v = split(qkv, ...)[2].view(num_kv_heads, head_dim)

_only_feeds_unified_attention(match, output_index) staticmethod

Whether the pattern output is used only inside the match or by decoder unified attention, which reads K/V from the cache.