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

kv_cache_store_ragged

def kv_cache_store_ragged[cache_t: KVCacheT, //, target: StringSlice[ImmStaticOrigin], input_fn: def[width: Int, alignment: Int](idx: IndexList[Int(3)]) capturing thin -> SIMD[cache_t.dtype, width]](cache: cache_t, input_shape: IndexList[Int(3)], 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], context: DeviceContext)

Stores ragged input values into a paged KV cache via an elementwise kernel.

Invokes the supplied input_fn to load values and writes them into the cache at positions determined by the per-batch cache lengths and input row offsets.

Parameters:

  • ​cache_t (KVCacheT): The KV cache type used to store key or value entries (inferred).
  • ​target (StringSlice[ImmStaticOrigin]): Compilation target string used to dispatch GPU versus CPU paths.
  • ​input_fn (def[width: Int, alignment: Int](idx: IndexList[Int(3)]) capturing thin -> SIMD[cache_t.dtype, width]): Compile-time callback that loads a SIMD vector of cache-typed elements at the given 3D index.

Args: