vllm.models.deepseek_v41.amd.ops.swa_decode_meta
¶
One-launch decode build of the DeepSeek V4.1 SWA metadata on ROCm.
DeepseekV41ROCMAiterSparseSWAMetadataBuilder.build runs once per SWA KV cache group, which is 8 times a step for DeepSeek-V4.1-Flash at TP 4. For a decode batch that this file does not take, each build launches 8 small kernels: torch.ge for is_valid_token, the zero fill of the unused decode_swa_lens, _compute_swa_indices_and_lens_kernel, the ragged row count, torch.cumsum, the ragged compaction and 2 copies into the CUDA graph buffers. On MI325X each took about 4.2 us, so at 128k context the 8 builds held the GPU for 281 us of every step before the decode graph could start.
_decode_swa_meta_kernel writes the same tensors with one program: the dense window indices and lengths, is_valid_token, the zero lengths after the batch, and the ragged indices and indptr directly into the graph buffers. It does not write the ragged entries past indptr[-1]. _copy_ragged_to_graph_buffers copies them from an uninitialized tensor, and the attention kernels read only up to indptr.
The DSpark draft's 3 layers build their non-causal block the same way, with ComputeDSparkNoncausalSWAIndicesKernel in place of the window kernel. That is 3 more builds of 8 launches after every target step.
On gfx942 with --monokernel (ops.enabled()), decode
batches of up to MAX_ROWS rows, causal or the draft block, use it. Other
batches take the rest of DeepseekV41ROCMAiterSparseSWAMetadataBuilder.build.
tests/kernels/models/amd/test_dsv41_gfx942_decode_meta.py compares it with the vLLM ops
that it replaces.
Functions:
-
build–Return the ROCm SWA metadata of a decode batch, causal or the DSpark
-
launch–Write is_valid[:num_tokens], indices[:num_tokens], all of lens, and
build(builder, common_prefix_len, cam, fast_build, replay_start, metadata_cls)
¶
Return the ROCm SWA metadata of a decode batch, causal or the DSpark draft block, built with one launch, or None when the batch needs the rest of DeepseekV41ROCMAiterSparseSWAMetadataBuilder.build.
Source code in vllm/models/deepseek_v41/amd/ops/swa_decode_meta.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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 296 297 | |
launch(slot_mapping, is_valid, indices, lens, ragged, indptr, query_start_loc, seq_lens, token_to_req, block_table, replay_start, num_tokens, window_size, block_size, noncausal=False)
¶
Write is_valid[:num_tokens], indices[:num_tokens], all of lens, and the ragged form into ragged and indptr, in one launch. noncausal builds the DSpark draft block's rows, whose width is the index tensor's.