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_decoding_single_batch
def mla_decoding_single_batch[q_type: DType, k_t: MHAOperand, output_type: DType, mask_t: MHAMask, *, BM: Int, BN: Int, BK: Int, WM: Int, WN: Int, depth: Int, depth_v: Int, num_threads: Int, num_pipeline_stages: Int, decoding_warp_split_k: Bool = False](q_ptr: Pointer[Scalar[q_type], MutAnyOrigin, _safe=False], k: k_t, output_ptr: Pointer[Scalar[output_type], MutAnyOrigin, _safe=False], exp_sum_ptr: Pointer[Scalar[get_accum_type[q_type]()], MutAnyOrigin, _safe=False], qk_max_ptr: Pointer[Scalar[get_accum_type[q_type]()], MutAnyOrigin, _safe=False], scale: Float32, num_keys: Int, num_partitions: Int, mask: mask_t, batch_idx: Int)
Flash attention v2 algorithm.
Computes single-batch MLA attention for one decode step on NVIDIA
GPUs: Q @ K^T with online softmax, then P @ V where V is derived as
K[:, :depth_v]. Split-K partitions the key range across
block_idx.x; block_idx.y selects the query head group.
Parameters:
- βq_type (
DType): Element type of the query tensorq_ptr(inferred). Must be a half-float orfloat8_e4m3fn. - βk_t (
MHAOperand): KV cache operand type backingk(inferred). Carries the KV layout, dtype, and head geometry. - βoutput_type (
DType): Element type of the output tensoroutput_ptr(inferred).bfloat16whenq_typeisfloat8_e4m3fn, else matchesq_type. - βmask_t (
MHAMask): Mask functor type applied to attention scores (inferred). - βBM (
Int): Number of query rows per block (the M-tile height). - βBN (
Int): Number of key rows per block (the N-tile width). - βBK (
Int): Tile size in the depth (head) dimension. - βWM (
Int): Warp tile height in the M dimension. - βWN (
Int): Warp tile width in the N dimension. - βdepth (
Int): Total head dimension of Q and K (576 for DeepSeek V2/3). - βdepth_v (
Int): V head dimension; V is derived asK[:, :, :depth_v](512 for DeepSeek V2/3). - βnum_threads (
Int): Number of threads per CTA, derived from the warp tile geometry. - βnum_pipeline_stages (
Int): Number of software-pipelined MMA stages. - βdecoding_warp_split_k (
Bool): Whether to use warp-level split-K reduction within the decode kernel (defaults toFalse). Currently unsupported; must beFalse.
Args:
- βq_ptr (
Pointer[Scalar[q_type], MutAnyOrigin, _safe=False]): Pointer to the query tensor for this batch, withnum_headsrows ofdepthelements each, indexed byblock_idx.yinBM-row blocks. - βk (
k_t): KV cache operand. V is derived asK[:, :, :depth_v], so V is not loaded separately. - βoutput_ptr (
Pointer[Scalar[output_type], MutAnyOrigin, _safe=False]): Pointer to the output tensor for this batch, withnum_headsrows ofdepth_velements each, indexed byblock_idx.yinBM-row blocks. - βexp_sum_ptr (
Pointer[Scalar[get_accum_type[q_type]()], MutAnyOrigin, _safe=False]): Pointer to the per-row softmax exp-sum stats buffer, used for split-K reduction. - βqk_max_ptr (
Pointer[Scalar[get_accum_type[q_type]()], MutAnyOrigin, _safe=False]): Pointer to the per-row softmax max stats buffer, used for split-K reduction. - βscale (
Float32): Softmax scale factor applied to QK^T. - βnum_keys (
Int): Total number of cached KV entries for this batch. - βnum_partitions (
Int): Split-K partition count; 1 disables split-K reduction. - βmask (
mask_t): Mask functor instance applied to attention scores. - βbatch_idx (
Int): Batch index into the paged KV cache.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!