IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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 function

kpool_expand_topk_kernel

def kpool_expand_topk_kernel[OutLayoutType: TensorLayout, out_origin: MutOrigin, PoolLayoutType: TensorLayout, pool_origin: ImmOrigin, IROLayoutType: TensorLayout, iro_origin: ImmOrigin, CacheLenLayoutType: TensorLayout, kpool: Int, pool_topk: Int, always_select_tail: Bool](out_indices: TileTensor[.int32, OutLayoutType, out_origin], pool_ids: TileTensor[.int32, PoolLayoutType, pool_origin], input_row_offsets: TileTensor[.uint32, IROLayoutType, iro_origin], cache_lengths: TileTensor[.uint32, CacheLenLayoutType, ImmutAnyOrigin], total_seq_len: Int32)

Turns selected pool ids back into the token positions they cover.

The indexer selects pools; attention reads tokens. Each selected pool expands to the kpool consecutive positions it covers.

An unselected slot expands to -1 in every one of its positions, never to a clamped valid one, which would point attention at a token the indexer did not choose.

With always_select_tail the output carries kpool - 1 further columns holding the query's most recent positions, the ones no complete pool covers yet. Their location comes from the query's visible count, so it tracks the pool currently being filled.

Parameters:

  • ​OutLayoutType (TensorLayout): Layout of out_indices.
  • ​out_origin (MutOrigin): Origin of out_indices.
  • ​PoolLayoutType (TensorLayout): Layout of pool_ids.
  • ​pool_origin (ImmOrigin): Origin of pool_ids.
  • ​IROLayoutType (TensorLayout): Layout of input_row_offsets.
  • ​iro_origin (ImmOrigin): Origin of input_row_offsets.
  • ​CacheLenLayoutType (TensorLayout): Layout of cache_lengths.
  • ​kpool (Int): Tokens per pool.
  • ​pool_topk (Int): Selected pools per token, index_topk // kpool.
  • ​always_select_tail (Bool): Whether to append the incomplete trailing pool.

Args:

Was this page helpful?