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_sm100_prefill_sparse
def mla_sm100_prefill_sparse[output_type: DType, q_type: DType, cache_t: KVCacheT, //, num_q_heads: Int, qk_depth: Int, v_depth: Int, indices_stride: Int](output: TileTensor[output_type, Storage=output.Storage, linear_idx_type=output.linear_idx_type], q: TileTensor[q_type, Storage=q.Storage, linear_idx_type=q.linear_idx_type], kv_cache: cache_t, indices: TileTensor[DType.uint32, Storage=indices.Storage, linear_idx_type=indices.linear_idx_type], topk_lengths: TileTensor[DType.uint32, Storage=topk_lengths.Storage, linear_idx_type=topk_lengths.linear_idx_type], attn_sink_ptr: Optional[Pointer[Float32, ImmutAnyOrigin, _safe=False]], scale: Float32, ctx: DeviceContext)
Sparse MLA prefill (DSv3.2 absorbed shape, BF16, SM100).
Thin wrapper around mla_prefill_sparse that builds the
MLASparseConfig from the passed dimensions so callers don't have to
reach into the kernel's config type. The kernel targets the DSv3.2
absorbed/latent shape and comptime-asserts qk_depth==576,
num_q_heads is 128 or 64, and num_kv_heads==1, plus equal
output/query bit-width. v_depth is assumed to be 512 (=
kv_lora_rank) by that shape but is not asserted.
Parameters:
- βoutput_type (
DType): Output element type (must be the same width asq_type; the kernel asserts this). - βq_type (
DType): Query element type (BF16 in the supported DSv3.2 shape). - βcache_t (
KVCacheT): KV cache type (typically a paged MLA cache obtained fromkv_collection.get_key_cache(layer_idx)). - βnum_q_heads (
Int): Number of query heads (asserted to be 128 or 64). - βqk_depth (
Int): Per-head Q/K depth (must be 576 =kv_lora_rank(512) + qk_rope_head_dim(64)). - βv_depth (
Int): Per-head V depth (512 =kv_lora_rankfor the DSv3.2 absorbed shape; not asserted). - βindices_stride (
Int): Per-query indices buffer stride (= the indexer'sindex_topk). Also used as the runtimeindices_strideto the kernel.
Args:
- βoutput (
TileTensor[output_type, Storage=output.Storage, linear_idx_type=output.linear_idx_type]): Output tile tensor with shape[total_q_tokens, num_q_heads, v_depth]. - βq (
TileTensor[q_type, Storage=q.Storage, linear_idx_type=q.linear_idx_type]): Query tile tensor with shape[total_q_tokens, num_q_heads, qk_depth]. - βkv_cache (
cache_t): Paged MLA KV cache for the current layer. - βindices (
TileTensor[DType.uint32, Storage=indices.Storage, linear_idx_type=indices.linear_idx_type]): Per-query gather4 indices, encoded asInt32(physical_block_id * page_size + token_offset_within_page)(reinterpreted via theuint32tile-tensor view;-1-bit-pattern sentinels are masked out by the kernel's k-valid producer). - βtopk_lengths (
TileTensor[DType.uint32, Storage=topk_lengths.Storage, linear_idx_type=topk_lengths.linear_idx_type]): Per-query effective top-k count ([total_q_tokens]). - βattn_sink_ptr (
Optional[Pointer[Float32, ImmutAnyOrigin, _safe=False]]): Optional attention sink (oneFloat32per query head). PassNoneto skip the sink term in the softmax epilogue. - βscale (
Float32): Softmax scale (1 / sqrt(qk_nope_head_dim + qk_rope_head_dim) * mscale^2; for DSv3.2 with mscale=1,1 / sqrt(192)). - βctx (
DeviceContext): GPU device context.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!