IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

unfused_qkv_matmul_ragged_paged_gguf_quantized

def unfused_qkv_matmul_ragged_paged_gguf_quantized[dtype: DType, params: KVCacheStaticParams, page_size: Int, //, quantization_encoding_q: StringSlice[ImmStaticOrigin], quantization_encoding_k: StringSlice[ImmStaticOrigin], quantization_encoding_v: StringSlice[ImmStaticOrigin]](hidden_state: LayoutTensor[DType.float32, element_layout=hidden_state.element_layout, layout_int_type=hidden_state.layout_int_type, linear_idx_type=hidden_state.linear_idx_type, masked=hidden_state.masked, alignment=hidden_state.alignment], input_row_offsets: LayoutTensor[DType.uint32, element_layout=input_row_offsets.element_layout, layout_int_type=input_row_offsets.layout_int_type, linear_idx_type=input_row_offsets.linear_idx_type, masked=input_row_offsets.masked, alignment=input_row_offsets.alignment], q_weight: LayoutTensor[DType.uint8, element_layout=q_weight.element_layout, layout_int_type=q_weight.layout_int_type, linear_idx_type=q_weight.linear_idx_type, masked=q_weight.masked, alignment=q_weight.alignment], k_weight: LayoutTensor[DType.uint8, element_layout=k_weight.element_layout, layout_int_type=k_weight.layout_int_type, linear_idx_type=k_weight.linear_idx_type, masked=k_weight.masked, alignment=k_weight.alignment], v_weight: LayoutTensor[DType.uint8, element_layout=v_weight.element_layout, layout_int_type=v_weight.layout_int_type, linear_idx_type=v_weight.linear_idx_type, masked=v_weight.masked, alignment=v_weight.alignment], kv_collection: PagedKVCacheCollection[dtype, params, page_size, scale_dtype_=kv_collection.scale_dtype_, quantization_granularity_=kv_collection.quantization_granularity_], layer_idx: UInt32, output: LayoutTensor[DType.float32, element_layout=output.element_layout, layout_int_type=output.layout_int_type, linear_idx_type=output.linear_idx_type, masked=output.masked, alignment=output.alignment], ctx: DeviceContext)

Performs a quantized matmul, writing the output into a mutable PagedKVCacheCollection object.

Unlike the un-quantized version (kv_matmul_ragged_continuous_batching), this implementation does not concat the q, k, and v weights together. Instead, it performs three matmuls. This allows the q, k, and v weights to have different quantization encodings.

This is only supported on CPU.

Parameters:

  • ​dtype (DType): Element type of the KV cache collection entries (inferred).
  • ​params (KVCacheStaticParams): Static shape parameters of the paged KV cache, including the attention-head count, per-head size, and MLA flag (inferred).
  • ​page_size (Int): Number of tokens stored per cache page (inferred).
  • ​quantization_encoding_q (StringSlice[ImmStaticOrigin]): GGUF quantization encoding name applied to the q_weight tensor.
  • ​quantization_encoding_k (StringSlice[ImmStaticOrigin]): GGUF quantization encoding name applied to the k_weight tensor.
  • ​quantization_encoding_v (StringSlice[ImmStaticOrigin]): GGUF quantization encoding name applied to the v_weight tensor.

Args: