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
mha_sm90_dispatch
def mha_sm90_dispatch[q_type: DType, KVType: MHAOperand, MaskType: MHAMask, output_type: DType, MaxPromptLenType: OptionallyStaticInt, PartitionType: MHAPartitionScheme, //, config: MHAConfig[config.dtype], group: Int, ragged: Bool, sink: Bool, _is_cache_length_accurate: Bool](output: DeviceBuffer[output_type], q_arg: DeviceBuffer[q_type], k: KVType, v: KVType, num_rows_q: Int, mask_functor: MaskType, valid_length: DeviceBuffer[DType.uint32], max_prompt_len_arg: MaxPromptLenType, max_cache_valid_length_arg: Int, scale: Float32, kv_input_row_offsets: OptionalReg[LayoutTensor[DType.uint32, Layout.row_major(Int(-1)), ImmutAnyOrigin]], batch_size_arg: Int, partition: PartitionType, ctx: DeviceContext, sink_weights: OptionalReg[LayoutTensor[q_type, Layout.row_major(Int(-1)), ImmutAnyOrigin]])
Dispatches the SM90 FlashAttention-3 MHA kernel for a single batch.
Selects a transient, tiled, or queued tile scheduler based on the persistent-kernel configuration, builds the Q/K/V TMA tile descriptors, and forwards the request down the dispatch chain to the enqueued kernel.
Parameters:
- βq_type (
DType): The dtype of the query tensor (inferred). - βKVType (
MHAOperand): The K/V operand type encoding dtype, page size, and layout (inferred). - βMaskType (
MHAMask): The mask functor type applied to attention scores (inferred). - βoutput_type (
DType): The dtype of the output tensor (inferred). - βMaxPromptLenType (
OptionallyStaticInt): The maximum prompt length, possibly known at compile time (inferred). - βPartitionType (
MHAPartitionScheme): The scheme for partitioning attention work across SMs (inferred). - βconfig (
MHAConfig[config.dtype]): The MHA configuration holding block sizes, head count, depth, and algorithm. - βgroup (
Int): The query grouping factor, the number of query heads per KV head. - βragged (
Bool): Whether per-row valid lengths vary and require ragged masking. - βsink (
Bool): Whether attention sink weights are applied. - β_is_cache_length_accurate (
Bool): Whether the supplied cache length is exact and needs no clamping.
Args:
- βoutput (
DeviceBuffer[output_type]): The device buffer that receives the attention output. - βq_arg (
DeviceBuffer[q_type]): The device buffer holding the query tensor. - βk (
KVType): The key operand lookup table. - βv (
KVType): The value operand lookup table. - βnum_rows_q (
Int): The number of query rows in the batch. - βmask_functor (
MaskType): The mask functor instance applied to attention scores. - βvalid_length (
DeviceBuffer[DType.uint32]): The per-batch valid sequence length buffer. - βmax_prompt_len_arg (
MaxPromptLenType): The maximum prompt length after padding. - βmax_cache_valid_length_arg (
Int): The maximum valid length of the KV cache. - βscale (
Float32): The scaling factor applied to the QK^T product. - βkv_input_row_offsets (
OptionalReg[LayoutTensor[DType.uint32, Layout.row_major(Int(-1)), ImmutAnyOrigin]]): Optional row offsets into the KV cache for ragged layouts. - βbatch_size_arg (
Int): The number of sequences in the batch. - βpartition (
PartitionType): The partition instance describing the work split. - βctx (
DeviceContext): The device context used to enqueue the kernel. - βsink_weights (
OptionalReg[LayoutTensor[q_type, Layout.row_major(Int(-1)), ImmutAnyOrigin]]): Optional sink weights tensor applied when sink is enabled.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!