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_sm100_prefill_blockscale
def mla_sm100_prefill_blockscale[output_dtype: DType, q_type: DType, KVType: MHAOperand, VType: MHAOperand, KRopeType: MHAOperand, MaskType: MHAMask, MaxPromptLenType: OptionallyStaticInt, //, config: MHAConfig[config.dtype], group: Int, q_depth: Int, cache_depth: Int, _ndbuffer_mha_operand: Bool, blockwise_scale: Int = Int(0), v_depth: Int = Int(-1)](output: TileTensor[output_dtype, Storage=output.Storage, linear_idx_type=output.linear_idx_type], q: TileTensor[q_type, Storage=q.Storage, linear_idx_type=q.linear_idx_type], k: KVType, v: VType, k_rope: KRopeType, mask_functor: MaskType, valid_length: TileTensor[DType.uint32, Storage=valid_length.Storage, linear_idx_type=valid_length.linear_idx_type], max_prompt_len: MaxPromptLenType, scale: Float32, batch_size: Int, ctx: DeviceContext)
Launches the SM100 MLA prefill kernel with blockwise FP8 scaling.
Selects an FA4 MLA config, builds the TMA tiles for Q, K_nope, K_rope, and
V, then enqueues the warp-specialized mla_prefill_kernel_blockscale kernel
that converts block-scaled FP8 K_rope to BF16 before the MMA stage.
Parameters:
- βoutput_dtype (
DType): The element dtype of the output tensor. - βq_type (
DType): The element dtype of the query tensor. - βKVType (
MHAOperand): TheMHAOperandtype for K_nope, carrying gmem layout and page-size metadata. - βVType (
MHAOperand): TheMHAOperandtype for V, carrying gmem layout and page-size metadata. - βKRopeType (
MHAOperand): TheMHAOperandtype for K_rope, carrying gmem layout, page-size, and dtype (FP8 for blockscale). - βMaskType (
MHAMask): TheMHAMasktype controlling causal and padding behavior. - βMaxPromptLenType (
OptionallyStaticInt): TheOptionallyStaticInttype ofmax_prompt_len, either a compile-time constant or a runtime integer. - βconfig (
MHAConfig[config.dtype]): TheMHAConfigholding tile sizes, stage counts, and head counts (inferred). - βgroup (
Int): The GQA group size, namely the number of query heads per KV head (inferred). - βq_depth (
Int): The total query head dimension, combining nope and rope depth (inferred). - βcache_depth (
Int): The total KV cache depth, combining nope and rope depth (inferred). - β_ndbuffer_mha_operand (
Bool): Whether the MHA operand uses the ndbuffer layout (inferred). - βblockwise_scale (
Int): The blockwise FP8 scaling mode flag (defaults to 0, inferred). - βv_depth (
Int): The V and output head dimension, or -1 for the DeepSeek shape where V width equals nope width (defaults to -1, inferred).
Args:
- βoutput (
TileTensor[output_dtype, Storage=output.Storage, linear_idx_type=output.linear_idx_type]): The output tensor of shape[batch * num_rows, num_q_heads, ov_depth]. - βq (
TileTensor[q_type, Storage=q.Storage, linear_idx_type=q.linear_idx_type]): The query tensor of shape[batch * num_rows, num_q_heads, qk_depth]. - βk (
KVType): The K_nope operand for the non-rotary part of the KV cache. - βv (
VType): The V operand for the value part of the KV cache. - βk_rope (
KRopeType): The K_rope operand for the rotary-position-encoded part of K, stored as block-scaled FP8. - βmask_functor (
MaskType): The attention mask functor applied to the score matrix. - βvalid_length (
TileTensor[DType.uint32, Storage=valid_length.Storage, linear_idx_type=valid_length.linear_idx_type]): The per-sequence valid length tensor of shape[batch]asuint32. - βmax_prompt_len (
MaxPromptLenType): The maximum prompt length across the batch, as a compile-time or runtime integer. - βscale (
Float32): The softmax scale factor applied to the Q@K' dot product. - βbatch_size (
Int): The number of sequences in the batch. - βctx (
DeviceContext): TheDeviceContextused to enqueue the kernel.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!