IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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

get_mha_decoding_num_partitions

def get_mha_decoding_num_partitions[num_heads: Int, group: Int](batch_size: Int, num_keys: Int, ctx: DeviceContext) -> Int

Return the recommended number of split-K partitions for MHA decoding.

Computes the number of CTAs (partitions) that maximally utilise the GPU for decoding, given the batch size and key-sequence length. The result feeds the split-K launcher and is also stored in MHADecodeDispatchMetadata.

Parameters:

  • ​num_heads (Int): Total number of query heads.
  • ​group (Int): GQA group size (query heads per key/value head).

Args:

  • ​batch_size (Int): Number of sequences in the batch.
  • ​num_keys (Int): Maximum key-sequence length (cache length).
  • ​ctx (DeviceContext): GPU device context used to query SM count and other properties.

Returns:

Int: The number of split-K partitions to launch.

Was this page helpful?