For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo struct
PaddingMask
struct PaddingMask[LayoutType: TensorLayout, origin_: ImmOrigin]
Padding-only mask: a position (seq_id, head, q, k) is visible iff k < valid_lengths[seq_id]. No causal (q >= k) restriction is applied.
Unlike CausalPaddingMask, this does not assume key column order
reflects key recency, so it is the right choice for an attention call
over a gathered/reordered key buffer (e.g. a top-k sparse selection
copied into a dense scratch) where causality is already enforced by
the selection step itself and a causal check against the column index
would be meaningless.
valid_lengths is a tensor of shape [num_seqs] with one uint32 value per
sequence indicating the number of valid (non-padding) tokens.
Fields
- valid_lengths (
TileTensor[.uint32, LayoutType, origin_]):
Implemented traits
AnyType,
Copyable,
Deinitable,
DevicePassable,
ImplicitlyCopyable,
MHAMask,
Movable,
RegisterPassable,
TrivialRegisterPassable
comptime members
apply_log2e_after_mask
comptime apply_log2e_after_mask = False
check_mask_during_decoding
comptime check_mask_during_decoding = True
device_type
comptime device_type = PaddingMask[LayoutType, origin_]
has_row_bias
comptime has_row_bias = False
Whether add_row_bias adds this mask's additive bias, leaving visibility_mask the rest of mask.
mask_out_of_bound
comptime mask_out_of_bound = is_nvidia_gpu()
mask_safe_out_of_bounds
comptime mask_safe_out_of_bounds = True
Methods
__init__
def __init__(valid_lengths: TileTensor[.uint32, LayoutType, origin_]) -> Self
get_type_name
name
mask
def mask[dtype: DType, width: SIMDLength, //, *, element_type: DType = .uint32](self, coord: IndexList[Int(4), element_type=element_type], score_vec: SIMD[dtype, width]) -> SIMD[dtype, width]
Returns:
status
def status[*, element_type: DType = .uint32](self, seq_id: UInt32, tile_offset: IndexList[Int(2), element_type=element_type], tile_size: IndexList[Int(2), element_type=element_type]) -> TileMaskStatus
Returns:
TileMaskStatus
start_column
def start_column[BM: Int, BN: Int, page_size: Int](self, seq_id: UInt32, row: UInt32) -> UInt32
Returns:
start_column_alignment
total_iters
def total_iters[BM: Int, BN: Int, page_size: Int](self, seq_id: UInt32, row: UInt32, num_cols: UInt32) -> UInt32
Returns:
count_nonfull_sets
last_masked_set_end
def last_masked_set_end[BM: Int, BN: Int, page_size: Int](self, seq_id: UInt32, row: UInt32, num_cols: UInt32) -> UInt32
Returns:
masked_set_ends
def masked_set_ends[BM: Int, BN: Int, page_size: Int](self, seq_id: UInt32, row: UInt32, num_cols: UInt32) -> StaticTuple[UInt32, PaddingMask.count_nonfull_sets(BM, BN)]
Returns:
nonfull_sets
static def nonfull_sets[BM: Int, BN: Int]() -> StaticTuple[TileMaskStatus, PaddingMask.count_nonfull_sets(BM, BN)]
Returns:
StaticTuple[TileMaskStatus, PaddingMask.count_nonfull_sets(BM, BN)]
mask_strategies
static def mask_strategies[BM: Int, BN: Int]() -> StaticTuple[MaskStrategy, PaddingMask.count_nonfull_sets(BM, BN)]
Returns:
StaticTuple[MaskStrategy, PaddingMask.count_nonfull_sets(BM, BN)]
mask_bits
def mask_bits(self, seq_id: UInt32, score_row: Int32, col_start: Int32, num_keys: Int32) -> UInt32
Returns: