vllm.models.deepseek_v41.nvidia.specialized_decode.ampere.mqa_logits
¶
The DeepSeek-V4.1 indexer logits on SM80, in CuTe DSL.
The indexer scores each query token m against keys n of its request:
logits[m, n] = sum_h weights[m, h] * relu(q[m, h] . k[n])
with MXFP4 queries (H heads of 128 dims) and MXFP4 keys (128 dims, one
UE8M0 scale per 32). MqaLogits computes one query token per CTA row of
the grid and a run of 64-key tiles per CTA: it decodes the token's queries
once into a BF16 tile [H, 128] in shared memory, then per key tile decodes
the keys into [64, 128], multiplies them on mma.sync BF16 tensor cores
(ldmatrix operands, FP32 accumulation; warps split the keys, 8 each),
applies the ReLU and the head weights to the accumulators and sums over the
heads with warp shuffles. Decoding is exact (codecs.py), so the result
differs from reference.mqa_logits only in the FP32 summation order, and
a key's score does not depend on which CTA computes it.
The grid is (splits, rows): CTA split of a row takes an equal share,
ceil(tiles / splits) consecutive tiles, of the row's own key tiles, so a
row's length (read on the device) bounds the work and a CUDA graph captured
for the longest rows wastes nothing on shorter ones. Prefill passes enough
splits for at most 8 tiles per CTA; decode passes splits for a few CTAs per
SM, whatever the logits width.
A speculative decode step scores several tokens of each request against the
same keys. A decode launch may group group consecutive rows (equal block
tables) into one CTA: its query tile is [group * H, 128], each key tile
is decoded once for the group, and the tile range covers the group's longest
row. Every row's scores are summed in the same order as alone, so grouping
changes no bit.
The keys come from one of two sources, chosen at compile time:
- ragged (prefill): the gathered keys of the chunk, values
[N, 64]and scales[N, 4]; rowmscores keys[ks[m], ke[m])into columns0 ..; - paged (decode): the indexer key cache, whose pages hold
block_size64-byte values then their 4-byte scales; rowmscores the firstlens[m]keys of requestm // next_n's block table.
Columns past a row's length are not written.
A decode step's candidate consumers (the two-level selection) score only
their row's candidate blocks of block keys (candidate_mqa_logits),
which the stock layer instead masks to -inf in dense logits: row m's
compact column c is key block * candidates[m, c // block] + c % block,
so a row costs its candidates (2048 * 8 keys) whatever its length. The
kernel scores the row's first min(count, ceil(len / block)) candidate
slots, where its valid blocks must lie, and writes that many blocks' keys as
the row's compact length; a -1 slot or a key at or past the row's length
scores -inf. A key scores the same bits as in a dense launch. Compact rows also
take SM90's FP8 index cache (pages of 128-byte E4M3 keys, then their FP32
scales) and FP8 queries whose scales the head weights carry: a key then
scores scale * sum_h weights[m, h] * relu(q[m, h] . k).
Classes:
-
MqaLogits–MXFP4 (or, compact, FP8) indexer logits; see the module docstring.
Functions:
-
candidate_mqa_logits–Compact paged logits of the candidate keys only, and the rows' compact
-
mqa_logits–Ragged logits
[rows, max_len](FP32): rowmscores keys -
paged_mqa_logits–Paged logits
[rows, max_len](FP32, rows 16-byte aligned): row
MqaLogits
¶
MXFP4 (or, compact, FP8) indexer logits; see the module docstring.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
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 | |
_check_query(q_values, q_scales, weights)
¶
(rows, heads) of contiguous MXFP4 queries [rows, heads, 64] with
scales [rows, heads, 4] and FP32 weights [rows, heads].
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
_decode_e4m3_chunk(values, chunk, out)
¶
Dims 8 chunk .. 8 chunk + 7 of an E4M3 row (128 bytes at
values) into out[0:8] as BF16.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
_decode_mxfp4_chunk(values, scales, chunk, out)
¶
Dims 8 chunk .. 8 chunk + 7 of an MXFP4 row (64 value bytes at
values, 4 scale bytes at scales) into out[0:8] as BF16.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
_decode_splits_target(device_index, group)
cached
¶
CTAs a decode launch spreads its rows' tiles over.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
_fake(dtype, align)
¶
A placeholder pointer for compilation.
_kernel(device_index, paged, heads, candidate_block=0, group=1, fp8=False)
cached
¶
MqaLogits compiled for a device, key source, head count, candidate
block size (0: dense rows), row group and key format.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
_pointer(dtype, tensor, align)
¶
A CuTe DSL global-memory pointer to tensor's data.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
candidate_mqa_logits(q_values, q_scales, k_cache, weights, lens, block_table, next_n, candidates, candidate_block_size, splits=None)
¶
Compact paged logits of the candidate keys only, and the rows' compact
lengths (int32 [rows]). candidates (int32 [rows, count]) lists
row m's blocks of candidate_block_size keys, in any order and
-1 padded, with every valid block within the row's first
min(count, ceil(lens[m] / candidate_block_size)) slots (the slots
scored). Column c of row m (FP32
[rows, count * candidate_block_size], rows 16-byte aligned) scores key
candidate_block_size * candidates[m, c // candidate_block_size] +
c % candidate_block_size of request m // next_n as
paged_mqa_logits does, or -inf for a -1 slot or at or past
lens[m]; the compact length counts the scored slots' keys, and later
columns are not written.
The queries are MXFP4 as in paged_mqa_logits, or with q_scales
None FP8 ([rows, heads, 128], their scales in weights) against
the FP8 cache ([blocks, block_size, ...] uint8 pages of 128-byte keys,
then their FP32 scales). splits (CTAs per row) defaults to about eight
CTAs per SM over all rows.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
mqa_logits(q_values, q_scales, k_values, k_scales, weights, row_starts, row_ends, max_len)
¶
Ragged logits [rows, max_len] (FP32): row m scores keys
[row_starts[m], row_ends[m]) of k_values [N, 64] /
k_scales [N, 4] (uint8, contiguous).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/mqa_logits.py
paged_mqa_logits(q_values, q_scales, k_cache, weights, lens, block_table, next_n, max_len, splits=None, group=1)
¶
Paged logits [rows, max_len] (FP32, rows 16-byte aligned): row
m scores the first lens[m] keys of request m // next_n in the
indexer key cache k_cache ([blocks, block_size, ...] uint8 pages of
68-byte keys). Each group consecutive rows (tokens of one request:
equal block tables) share a CTA and the keys it decodes. splits (CTAs
per group) defaults to about eight CTAs per SM over all groups.