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
apply_mask
def apply_mask[BN: Int, MaskType: MHAMask, //, *, mask_strategy: MaskStrategy, skip_scale: Bool = False](mut srow: Array[Float32, BN], mask: MaskType, scale_log2e: Float32, *, prompt_idx: UInt32, q_head_idx: UInt32, kv_tile_start_row: Int32, max_seq_len: UInt32, num_keys: Int32, score_row: Int32)
Applies bitmask, computed, and out-of-bounds masking strategies to a row of BN attention scores.
Scales by scale_log2e (unless skip_scale), then applies the mask strategy: the bitmask path uses mask_select8 per 32-column batch, the computed path calls mask.mask, and both paths apply the out-of-bounds clip via apply_oob_mask.
Parameters:
- βBN (
Int): Number of scores in the row; must be a multiple of 32 for the bitmask path. - βMaskType (
MHAMask):MHAMasktype providing theapply_log2e_after_maskflag and themask_bitsormaskmasking primitives. - βmask_strategy (
MaskStrategy):MaskStrategybitset selecting which masking strategies to apply (BITMASK, COMPUTED, OUT_OF_BOUNDS). - βskip_scale (
Bool): Whether to skip thescale_log2epre-scaling (defaults toFalse).
Args:
- βsrow (
Array[Float32, BN]): Row ofBNattention scores to mask in place. - βmask (
MaskType): Mask object providing bitmask or computed mask values. - βscale_log2e (
Float32): Softmax scale factor in log2 base, applied to scores before masking unlessskip_scaleis set. - βprompt_idx (
UInt32): Index of the prompt in the batch. - βq_head_idx (
UInt32): Index of the query head. - βkv_tile_start_row (
Int32): Starting row of the KV tile in the key dimension, the absolute column offset of the first key in this tile. - βmax_seq_len (
UInt32): Maximum sequence length. - βnum_keys (
Int32): Number of valid keys; columns at or beyond this index are out of bounds. - βscore_row (
Int32): Row index of the score in the query dimension.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!