flashinfer.quantization.nvfp4_kv_dequantize_paged¶
- flashinfer.quantization.nvfp4_kv_dequantize_paged(paged_kv_cache: Tensor | Tuple[Tensor, Tensor], kv_cache_sf: Tensor | Tuple[Tensor, Tensor], block_tables: Tensor, seq_lens: Tensor, k_scale: Tensor, v_scale: Tensor, output_k: Tensor, output_v: Tensor, kv_layout: str = 'NHD') None¶
Dequantize a paged NVFP4 KV cache into caller-owned contiguous outputs.
Requires SM80+. This helper gathers pages through
block_tablesand writes dequantized K/V tensors in[batch, max_seq_len, num_heads, head_dim]layout. Tokens at positions>= seq_lens[batch]are left unchanged.- Parameters:
paged_kv_cache (Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]) – The packed NVFP4 paged KV cache. Accepts the same tuple or stacked cache format as paged attention APIs. For tuple input, each tensor has shape
[num_pages, page_size, num_kv_heads, head_dim // 2]whenkv_layout="NHD"and[num_pages, num_kv_heads, page_size, head_dim // 2]whenkv_layout="HND".kv_cache_sf (Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]) – Per-block FP8 E4M3 scales with the same tuple or stacked cache format as
paged_kv_cache, replacinghead_dim // 2withhead_dim // 16.block_tables (torch.Tensor) – Physical page table of shape
[batch, max_pages_per_request]with dtypeint32orint64.seq_lens (torch.Tensor) – Sequence lengths of shape
[batch]with dtypeint32.k_scale (torch.Tensor) – Global dequantization scale tensors of dtype
float32on the same CUDA device as the cache.v_scale (torch.Tensor) – Global dequantization scale tensors of dtype
float32on the same CUDA device as the cache.output_k (torch.Tensor) – Caller-owned output tensors in
[batch, max_seq_len, num_heads, head_dim]layout. Each must be contiguous and have dtypetorch.float16ortorch.bfloat16.output_v (torch.Tensor) – Caller-owned output tensors in
[batch, max_seq_len, num_heads, head_dim]layout. Each must be contiguous and have dtypetorch.float16ortorch.bfloat16.kv_layout (str) – Layout of the paged input cache, either
"NHD"or"HND".
- Returns:
This function writes dequantized K/V values into
output_kandoutput_vin place.- Return type:
None