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_sm100_dispatch
def mha_sm100_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: MaskType, valid_length: DeviceBuffer[DType.uint32], max_prompt_len_arg: MaxPromptLenType, max_cache_valid_length_arg: Int, scale: Float32, kv_input_row_offsets: OptionalReg[TileTensor[DType.uint32, Layout[*?, *?], ImmutAnyOrigin]], batch_size_arg: Int, partition: PartitionType, ctx: DeviceContext, sink_weights: OptionalReg[TileTensor[q_type, Layout[*?, *?], ImmutAnyOrigin]])
Dispatches single-query (decode) multi-head attention to the SM100 kernel, selecting TMA tiles, scheduler, and partition configuration.
Parameters:
- βq_type (
DType): The element type of the query tensor. - βKVType (
MHAOperand): The operand type describing the key and value memory layout (for example, paged or ragged). - βMaskType (
MHAMask): The mask type applied to the attention scores. - βoutput_type (
DType): The element type of the output tensor. - βMaxPromptLenType (
OptionallyStaticInt): The type representing the maximum prompt length, which may be statically or dynamically known. - βPartitionType (
MHAPartitionScheme): The scheme for partitioning work across CTAs. - βconfig (
MHAConfig[config.dtype]): The MHA configuration holding tile sizes, depth, and head count. - βgroup (
Int): The group-query attention group size, equal to the number of query heads sharing each KV head. - βragged (
Bool): Whether the input sequences have variable lengths. - βsink (
Bool): Whether attention sink weights are applied. - β_is_cache_length_accurate (
Bool): Whether the reported cache length is exact, affecting position computation.
Args:
- βoutput (
DeviceBuffer[output_type]): The output buffer for the attention results. - βq_arg (
DeviceBuffer[q_type]): The query tensor buffer. - βk (
KVType): The key operand, with layout described byKVType. - βv (
KVType): The value operand, with layout described byKVType. - βnum_rows_q (
Int): Number of query rows in the batch. - βmask (
MaskType): The attention mask instance. - βvalid_length (
DeviceBuffer[DType.uint32]): The per-sequence valid length buffer. - βmax_prompt_len_arg (
MaxPromptLenType): The maximum prompt length across the batch. - βmax_cache_valid_length_arg (
Int): The maximum valid cache length. - βscale (
Float32): The scaling factor applied to the query-key dot product. - βkv_input_row_offsets (
OptionalReg[TileTensor[DType.uint32, Layout[*?, *?], ImmutAnyOrigin]]): Optional row offsets into the KV input. for ragged layouts. - βbatch_size_arg (
Int): The number of sequences in the batch. - βpartition (
PartitionType): The partition descriptor for splitting work across CTAs. - βctx (
DeviceContext): The device context used to launch the kernel. - βsink_weights (
OptionalReg[TileTensor[q_type, Layout[*?, *?], ImmutAnyOrigin]]): Optional sink weights for attention sinks.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!