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_padded
def kv_cache_store_padded[cache_t: KVCacheT, //, target: StringSlice[ImmStaticOrigin], input_fn: def[width: Int, alignment: Int](idx: IndexList[Int(4)]) capturing thin -> SIMD[cache_t.dtype, width]](cache: cache_t, input_shape: IndexList[Int(4)], valid_lengths: LayoutTensor[DType.uint32, element_layout=valid_lengths.element_layout, layout_int_type=valid_lengths.layout_int_type, linear_idx_type=valid_lengths.linear_idx_type, masked=valid_lengths.masked, alignment=valid_lengths.alignment], context: DeviceContext)
Stores padded 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, skipping tokens beyond each batch's valid length.
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(4)]) capturing thin -> SIMD[cache_t.dtype, width]): Compile-time callback that loads a SIMD vector of cache-typed elements at the given 4D index.
Args:
- βcache (
cache_t): The KVCache object to write key or value entries into. - βinput_shape (
IndexList[Int(4)]): Shape of the input as a 4D index list (batch, tokens, heads, head_size). - βvalid_lengths (
LayoutTensor[DType.uint32, element_layout=valid_lengths.element_layout, layout_int_type=valid_lengths.layout_int_type, linear_idx_type=valid_lengths.linear_idx_type, masked=valid_lengths.masked, alignment=valid_lengths.alignment]): Tensor with shape (batch_size,) giving the number of valid tokens per batch; rows beyond this are skipped. - βcontext (
DeviceContext): The call context pointer, passed by the graph compiler.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!