For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
kv_cache_store_padded
def kv_cache_store_padded[cache_t: KVCacheT, //, InputFnType: def[width: Int, alignment: Int](Coord[**?]) -> SIMD[cache_t.dtype, width] & RegisterPassable & ImplicitlyCopyable](cache: cache_t, input_shape: Coord[*input_shape.element_types], valid_lengths: TileTensor[.uint32, Engine=valid_lengths.Engine, linear_idx_type=valid_lengths.linear_idx_type], input_fn: InputFnType, 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). - InputFnType (
def[width: Int, alignment: Int](Coord[**?]) -> SIMD[cache_t.dtype, width]&RegisterPassable&ImplicitlyCopyable): Type ofinput_fn(inferred).
Args:
- cache (
cache_t): The KVCache object to write key or value entries into. - input_shape (
Coord[*input_shape.element_types]): Shape of the input as a 4DCoord(batch, tokens, heads, head_size). - valid_lengths (
TileTensor[.uint32, Engine=valid_lengths.Engine, linear_idx_type=valid_lengths.linear_idx_type]): Tensor with shape (batch_size,) giving the number of valid tokens per batch; rows beyond this are skipped. - input_fn (
InputFnType): Callback that loads a SIMD vector of cache-typed elements at the given 4D index. - context (
DeviceContext): The call context pointer, passed by the graph compiler.