flashinfer.mla.cake_dsv4_nvfp4_kv_rope_quantize_insert¶
- flashinfer.mla.cake_dsv4_nvfp4_kv_rope_quantize_insert(kv: Tensor, cache: Tensor, slot_mapping: Tensor, positions: Tensor, cos_sin_cache: Tensor, *, compress_ratio: int = 1) None¶
Rotate, quantize and insert latent KV rows into the DeepSeek-V4 NVFP4 cache (KV only).
The compressed-pool and speculative-context writer: row
iis inserted wheni < slot_mapping.numel(), its slot is valid and(positions[i] + 1) % compress_ratio == 0; the RoPE row iscos_sin_cache[positions[i] // compress_ratio * compress_ratio]. Withcompress_ratio=1every addressed row is inserted at its own position. The cache bytes equalflashinfer.mla.nvfp4_quantize_append_sparse_mla_cache()applied to the BF16-rounded roped rows.- Parameters:
kv (torch.Tensor) – Contiguous CUDA BF16
[num_tokens, 512]latent KV rows (unrotated).cache (torch.Tensor) – Destination opaque uint8 NVFP4 paged cache (3-D, HND or NHD; any positive page size; 16-byte-multiple page stride). Only the addressed data rows and scale slots are written.
slot_mapping (torch.Tensor) – Contiguous 1-D CUDA int32 or int64 tensor with at most
num_tokensentries; negative and out-of-range slots are skipped, and the caller may pass-1for non-boundary rows instead of relying oncompress_ratio. A valid slot must not repeat inside one call.positions (torch.Tensor) – Contiguous 1-D CUDA int64
[num_tokens]positions; every inserted row’s cos/sin row must index insidecos_sin_cache(not checked on the device). int32 is rejected rather than converted.cos_sin_cache (torch.Tensor) – Contiguous CUDA fp32
[max_position, 64]table,cos[32] | sin[32].compress_ratio (int) – 1 or 2: the boundary rule and the cos/sin row rule above.
- Returns:
The cache is updated in place;
num_tokens == 0or an emptyslot_mappingreturns without a launch. CUDA-Graph safe (no allocation, no host synchronisation).- Return type:
None