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
mla_prefill_plan_kernel
def mla_prefill_plan_kernel[BufferRowOffsetsLayoutType: TensorLayout, CacheOffsetsLayoutType: TensorLayout, BufferLengthsLayoutType: TensorLayout, InputRowOffsetsLayoutType: TensorLayout, cache_t: KVCacheT](buffer_row_offsets: TileTensor[DType.uint32, BufferRowOffsetsLayoutType, MutUntrackedOrigin], cache_offsets: TileTensor[DType.uint32, CacheOffsetsLayoutType, MutUntrackedOrigin], buffer_lengths: TileTensor[DType.int32, BufferLengthsLayoutType, MutUntrackedOrigin], input_row_offsets: TileTensor[DType.uint32, InputRowOffsetsLayoutType, ImmUntrackedOrigin], k_cache: cache_t, buffer_token_size: UInt32)
Plans how to process a batch of varying-length sequences through a fixed-size buffer.
For each sequence, computes the per-chunk buffer row offsets, cache offsets, and total buffer lengths needed to divide the cached plus new tokens into fixed-size chunks aligned to the page size, enabling the MLA prefill kernel to process sequences that exceed the buffer in multiple iterations.
Parameters:
- βBufferRowOffsetsLayoutType (
TensorLayout): Compile-time layout ofbuffer_row_offsets(inferred). - βCacheOffsetsLayoutType (
TensorLayout): Compile-time layout ofcache_offsets(inferred). - βBufferLengthsLayoutType (
TensorLayout): Compile-time layout ofbuffer_lengths(inferred). - βInputRowOffsetsLayoutType (
TensorLayout): Compile-time layout ofinput_row_offsets(inferred). - βcache_t (
KVCacheT): Paged KV cache type backingk_cache(inferred). Carries the KV layout, dtype, and page size.
Args:
- βbuffer_row_offsets (
TileTensor[DType.uint32, BufferRowOffsetsLayoutType, MutUntrackedOrigin]): Output[MAX_CHUNKS, batch_size + 1]tensor of per-chunk buffer row offsets.buffer_row_offsets[chunk_idx, seq_idx]is the starting row offset within the buffer for sequenceseq_idxin chunkchunk_idx. - βcache_offsets (
TileTensor[DType.uint32, CacheOffsetsLayoutType, MutUntrackedOrigin]): Output[MAX_CHUNKS, batch_size]tensor of per-chunk cache offsets.cache_offsets[chunk_idx, seq_idx]is the starting offset into the paged KV cache for sequenceseq_idxin chunkchunk_idx. - βbuffer_lengths (
TileTensor[DType.int32, BufferLengthsLayoutType, MutUntrackedOrigin]): Output[MAX_CHUNKS]tensor of per-chunk total buffer lengths.buffer_lengths[chunk_idx]is the total number of valid rows across all sequences in chunkchunk_idx; -1 marks unused chunks. - βinput_row_offsets (
TileTensor[DType.uint32, InputRowOffsetsLayoutType, ImmUntrackedOrigin]): Input[batch_size + 1]tensor of cumulative row offsets;offsets[b]tooffsets[b+1]gives batchb's new token range. - βk_cache (
cache_t): Paged KV cache providing per-sequence cache lengths. - βbuffer_token_size (
UInt32): Fixed buffer size in tokens; each chunk processes at most this many tokens per sequence.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!