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
flare_mla_prefill_dispatch
def flare_mla_prefill_dispatch[k_t: MHAOperand, v_t: MHAOperand, k_rope_t: MHAOperand, mask_t: MHAMask, dtype: DType, output_type: DType, //, kv_num_heads: Int, config: MHAConfig[dtype], q_depth: Int = Int(192), cache_depth: Int = Int(576), _ndbuffer_mha_operand: Bool = False](output: TileTensor[output_type, Storage=output.Storage, linear_idx_type=output.linear_idx_type], q: TileTensor[dtype, Storage=q.Storage, linear_idx_type=q.linear_idx_type], k: k_t, v: v_t, k_rope: k_rope_t, mask_functor: mask_t, valid_length: TileTensor[DType.uint32, Storage=valid_length.Storage, linear_idx_type=valid_length.linear_idx_type], max_prompt_len: Int, scale: Float32, ctx: DeviceContext, cache_offsets: OptionalReg[LayoutTensor[DType.uint32, Layout.row_major(Int(-1)), MutAnyOrigin]] = None)
Dispatches an MLA prefill request to the platform-specific kernel.
Routes to mla_sm100_prefill on SM100 GPUs or enqueues the generic
mla_prefill kernel on other NVIDIA and AMD targets, computing the grid
and shared-memory layout from the MHA config.
Parameters:
- βk_t (
MHAOperand): Key operand type backingk(inferred). EitherRaggedMHAOperandorLayoutTensorMHAOperand. - βv_t (
MHAOperand): Value operand type backingv(inferred). EitherRaggedMHAOperandorLayoutTensorMHAOperand. - βk_rope_t (
MHAOperand): KV cache operand type backingk_rope(inferred). EitherKVCacheMHAOperandorLayoutTensorMHAOperand. - βmask_t (
MHAMask): Mask functor type applied to attention scores (inferred). - βdtype (
DType): Element type ofq(inferred). Must bebfloat16orfloat8_e4m3fn. - βoutput_type (
DType): Element type ofoutput(inferred).bfloat16whenqisfloat8_e4m3fn, else matchesq. - βkv_num_heads (
Int): Number of KV attention heads. Must be 1 for MLA. - βconfig (
MHAConfig[dtype]): MLA attention config carryingnum_heads,depth, and tile geometry (block_m,block_n,block_k). - βq_depth (
Int): Q head dimension in elements (defaults to 192). For DeepSeek V2/3, 192 = 128 nope + 64 rope. - βcache_depth (
Int): KV cache head dimension in elements (defaults to 576). The absorbed-latent width of the paged MLA cache. - β_ndbuffer_mha_operand (
Bool): Whether the K/V/k_ropeoperands use ND-buffer layout instead of the default TileTensor layout (defaults toFalse).
Args:
- βoutput (
TileTensor[output_type, Storage=output.Storage, linear_idx_type=output.linear_idx_type]): Output tensor with ragged rank-3 shape[total_q_tokens, num_heads, v_depth]. Dtype isbfloat16whenqisfloat8_e4m3fn, else matchesq. - βq (
TileTensor[dtype, Storage=q.Storage, linear_idx_type=q.linear_idx_type]): Query tensor with ragged rank-3 shape[total_q_tokens, num_heads, q_depth]. - βk (
k_t): Key operand (nope part). Carries the ragged K tensor and row offsets. - βv (
v_t): Value operand. Carries the ragged V tensor and row offsets. - βk_rope (
k_rope_t): KV cache operand providing the rope part of K, with shape[cache_len, 1, q_depth - depth]. - βmask_functor (
mask_t): Mask functor instance applied to attention scores. - βvalid_length (
TileTensor[DType.uint32, Storage=valid_length.Storage, linear_idx_type=valid_length.linear_idx_type]): Per-batchuint32tensor of cumulative row offsets withbatch_size + 1entries;offsets[b]tooffsets[b+1]gives batchb's token range. - βmax_prompt_len (
Int): Maximum query sequence length (tokens per batch across all batches); drives the grid's M dimension. - βscale (
Float32): Softmax scale factor applied to QK^T. - βctx (
DeviceContext): Device context used to enqueue the kernel. - βcache_offsets (
OptionalReg[LayoutTensor[DType.uint32, Layout.row_major(Int(-1)), MutAnyOrigin]]): Optional per-batchuint32tensor of starting offsets into the paged KV cache;Nonewhen the cache is contiguous.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!