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_v2_ragged
def mla_prefill_v2_ragged[k_nope_t: MHAOperand, k_rope_t: MHAOperand, v_t: MHAOperand, mask_t: MHAMask, qkv_dtype: DType, output_dtype: DType, //, config: MlaConfigV2, compile_options: StringSlice[ImmStaticOrigin] = CompilationTarget.default_compile_options()](q_ptr: Pointer[Scalar[qkv_dtype], ImmutAnyOrigin, _safe=False], k_nope: k_nope_t, k_rope: k_rope_t, v: v_t, output_ptr: Pointer[Scalar[output_dtype], MutAnyOrigin, _safe=False], mask_functor: mask_t, scale: Float32, input_row_offsets_ptr: Pointer[UInt32, ImmutAnyOrigin, _safe=False], max_prompt_len: Int, batch_size: Int, ctx: DeviceContext)
Host launcher for ragged MLA prefill.
Standard ragged-prefill signature/boilerplate (grid/block derivation,
three operands, mask functor, scale, input row offsets).
Grid: (NUM_HEADS, ceildiv(max_prompt_len, BM), batch_size).
Parameters:
- βk_nope_t (
MHAOperand): Compile-time operand type for the K nope segment (inferred). - βk_rope_t (
MHAOperand): Compile-time operand type for the K rope segment (inferred). - βv_t (
MHAOperand): Compile-time operand type for the V segment (inferred). - βmask_t (
MHAMask): Compile-time mask predicate type (causal, null, etc.) (inferred). - βqkv_dtype (
DType): Element type of the Q, K, and V tensors; must equalconfig.dtype(inferred). - βoutput_dtype (
DType): Element type of the output tensor; must equalconfig.output_dtype(inferred). - βconfig (
MlaConfigV2): Shape configuration (MlaConfigV2). - βcompile_options (
StringSlice[ImmStaticOrigin]): Compilation options for the kernel (defaults to the device's default compile options).
Args:
- βq_ptr (
Pointer[Scalar[qkv_dtype], ImmutAnyOrigin, _safe=False]): Pointer to the ragged-batch Q tensor data. - βk_nope (
k_nope_t): K nope-segment operand; suppliescache_lengthforstart_pos. - βk_rope (
k_rope_t): K rope-segment operand (unused by the kernel; kept for contract parity). - βv (
v_t): V operand (the nope segment of the latent cache). - βoutput_ptr (
Pointer[Scalar[output_dtype], MutAnyOrigin, _safe=False]): Pointer to the ragged-batch output tensor data. - βmask_functor (
mask_t): Per-tile mask predicate (causal / null / ...). - βscale (
Float32): Softmax scale (1/sqrt(d_qk)). - βinput_row_offsets_ptr (
Pointer[UInt32, ImmutAnyOrigin, _safe=False]): Pointer to the per-sequence row offset prefix-sum[batch_size+1]uint32array. - βmax_prompt_len (
Int): Maximum prompt length in the batch; bounds the grid's BM-tile dimension. - βbatch_size (
Int): Number of sequences in the ragged batch. - βctx (
DeviceContext): Device context used to compile and enqueue the kernel.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!