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_splitk_reduce
def mla_splitk_reduce[intermediate_type: DType, output_type: DType, ValidLT: TensorLayout, depth: Int, num_heads: Int, D_TILES: Int, W_PARTS: Int, MAX_PARTITIONS: Int, use_exp2: Bool = False, q_seq_len: Int = Int(1), ragged: Bool = False](intermediate_ptr: Pointer[Scalar[intermediate_type], ImmutAnyOrigin, _safe=False], output_ptr: Pointer[Scalar[output_type], MutAnyOrigin, _safe=False], exp_sum_ptr: Pointer[Scalar[get_accum_type[output_type]()], MutAnyOrigin, _safe=False], qk_max_ptr: Pointer[Scalar[get_accum_type[output_type]()], MutAnyOrigin, _safe=False], batch_size: Int, num_partitions: Int, valid_length_tt: TileTensor[DType.uint32, ValidLT, ImmutAnyOrigin])
Combines per-partition MLA decode partial outputs into the final result.
Performs the split-K reduction for MLA decoding by merging per-partition
intermediate outputs and softmax statistics (exp-sum and qk-max) across the
partition axis using W_PARTS warps per CTA and D_TILES CTAs over the
depth axis, then stores the rescaled output to global memory.
Parameters:
- βintermediate_type (
DType): Element type of the per-partition intermediate output buffer. - βoutput_type (
DType): Element type of the final reduced output. - βValidLT (
TensorLayout): Layout type of thevalid_length_tttensor (inferred). - βdepth (
Int): Per-head attention head dimension. Must be positive and divisible byD_TILES * WARP_SIZE; 576 for DeepSeek V2/3. - βnum_heads (
Int): Number of query attention heads. The folded query-row count isnum_heads * q_seq_len. - βD_TILES (
Int): Number of CTAs the kernel launches along the depth axis; each CTA ownsdepth / D_TILESelements. - βW_PARTS (
Int): Number of warps per CTA, each handlingMAX_PARTITIONS / W_PARTSpartitions. - βMAX_PARTITIONS (
Int): Upper bound on the partition count this specialization handles; must be a multiple ofWARP_SIZEandW_PARTS. - βuse_exp2 (
Bool): Whether the softmax rescale usesexp2instead ofexp(defaults toFalse). AMD usesexp2. - βq_seq_len (
Int): Query tokens per batch (the MTP token-fold ceiling); the MMA M dimension isnum_heads * q_seq_len(defaults to 1). - βragged (
Bool): Whether the final store is remapped throughvalid_length_ttto the ragged[total_q_tokens, num_heads, depth]layout (defaults toFalse).
Args:
- βintermediate_ptr (
Pointer[Scalar[intermediate_type], ImmutAnyOrigin, _safe=False]): Pointer to the per-partition intermediate output with shape[num_partitions, batch_size, num_rows, depth]wherenum_rows = num_heads * q_seq_len. - βoutput_ptr (
Pointer[Scalar[output_type], MutAnyOrigin, _safe=False]): Pointer to the final output buffer with shape[batch_size * num_rows, depth]. - βexp_sum_ptr (
Pointer[Scalar[get_accum_type[output_type]()], MutAnyOrigin, _safe=False]): Pointer to per-partition exp-sum statistics with shape[num_partitions, batch_size, num_rows]. - βqk_max_ptr (
Pointer[Scalar[get_accum_type[output_type]()], MutAnyOrigin, _safe=False]): Pointer to per-partition qk-max statistics with shape[num_partitions, batch_size, num_rows]. - βbatch_size (
Int): Number of sequences in the batch. - βnum_partitions (
Int): Number of split-K partitions actually used. Must be positive and at mostMAX_PARTITIONS. - βvalid_length_tt (
TileTensor[DType.uint32, ValidLT, ImmutAnyOrigin]):uint32tensor of input row offsets of shape[batch_size + 1]. Read only on theragged and q_seq_len > 1path to remap the final store; a zero-length placeholder otherwise.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!