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_decode_dispatch_scalars
def mla_decode_dispatch_scalars(batch_size: Int, max_cache_valid_length: Int, q_max_seq_len: Int, num_heads: Int, is_fp8_kv: Bool, ctx: DeviceContext) -> Tuple[Int, Int, Int]
Compute the packed MLA decode dispatch metadata for the active device.
Returns (batch_size, q_max_seq_len, num_partitions). Dispatches on
ctx.api() internally, mirroring mha_decoding_num_partitions:
- HIP (AMD): the AMD MLA decode kernel bakes its split-K grid from
mha_decoding_num_partitions(..., is_mla=True)at dispatch time and never readsnum_partitionsfrom the scalar buffer; the metadatanum_partitionsis used only as the HIP device-graph capture/replay selection key. To keep the capture key byte-for-byte equal to the baked grid, compute the SAME value the kernel bakes: pass RAWmax_cache_valid_lengthandnum_heads(kv_heads == 1for MLA soheads_per_group == num_heads), with NOq_max_seq_lenadjustment. - CUDA (NVIDIA/SM100): delegate to the SM100 runtime heuristic
compute_mla_dispatch_scalars_runtime, which reads the device SM count. - Any other api (e.g. Metal): raise: there is no MLA decode dispatch path for non-HIP/non-CUDA devices, so route them to a clear error rather than silently into the SM100 heuristic.
Args:
- βbatch_size (
Int): Current decode batch size. - βmax_cache_valid_length (
Int): Max valid KV-cache length across the batch. - βq_max_seq_len (
Int): Max query sequence length (1 for decode). - βnum_heads (
Int): Number of Q attention heads. - βis_fp8_kv (
Bool): Whether the KV cache is FP8 (selects the SM100 sub-heuristic). - βctx (
DeviceContext): Device context used to readapi()and the SM count.
Returns:
Tuple[Int, Int, Int]: The packed (batch_size, q_max_seq_len, num_partitions) metadata.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!