vllm.models.flint.ops.qk_norm_rope
¶
Fused per-head q/k RMSNorm + NeoX RoPE + paged KV-cache write.
Numerics follow the unfused vLLM ops it replaces: RMSNorm computes
bf16(x * rsqrt(mean(x^2) + eps) * w) in fp32, RoPE computes
x * cos - y * sin in fp32 from the fp32 cos/sin cache (as the reference
implementation does; vLLM's rotary op would round the cache to bf16 first) and
rounds to bf16, and K/V are stored unchanged in the bf16 cache.
Functions:
-
qk_norm_rope_cache–Normalize and rotate q/k from
qkvand write k/v into the cache.
qk_norm_rope_cache(qkv, positions, q_weight, k_weight, eps, cos_sin_cache, k_cache, v_cache, slot_mapping, num_q_heads, num_kv_heads, head_dim, launch_dependents=False)
¶
Normalize and rotate q/k from qkv and write k/v into the cache.
Parameters:
-
(qkv¶Tensor) –[T, (Hq + 2 * Hkv) * D] bf16; k is normalized in place.
-
(positions¶Tensor) –[T] token positions.
-
(q_weight¶Tensor) –[D] q RMSNorm weight.
-
(k_weight¶Tensor) –[D] k RMSNorm weight.
-
(eps¶float) –RMSNorm epsilon.
-
(cos_sin_cache¶Tensor | None) –[max_pos, D] fp32 (cos | sin), or None for no RoPE.
-
(k_cache¶Tensor | None) –[num_blocks, block_size, Hkv, D] view (any strides with a contiguous last dim), or None to skip the cache write.
-
(v_cache¶Tensor | None) –Same shape and strides as
k_cache. -
(slot_mapping¶Tensor | None) –[<= T] int64; negative slots are skipped.
-
(num_q_heads¶int) –Hq.
-
(num_kv_heads¶int) –Hkv.
-
(head_dim¶int) –D.
-
(launch_dependents¶bool, default:False) –Let a PDL successor that waits on the grid dependency before reading q / K / V (Flint decode attention) start its prologue early. Must stay False before other kernels.
Returns:
-
q(Tensor) –[T, Hq * D] bf16.
Source code in vllm/models/flint/ops/qk_norm_rope.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |