vllm.models.deepseek_v41.common.ops.fused_compress_quant_cache
¶
V4.1 state saving/compression and independently schedulable cache insertion.
Functions:
-
fused_save_compress_norm–Pool each closed group into a normalized BF16 latent; save FP32 states.
-
rope_quant_insert–Apply GPT-J RoPE and publish a latent to the compressed KV cache.
_rope_quant_insert_mxfp8_kernel(latent, positions, cos_sin, cache, cache_slots, COS_STRIDE, CACHE_STRIDE, CACHE_BLOCK, COMPRESS_RATIO, SANITIZE_CACHE_NANS)
¶
V4.1 record: RoPE first, then MXFP8-quantize all 512 dims.
The RoPE dims are quantized here too, so unlike the V4 kernel the rotation has to happen before the scales are picked.
Source code in vllm/models/deepseek_v41/common/ops/fused_compress_quant_cache.py
_rope_quant_insert_nvfp4_kernel(latent, positions, cos_sin, cache, cache_slots, COS_STRIDE, CACHE_STRIDE, CACHE_BLOCK, COMPRESS_RATIO, SANITIZE_CACHE_NANS)
¶
V4.1 NVFP4 record: RoPE, then e2m1 with one e4m3 scale per 16 dims.
The scale is amax / 6 (6 is e2m1's largest magnitude) clamped to the
e4m3 range, with no per-tensor scale on top.
Source code in vllm/models/deepseek_v41/common/ops/fused_compress_quant_cache.py
fused_save_compress_norm(kv_score, positions, state_cache, slot_mapping, query_start_loc, token_to_req_indices, rms_norm_weight, rms_norm_eps, compress_ratio, latent_out)
¶
Pool each closed group into a normalized BF16 latent; save FP32 states.
The latent feeds the main-cache insert and the indexer K path, which the attention layer schedules on separate streams.
Ratio 2 keeps one ring block per request holding the open group's rows:
position p lives in row p % capacity and slot_mapping encodes
block * capacity + p % capacity. The grid has one program per request
followed by one per pair of packed tokens. A request program handles the
group that the chunk's first token closes with its predecessor's ring row,
then stores the chunk's last capacity rows to the ring; because the
same program does both, ring reads and writes never race. A pair program
handles the group that ends inside its pair, reading both rows from the
raw input. Ratio 1 has no ring and one program per token; slot_mapping
then only marks valid tokens.
Parameters:
-
(kv_score¶Tensor) –FP32 [tokens, 512] for CR1, [tokens, 1024] for CR2.
-
(positions¶Tensor) –Absolute positions of the packed request tokens.
-
(state_cache¶Tensor | None) –Ring FP32 [blocks, capacity, 1024] KV/score states (CR2).
-
(slot_mapping¶Tensor) –Ring slots (CR2) or main-cache slots (CR1).
-
(query_start_loc¶Tensor | None) –[num_reqs + 1] token offsets of each request's chunk.
-
(token_to_req_indices¶Tensor | None) –Request indices for the packed token rows.
-
(rms_norm_weight¶Tensor) –BF16 [512] normalization weight.
-
(rms_norm_eps¶float) –RMSNorm epsilon.
-
(compress_ratio¶int) –Group size, either 1 or 2.
-
(latent_out¶Tensor) –BF16 [tokens, 512], written only at valid group boundaries.
Source code in vllm/models/deepseek_v41/common/ops/fused_compress_quant_cache.py
rope_quant_insert(latent, positions, cos_sin_cache, kv_cache, slot_mapping, compress_ratio, fp8_scale=None)
¶
Apply GPT-J RoPE and publish a latent to the compressed KV cache.
The BF16 latent supplies both NoPE quantization and RoPE input. It is read
only for valid slots at group boundaries. The cache dtype selects the
layout: uint8 is a paged FlashMLA layout, whose record the per-token
byte width names -- 584 B for V4 (576 value bytes and eight segregated
UE8M0 scale bytes, including one zero padding scale), 528 B for V4.1
(512 MXFP8 value bytes covering the RoPE dims too, then 16 UE8M0 scales of
32 dims each), or 288 B for V4.1 NVFP4 (256 bytes of e2m1 pairs then 32
e4m3 scales of 16 dims each), which only the compressed cache uses.
bfloat16 and float8_e4m3fn are the plain [448 NoPE | 64 RoPE] rows
read by FlashInfer, the latter scaled by the per-tensor fp8_scale.
Source code in vllm/models/deepseek_v41/common/ops/fused_compress_quant_cache.py
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 | |