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_tail_update_kernel
def kpool_tail_update_kernel[dtype: DType, TailLayoutType: TensorLayout, tail_origin: MutOrigin, OutLayoutType: TensorLayout, out_origin: MutOrigin, ClosedLayoutType: TensorLayout, closed_origin: MutOrigin, KLayoutType: TensorLayout, k_origin: ImmOrigin, GateLayoutType: TensorLayout, gate_origin: ImmOrigin, ApeLayoutType: TensorLayout, ape_origin: ImmOrigin, PosLayoutType: TensorLayout, pos_origin: ImmOrigin, SlotLayoutType: TensorLayout, slot_origin: ImmOrigin, TailEngine: TensorEngine, OutEngine: TensorEngine, ClosedEngine: TensorEngine, KEngine: TensorEngine, GateEngine: TensorEngine, ApeEngine: TensorEngine, PosEngine: TensorEngine, SlotEngine: TensorEngine, head_dim: Int, kpool: Int, next_n: Int = Int(1)](tail: TileTensor[dtype, TailLayoutType, tail_origin, Engine=TailEngine], pooled: TileTensor[dtype, OutLayoutType, out_origin, Engine=OutEngine], closed_pool: TileTensor[.int32, ClosedLayoutType, closed_origin, Engine=ClosedEngine], k: TileTensor[dtype, KLayoutType, k_origin, Engine=KEngine], gate: TileTensor[dtype, GateLayoutType, gate_origin, Engine=GateEngine], ape: TileTensor[.float32, ApeLayoutType, ape_origin, Engine=ApeEngine], positions: TileTensor[.int32, PosLayoutType, pos_origin, Engine=PosEngine], slot_idx: TileTensor[.uint32, SlotLayoutType, slot_origin, Engine=SlotEngine], num_requests: Int32)
Stashes a request's new tokens, and closes each pool as it fills.
A decoded token cannot be pooled on arrival, because its pool-mates arrived
on earlier steps and have left the batch. Each request keeps its
in-progress pool in tail, a ring of kpool slots addressed by
position % kpool.
A speculative step appends next_n tokens at once, so several pools can
close in one call.
The ring is indexed by slot_idx[r], not by r. A batch reorders between
steps, so row r is not always the same request.
Every real token stashes, whether or not it closes a pool.
Rejected speculative tokens are the caller's problem. The ring holds no pointer to rewind, so a rejected token that has already stashed stays.
Parameters:
- dtype (
DType): Element type oftail,k,gateandpooled. - TailLayoutType (
TensorLayout): Layout oftail. - tail_origin (
MutOrigin): Origin oftail. - OutLayoutType (
TensorLayout): Layout ofpooled. - out_origin (
MutOrigin): Origin ofpooled. - ClosedLayoutType (
TensorLayout): Layout ofclosed_pool. - closed_origin (
MutOrigin): Origin ofclosed_pool. - KLayoutType (
TensorLayout): Layout ofk. - k_origin (
ImmOrigin): Origin ofk. - GateLayoutType (
TensorLayout): Layout ofgate. - gate_origin (
ImmOrigin): Origin ofgate. - ApeLayoutType (
TensorLayout): Layout ofape. - ape_origin (
ImmOrigin): Origin ofape. - PosLayoutType (
TensorLayout): Layout ofpositions. - pos_origin (
ImmOrigin): Origin ofpositions. - SlotLayoutType (
TensorLayout): Layout ofslot_idx. - slot_origin (
ImmOrigin): Origin ofslot_idx. - TailEngine (
TensorEngine): Engine oftail. - OutEngine (
TensorEngine): Engine ofpooled. - ClosedEngine (
TensorEngine): Engine ofclosed_pool. - KEngine (
TensorEngine): Engine ofk. - GateEngine (
TensorEngine): Engine ofgate. - ApeEngine (
TensorEngine): Engine ofape. - PosEngine (
TensorEngine): Engine ofpositions. - SlotEngine (
TensorEngine): Engine ofslot_idx. - head_dim (
Int): Channels per key; also the block width. - kpool (
Int): Tokens per pool. - next_n (
Int): Tokens appended per request per call.
Args:
- tail (
TileTensor[dtype, TailLayoutType, tail_origin, Engine=TailEngine]): Per-slot ring,[max_slots, 2, kpool, head_dim], sized by the engine's concurrent-request capacity. Index 0 holds keys, index 1 holds gate scores. Only slotslot_idx[r]is touched for rowr. Persists across steps. - pooled (
TileTensor[dtype, OutLayoutType, out_origin, Engine=OutEngine]): Output[num_requests, ceil(next_n / kpool), head_dim], meaningful only whereclosed_poolis non-negative. - closed_pool (
TileTensor[.int32, ClosedLayoutType, closed_origin, Engine=ClosedEngine]): Output[num_requests, ceil(next_n / kpool)]. The pool ids this call completed, in order, padded with -1. - k (
TileTensor[dtype, KLayoutType, k_origin, Engine=KEngine]): This step's layer-normed keys,[num_requests, next_n, head_dim]. - gate (
TileTensor[dtype, GateLayoutType, gate_origin, Engine=GateEngine]): This step's gate scores,[num_requests, next_n, head_dim]. - ape (
TileTensor[.float32, ApeLayoutType, ape_origin, Engine=ApeEngine]): Within-pool position embedding,[kpool, head_dim], f32. - positions (
TileTensor[.int32, PosLayoutType, pos_origin, Engine=PosEngine]): Absolute position of each new token,[num_requests, next_n]. Negative marks a padded entry. - slot_idx (
TileTensor[.uint32, SlotLayoutType, slot_origin, Engine=SlotEngine]): Ring slot owned by each batch row,[num_requests],uint32. - num_requests (
Int32): Requests actually present.