Mojo trait
KVCacheT
Trait for different KVCache types and implementations.
Represents a single (key or value) cache.
Implemented traits
AnyType
,
Copyable
,
Movable
,
UnknownDestructibility
Aliases
kv_params
alias kv_params
type
alias type
Methods
__copyinit__
__copyinit__(out self: _Self, existing: _Self, /)
Create a new instance of the value by copying an existing one.
Args:
- existing (
_Self
): The value to copy.
__moveinit__
__moveinit__(out self: _Self, owned existing: _Self, /)
Create a new instance of the value by moving the value of another.
Args:
- existing (
_Self
): The value to move.
cache_lengths_nd
cache_lengths_nd(self: _Self) -> NDBuffer[uint32, 1, MutableAnyOrigin]
Returns the cache lengths as a NDBuffer.
cache_length
cache_length(self: _Self, batch_idx: Int) -> Int
Returns the length of the cache for a given batch index.
load
load[width: Int](self: _Self, bs: Int, head_idx: Int, tok_idx: Int, head_dim_idx: Int) -> SIMD[get_vtable_entry(:trait<_kv_cache::_types::_KVCacheT> _Self, "type"), width]
Loads an element from the given index.
store
store(self: _Self, bs: Int, head_idx: Int, tok_idx: Int, head_dim_idx: Int, val: SIMD[get_vtable_entry(:trait<_kv_cache::_types::_KVCacheT> _Self, "type"), size])
Stores an element at the given index.
empty_cache
empty_cache(self: _Self) -> Bool
Returns true if the cache_lengths for all requests is 0, false otherwise.
max_prompt_length
max_prompt_length(self: _Self) -> SIMD[uint32, 1]
Returns the maximum sequence length across all batches of the current request.
max_context_length
max_context_length(self: _Self) -> SIMD[uint32, 1]
Returns the maximum cache length used across all batches of the current request.
block_paged_ptr
block_paged_ptr[tile_size: Int](self: _Self, batch_idx: Int, start_tok_idx: Int, head_idx: Int, head_dim_idx: Int = 0) -> UnsafePointer[SIMD[get_vtable_entry(:trait<_kv_cache::_types::_KVCacheT> _Self, "type"), 1]]
Returns a LayoutTensor pointing to the KVCache block at the given index.
Paged KVCache implementations must have a block_size which is a multiple of the and greater than the layout's first dimension.
max_tile_size
static max_tile_size() -> Int
Returns the maximum tile size for the KVCache.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!