vllm.models.muse_spark.nvidia.specialized_decode.cutedsl.draft.context
¶
The Muse Spark DSpark draft's context K/V chain around its K/V projection, as two CuTe kernels.
MuseSparkDSparkModel.precompute_and_store_context_kv runs the hidden norm,
one input norm per draft layer and a stack, then the batched K/V projection
(cuBLAS), then the K-norm, RoPE and one cache insert per layer. Here the chain
before the projection is one kernel (ContextNorms) and the chain after it
is another (ContextKvStore); the projection stays the stock torch.bmm.
Both are bitwise equal to the stock chain on contiguous rows:
- the norms: one CTA of 256 threads per (row, layer), the row norm of
common/row_norm.py(the stock single-tilefused_rmsnorm_fwd), the hidden norm's output rounded to BF16 before the layer norm reads it, as the stock chain stores it; - the store: one warp per (row, layer), lane j holding the GPT-J pair (2 j, 2 j + 1) of every head: the K-norm in the order of torch's CUDA mean over a 64-wide row (a torch that reduces in another order breaks the bitwise tests), the BF16 key, GPT-J RoPE as the CUDA rotary op computes it, and the cache insert.
Every FP32 op is explicit PTX with its rounding, so nothing contracts but where the stock chain does.
Classes:
-
ContextKvStore–The K-norm with
eps, GPT-J RoPE (withrope) and cache insert of -
ContextNormConstants–Compile-time constants of the norms kernel.
-
ContextNorms–stack([pre_norm_l(hidden_norm(x)) for l])as one kernel, bound to
Functions:
-
compile_context_kv_store–cute.compile the store kernel of
headsKV heads (before CUDA graph -
compile_context_norms–cute.compile the norms kernel of one constant set (before CUDA graph
-
context_norm_constants–The constants of the norms kernel, or ValueError where it does not
ContextKvStore
¶
The K-norm with eps, GPT-J RoPE (with rope) and cache insert of
num_heads KV heads per layer, as the stock chain after the K/V
projection. Compiles at construction (before CUDA graph capture); a call
is graph-capturable.
Methods:
-
__call__–Insert
L = len(caches)layers' context K/V rows into their
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
__call__(k, v, positions, slots, cos_sin_cache, caches)
¶
Insert L = len(caches) layers' context K/V rows into their
caches, the operands as ContextKV.store checks them.
k and v are bf16 [L, T, H, 64] views of the K/V
projection's output, unit stride over the last dim, 64 over the one
before, even strides and 4-byte aligned. slots holds each
layer's contiguous int64 slot mapping, all of one length; the first
len(slots[0]) rows are inserted, as reshape_and_cache_flash
does; a negative slot skips its row. positions is contiguous
int64. k gets the weightless K-norm, then GPT-J RoPE at
positions from cos_sin_cache (contiguous bf16
[max_position, 64], cos then sin; None without rope).
caches holds each layer's key-cache view [num_blocks,
block_size, H, 64] of the attention backend's bf16 cache
[num_blocks, H, block_size, 128] (K then V in the last dim), of
one shape and stride, even strides, 4-byte aligned and fewer than
2^31 slots. Up to MAX_LAYERS_PER_LAUNCH layers take one launch.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
ContextNormConstants
¶
Bases: NamedTuple
Compile-time constants of the norms kernel.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
ContextNorms
¶
stack([pre_norm_l(hidden_norm(x)) for l]) as one kernel, bound to
its norms: the hidden norm's weight [D] and the layers' input-norm
weights [L, D] (BF16 or FP32; None for weightless norms), eps, gain
centers and whether each weight scales the input (else the norm's
output); constants their context_norm_constants where the caller
has them. Compiles at construction (before CUDA graph capture); a call
is graph-capturable.
Methods:
-
__call__–The norms of
x, contiguous BF16[T, D]with T >= 1 and D
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
__call__(x)
¶
The norms of x, contiguous BF16 [T, D] with T >= 1 and D
8192 (the norms' single tile; the caller checks it): BF16
[L, T, D].
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
_ContextKvStoreKernel
¶
Grid (rows, layers), one warp: one (row, layer) per CTA.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
_ContextNormsKernel
¶
Grid (rows, layers), THREADS threads: one (row, layer) per CTA.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
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 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 | |
_rope(x, y, c, s)
¶
The CUDA rotary op's GPT-J pair (x * c - y * s, y * c + x * s) in its contraction (traced inline).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
_rows_view(tensor)
¶
rows_view of BF16 or FP32 rows of H (32-byte aligned in FP32).
_sum_squares_64(k0, k1)
¶
x.pow(2).sum(-1) of one 64-wide head whose pair (2 j, 2 j + 1) lane
j holds, in torch's CUDA mean order: the squares of elements i and i + 32
added, then the 32 sums folded by halves (a lane butterfly, then even +
odd). Every lane gets it (traced inline).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
compile_context_kv_store(heads, rope, enable_pdl)
cached
¶
cute.compile the store kernel of heads KV heads (before CUDA graph
capture); rows, layers, strides, the block size and eps are runtime
arguments.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
compile_context_norms(constants)
cached
¶
cute.compile the norms kernel of one constant set (before CUDA graph capture); rows, layers, eps and gain centers are runtime arguments.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/context.py
context_norm_constants(hidden_weight, pre_weights, *, hidden_input_scale=False, pre_input_scale=False)
¶
The constants of the norms kernel, or ValueError where it does not take the weights.