vllm.models.kimi_k3.amd.ops.flydsl_sparse_mla
¶
FlyDSL sparse MLA forward on the fp8_ds_mla cache (gfx950).
Covers the slice of rocm_aiter_ops.triton_sparse_mla_fwd that
DeepSeek-V3.2 / Kimi-K3 prefill takes: bf16 q, a 656 B fp8_ds_mla record
cache, kv_lora_rank 512, rope 64, at most 16 heads, bf16 dots, no sink, no
second segment, no split-K. flydsl_sparse_mla_fp8ds_supported says whether
a call is in that slice; rocm_aiter_ops routes it here when
VLLM_ROCM_USE_AITER_FLYDSL_SPARSE_MLA=1.
Functions:
-
flydsl_sparse_mla_fp8ds_fwd–Sparse MLA over an fp8_ds_mla cache,
sparse_mla_fwdsemantics. -
flydsl_sparse_mla_fp8ds_supported–Can
flydsl_sparse_mla_fp8ds_fwdserve thissparse_mla_fwdcall? -
flydsl_sparse_mla_fp8ds_warmup–Compile (and run once on a one-token problem) every listed configuration,
_kv_rows(kv)
¶
The cache as a 2-D [N, 656] uint8 view, or None if it is not flat records.
Takes [N, 656], [N, 1, 656], [N, 1, 1, 656] and an unpadded paged pool [nb, block, 656] of any 1-byte dtype.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla.py
flydsl_sparse_mla_fp8ds_fwd(q, kv_buffer, kv_indptr, kv_indices, softmax_scale, *, kv_lora_rank=512, qk_rope_head_dim=64, has_invalid=False, out=None, return_lse=False)
¶
Sparse MLA over an fp8_ds_mla cache, sparse_mla_fwd semantics.
Parameters:
-
(q¶Tensor) –[T, H, 576] bf16, H <= 16.
-
(kv_buffer¶Tensor) –fp8_ds_mla records (512 e4m3 | 4 f32 per-128 scales | 64 bf16 rope), see
flydsl_sparse_mla_fp8ds_supported. -
(kv_indptr¶Tensor) –[T + 1] CSR offsets into kv_indices. Row q attends
kv_indices[kv_indptr[q] : kv_indptr[q + 1]]; any length >= 0, no alignment needed. int64 is accepted and copied to int32. -
(kv_indices¶Tensor) –flat GLOBAL slot ids.
-
(softmax_scale¶float) –the layer's softmax scale.
-
(kv_lora_rank¶int, default:512) –latent width; only 512 is served.
-
(qk_rope_head_dim¶int, default:64) –rope width; only 64 is served.
-
(has_invalid¶bool, default:False) –entries < 0 anywhere in a row are masked. Without it every entry must be a valid slot.
-
(out¶Tensor | None, default:None) –optional [T, H, >= 512] bf16 destination (strided views are fine); the first 512 columns are written.
-
(return_lse¶bool, default:False) –also return a fresh [T, H] f32 natural-log log-sum-exp of softmax_scale * q.k over the unmasked keys.
A row with no unmasked key gives out = 0 and lse = -inf (the Gluon kernel returns NaN out for such a row).
The first call for a new (H, has_invalid, return_lse) JIT-compiles the
kernel: call flydsl_sparse_mla_fp8ds_warmup before CUDA-graph capture.
The launch itself does no host sync.
Returns:
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
flydsl_sparse_mla_fp8ds_supported(q, kv_buffer, kv_indptr, kv_indices, *, kv_scale=None, kv_lora_rank=512, qk_rope_head_dim=64, kv_splits=None, skip_reduce=False, has_invalid=False, dot_precision='bf16', q_scale=None, out=None, return_lse=False, attn_sink=None, extra_kv=None, extra_indptr=None, extra_indices=None, extra_kv_scale=None, inv_rope_positions=None, inv_rope_cos_sin_cache=None, out_mxfp8=None)
¶
Can flydsl_sparse_mla_fp8ds_fwd serve this sparse_mla_fwd call?
Takes sparse_mla_fwd's arguments. Reads host metadata only (no device
reads, no sync), so it is safe under CUDA-graph capture. has_invalid and
return_lse are accepted with either value.
True iff: gfx950; q is bf16 [T, H, 576] with 1 <= H <= 16, stride(2) == 1, even token/head strides and a 4 B aligned base; kv_buffer has a 16 B aligned base and holds 1-byte fp8_ds_mla records at a 656 B pitch ([N, 656], [N, 1, 656], [N, 1, 1, 656] or an unpadded [nb, block, 656]) of any size (rows are addressed in 64 bits; slot ids are int32); kv_indptr / kv_indices are 1-D int32 or int64 on q's device with T + 1 / < 2^29 entries; out, if given, is bf16 [T, H, >= 512] with stride(2) == 1, even strides and a 4 B aligned base; and none of kv_scale, q_scale, attn_sink, the extra_* segment, the inverse-RoPE / MXFP8 epilogue, kv_splits or skip_reduce is used, with dot_precision "bf16".
Not checkable here (it would need a device read): the per-128 KV scales must be powers of two <= 2^7, which vLLM's fp8_ds_mla writer guarantees for any latent with |x| <= 57344. See the kernel module docstring.
Source code in vllm/models/kimi_k3/amd/ops/flydsl_sparse_mla.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 188 189 190 191 192 193 194 | |
flydsl_sparse_mla_fp8ds_warmup(device=None, heads=(1, 2, 4, 6, 8, 12, 16), has_invalid=(False, True), return_lse=(False, True))
¶
Compile (and run once on a one-token problem) every listed configuration, so no JIT compile lands inside a CUDA-graph capture.