vllm.models.kimi_k3.nvidia.specialized_decode.runtime.decode
¶
The specialized decode executor over the stock Kimi K3 backbone: one routing decision per step, then every layer's prepared providers in one loop.
Classes:
-
SpecializedDecode–Built once the weights are loaded; owns every prepared provider, the
Functions:
-
attention_layer–The registered attention layer of a decoder's attention: a K3.1 DSA layer's
-
decode_metadata–One layer's metadata if this step is a pure decode (q = 1) or a uniform
-
is_uniform_verify–Whether every request of the b // q graph rows verifies q tokens (FULL graphs
SpecializedDecode
¶
Built once the weights are loaded; owns every prepared provider, the
mailboxes and the decode buffers. Reads the backbone, never modifies it (but
for the deferred RecoverSSM's per-instance KDA verify, recoverssm.state).
Methods:
-
bind_model_state–Install the runner-state side of the deferred RecoverSSM on the model
-
build_dep–DEP: no full specialized step (its MoE, o-projection and AttnRes
-
build_providers–Every layer's attention and feed-forward providers, the model's mailboxes
-
normalize–A stock step's output with the backbone's final norm applied, as the
-
plan–This step's decode plan, or None to run the stock forward instead.
-
prepare_kv–Compile each layer's cores for its bound KV cache layout. The memory
-
process_weights_after_loading–After a weight reload: re-derive, in place, the copies built from the
-
run–Normalized hidden states (and the aux streams) of a planned step.
-
run_wide–A wide step: the stock decoder layer loop (KimiLinearModel.forward without
-
wide_batches–The wide step rows whose
kindattention layers run the specialized
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
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 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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
bind_model_state(state)
¶
Install the runner-state side of the deferred RecoverSSM on the model
runner state (recoverssm.state.install_model_state).
build_dep(rounded)
¶
DEP: no full specialized step (its MoE, o-projection and AttnRes
providers are TP8 / TP16 ones); every decode or uniform verify step of up
to the KV cache dtype's DEP_ROWS rows runs run_wide with the DEP_KINDS
attention layers specialized at TP1 (runtime.dep.DepAttention), the rest
stock.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
build_providers()
¶
Every layer's attention and feed-forward providers, the model's mailboxes and the prefetch side stream. All collective allocations, weight packing and kernel compiles finish here, before KV binding and CUDA graph capture.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
normalize(output)
¶
A stock step's output with the backbone's final norm applied, as the specialized decode's last AttnRes applies it; the aux streams stay pre-norm.
Runs in chunks of at most 255 rows: the stock RMSNorm kernel reduces with
1024-thread blocks below 256 rows and 256-thread blocks above, so chunking keeps
the reduction order compute_logits uses for the few sampled rows, and
prefill logits match stock.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
plan(positions, intermediate_tensors)
¶
This step's decode plan, or None to run the stock forward instead.
Steps that run the stock forward:
- pipeline-parallel stage inputs (intermediate_tensors);
- token counts without prepared providers (not in batches, and not a
wide verify step: q > 1 and in wide, the rows past the step cap
that some attention layer kind's projection and core take, run_wide);
- steps before prepare_kv bound the KV cache (the memory profiling's
cache is never prepared);
- steps outside a CUDA graph capture (profiling, warmup and the warmup run
before each capture), so every stock kernel runs before its capture;
- PIECEWISE steps, keyed by token count alone and so captured as stock;
- steps with prompt rows (prefills, chunked prefills, fresh prompts);
- speculative steps whose requests do not all verify q tokens (partial
drafts, verify rows mixed with plain decode rows).
Every predicate is the same on all TP ranks: the mailboxes of the specialized decode need every rank to take the same path.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
prepare_kv()
¶
Compile each layer's cores for its bound KV cache layout. The memory profiling's throwaway cache is left unprepared (its compiles would all be thrown away: every KV-dependent kernel is specialized to its cache's block count), so its steps run the stock forward; the worker records the real cache's block count before binding it, the profiling one only after.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
process_weights_after_loading()
¶
After a weight reload: re-derive, in place, the copies built from the weights. Everything else reads the backbone's tensors directly, which a reload refills at the same addresses.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
run(step, input_ids, inputs_embeds)
¶
Normalized hidden states (and the aux streams) of a planned step.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
run_wide(step, input_ids, inputs_embeds)
¶
A wide step: the stock decoder layer loop (KimiLinearModel.forward without pipeline or sequence parallelism: AttnRes, o_proj + all-reduce, MoE / dense MLP), with the attention layers whose kind serves this many rows running the specialized input projection and core instead of the stock module's.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
wide_batches(kind)
¶
The wide step rows whose kind attention layers run the specialized
projection and core.
attention_layer(module)
¶
The registered attention layer of a decoder's attention: a K3.1 DSA layer's inner sparse MLA layer, else the module itself.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
decode_metadata(attention, context, q, b)
¶
One layer's metadata if this step is a pure decode (q = 1) or a uniform verify step of b tokens, else None.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/runtime/decode.py
is_uniform_verify(md, q, b)
¶
Whether every request of the b // q graph rows verifies q tokens (FULL graphs pad whole requests: KDA stages NULL state rows, MLA zero-length decodes).