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
SparseRowsDecodeMask
struct SparseRowsDecodeMask[base_t: MHAOperand, //, row_width: Int]
Padding mask for in-place sparse decode, plus a key-count bound.
A position (seq_id, head, q, k) is visible iff k is below the
entry's closed-form valid length, which rows computes from the cache
length (see SparseRowsMHAOperand.valid_length), so masking and the
in-place loader agree without a lengths buffer. Like PaddingMask there
is no causal check; the top-k selection already enforces causality.
mask_out_of_bound is set on every target, so the AMD decode kernel
also masks the keys of a tile past its split-K partition's end, which
lets partitions be smaller than a tile.
Parameters
- base_t (
MHAOperand): The operand over the full paged cache (inferred). - row_width (
Int): Elements per cache row.
Fields
- rows (
SparseRowsMHAOperand[row_width, True]):
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 = SparseRowsDecodeMask[row_width]
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 = True
mask_safe_out_of_bounds
comptime mask_safe_out_of_bounds = True
MaskType
comptime MaskType[*Ts: Fused & Input & LoadAccess] = SparseRowsDecodeMask[row_width]
Parameters
- *Ts (
Fused&Input&LoadAccess):
supports_decode_token_fold
comptime supports_decode_token_fold = False
Whether AMD decode may fold several query tokens into one tile under this mask, and start its split-K key range at start_column: both status and start_column stay valid when asked about the span of query rows a sequence's decode step carries.
Methods
__init__
def __init__(rows: SparseRowsMHAOperand[row_width, True]) -> Self
Masks with rows' closed-form valid lengths.
Args:
- rows (
SparseRowsMHAOperand[row_width, True]): The in-place operand the decode reads.
get_type_name
name
mask
def mask[dtype: DType, width: SIMDLength, //](self, coord: Coord[Int, Int, Int, Int], score_vec: SIMD[dtype, width]) -> SIMD[dtype, width]
Returns:
status
def status(self, seq_id: UInt32, tile_offset: Coord[Int, Int], tile_size: Coord[Int, Int]) -> TileMaskStatus
Returns:
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, SparseRowsDecodeMask.count_nonfull_sets(BM, BN)]
Returns:
StaticTuple[UInt32, SparseRowsDecodeMask.count_nonfull_sets(BM, BN)]
nonfull_sets
static def nonfull_sets[BM: Int, BN: Int]() -> StaticTuple[TileMaskStatus, SparseRowsDecodeMask.count_nonfull_sets(BM, BN)]
Returns:
StaticTuple[TileMaskStatus, SparseRowsDecodeMask.count_nonfull_sets(BM, BN)]
mask_strategies
static def mask_strategies[BM: Int, BN: Int]() -> StaticTuple[MaskStrategy, SparseRowsDecodeMask.count_nonfull_sets(BM, BN)]
Returns:
StaticTuple[MaskStrategy, SparseRowsDecodeMask.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: