vllm.models.kimi_k3.nvidia.ops.dsa_indexer_mxfp4
¶
MXFP4 writers of the Kimi K3.1 DSA indexer: the key LayerNorm + MXFP4 quant + cache insert (standalone, and fused into the DSA prologue) and the MXFP4 query quant.
Format (DeepSeek V4's MXFP4 indexer cache, what DeepGEMM's fp8_fp4_*mqa_logits
read): one UE8M0 scale 2^ceil(log2(amax / 6)) per 32 values, E2M1 values (round to
nearest even, saturating), two per byte with the even element in the low nibble. A
cache block of B tokens is [B x D/2 E2M1 | B x D/32 UE8M0], D/2 + D/32 =
68 B/token for D = 128. The query is [T, P, D/2] E2M1 with its four UE8M0
bytes per head packed into one int32 (q_scale [T, P]); the head weights take only
weight_scale (the MX scales stay in the logits MMA).
Used only with an explicit --attention-config '{"indexer_kv_dtype": "mxfp4"}'
(kimi_k3_indexer_uses_fp4); the default FP8 cache keeps the writers of
dsa_indexer.py, whose LayerNorm this key insert repeats op for op. Triton only (no
CuTe import), so every engine of a P/D pair writes the same bytes.
Functions:
-
mxfp4_fused_prologue–dsa_fused_prologuefor the MXFP4 indexer cache, in one launch: the -
mxfp4_k_norm_quant_insert–indexer_k_norm_quant_insertfor the MXFP4 cache: LayerNorm + MXFP4 -
mxfp4_q_quant–Quantize
index_q[T, H, D]to MXFP4 (one ue8m0 scale per 32
_mxfp4_fused_prologue_kernel(q_c_ptr, q_c_stride, q_norm_w_ptr, q_out_ptr, kv_c_ptr, kv_c_stride, kv_norm_w_ptr, kv_out_ptr, k_pe_ptr, k_pe_stride, index_k_ptr, index_k_stride, k_norm_w_ptr, k_norm_b_ptr, eps, mla_slot_ptr, num_mla_slots, mla_cache_ptr, mla_scale_ptr, mla_rope_ptr, mla_block_size, mla_block_stride, mla_entry_stride, index_slot_ptr, num_index_slots, index_cache_ptr, index_block_size, index_block_stride, topk_ptr, topk_stride, Q_DIM, Q_BLOCK, KV_DIM, ROPE_DIM, INDEX_DIM, TOPK, TOPK_BLOCK, USE_PDL, FP8_MAX, USE_FNUZ)
¶
The stock FP8 prologue (dsa_indexer._dsa_fused_prologue_kernel) with its program 0, the indexer key insert, writing MXFP4: programs 1-3 (fp8_ds_mla insert, q_a RMSNorm, top-k fill) run the stock kernel's own code.
Source code in vllm/models/kimi_k3/nvidia/ops/dsa_indexer_mxfp4.py
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 | |
_mxfp4_q_quant_kernel(q_ptr, q_stride0, q_stride1, w_ptr, w_stride, q_out_ptr, q_out_stride0, q_scale_ptr, q_scale_stride0, w_out_ptr, w_out_stride, weight_scale, num_heads, HEAD_DIM, HEADS_PER_PROGRAM, EVEN_HEADS)
¶
HEADS_PER_PROGRAM heads of one token. The MXFP4 blocks never straddle two heads, so the heads quantize as one row, each block exactly as alone.
Source code in vllm/models/kimi_k3/nvidia/ops/dsa_indexer_mxfp4.py
_mxfp4_quant(x, HEAD_DIM)
¶
MXFP4 of one HEAD_DIM fp32 row, same math as DeepSeek V4's
_quantize_mxfp4_pair. Returns (packed [HEAD_DIM // 2] uint8 with the
even element in the low nibble, ue8m0 [HEAD_DIM // 32] uint8).
cutedsl/dsa/index.py (mxfp4_scale) replays the PTX Triton emits for this scale: keep the two in step.
Source code in vllm/models/kimi_k3/nvidia/ops/dsa_indexer_mxfp4.py
mxfp4_fused_prologue(q_c, kv_c, k_pe, index_k, q_norm_weight, kv_norm_weight, k_norm_weight, k_norm_bias, eps, topk_indices_buffer, mla_cache, mla_slot_mapping, index_cache, index_slot_mapping)
¶
dsa_fused_prologue for the MXFP4 indexer cache, in one launch: the
q_a / kv_a RMSNorms, the fp8_ds_mla insert of [kv_c_normed | k_pe] and
the -1 fill of the top-k rows (the stock kernel's code), and the indexer key
LayerNorm + MXFP4 insert.
mla_cache ([num_blocks, block_size, 656]) and index_cache
([num_blocks, block_size, indexer_cache_entry_bytes]) are uint8, possibly
strided page views of a packed cache; None (profile runs) skips the
insert. Rows past a slot mapping or with a negative slot are not inserted.
Returns (q_c_normed, kv_c_normed).
Source code in vllm/models/kimi_k3/nvidia/ops/dsa_indexer_mxfp4.py
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 | |
mxfp4_k_norm_quant_insert(k, norm_weight, norm_bias, norm_eps, slot_mapping, kv_cache, topk_indices_buffer, num_tokens)
¶
indexer_k_norm_quant_insert for the MXFP4 cache: LayerNorm + MXFP4
quant + cache insert of the indexer key, and the -1 fill of the top-k rows
[:num_tokens].
kv_cache is [num_blocks, block_size, indexer_cache_entry_bytes] uint8,
possibly a strided page view of a packed cache. Rows past slot_mapping or
with a negative slot are not inserted.
Source code in vllm/models/kimi_k3/nvidia/ops/dsa_indexer_mxfp4.py
mxfp4_q_quant(index_q, index_weights, weight_scale, padded_num_heads)
¶
Quantize index_q [T, H, D] to MXFP4 (one ue8m0 scale per 32
values), the query format of the MXFP4 indexer key cache, and scale
index_weights [T, H] by weight_scale.
Returns (q_packed [T, P, D // 2] uint8, q_scale [T, P] int32 packing the
four ue8m0 bytes of each head, weights [T, P] fp32) where P =
padded_num_heads; heads [H, P) are zero.