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 struct
FixedHeightMinHeap
struct FixedHeightMinHeap[k_dtype: DType, v_dtype: DType, levels: Int]
Maintains a fixed-capacity min-heap of key/value pairs used to track top-k logits.
Parametersβ
- βk_dtype (
DType): Element type of the heap keys, the token id dtype. - βv_dtype (
DType): Element type of the heap values, the logit dtype. - βlevels (
Int): Number of heap levels; the heap stores2**levels - 1entries.
Fieldsβ
- βk_array (
Array[Scalar[k_dtype], FixedHeightMinHeap[k_dtype, v_dtype, levels].num_elements]): Inline array of heap keys, storing token ids. - βv_array (
Array[Scalar[v_dtype], FixedHeightMinHeap[k_dtype, v_dtype, levels].num_elements]): Inline array of heap values, storing logits.
Implemented traitsβ
comptime membersβ
num_elementsβ
comptime num_elements = ((Int(2) ** levels) - Int(1))
Maximum number of entries the heap can hold.
Methodsβ
__init__β
def __init__(out self, *, fill_k: Scalar[k_dtype], fill_v: Scalar[v_dtype])
Initializes the heap with fill values for all slots.
Args:
- βfill_k (
Scalar[k_dtype]): Key value to fill every heap slot with. - βfill_v (
Scalar[v_dtype]): Value to fill every heap slot with.
swapβ
def swap(mut self, a: Int, b: Int)
Swaps the key/value pairs at two heap positions.
Args:
heap_downβ
def heap_down(mut self)
Restores the min-heap property by sifting the root down.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!