Mojo struct
ContinuousBatchingKVCacheCollection
struct ContinuousBatchingKVCacheCollection[dtype_: DType, kv_params_: KVCacheStaticParams]
This is a "view" of the cache for the given sequences in the batch.
This object does not own the underlying buffers in k_cache and v_cache, it's borrowing them from the BlockWrappers in our KVCacheManager.
Parametersβ
- βdtype_ (
DType): The dtype of the kv-cache. - βkv_params_ (
KVCacheStaticParams): The kv-cache static parameters.
Fieldsβ
- βblocks (
ContinuousBatchingKVCacheCollection[dtype_, kv_params_].blocks_tt_type): - βcache_lengths (
ContinuousBatchingKVCacheCollection[dtype_, kv_params_].CacheType.cache_lengths_tt_type): - βlookup_table (
ContinuousBatchingKVCacheCollection[dtype_, kv_params_].CacheType.lookup_table_tt_type): - βmax_seq_length (
UInt32): - βmax_cache_length (
UInt32): - βkv_cache_dynamic_shape (
IndexList[4]): - βkv_cache_dynamic_strides (
IndexList[4]):
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDestructible,
KVCollectionT,
Movable
comptime membersβ
blocks_layoutβ
comptime blocks_layout = Layout.row_major(ContinuousBatchingKVCacheCollection[dtype_, kv_params_].blocks_shape)
blocks_shapeβ
comptime blocks_shape = IntTuple(-1, -1, -1, -1, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params)
blocks_tt_layoutβ
comptime blocks_tt_layout = Layout[*?, *?]
blocks_tt_typeβ
comptime blocks_tt_type = TileTensor[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, Layout[*?, *?], MutAnyOrigin]
CacheTypeβ
comptime CacheType = ContinuousBatchingKVCache[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params]
dtypeβ
comptime dtype = dtype_
kv_paramsβ
comptime kv_params = kv_params_
name_strβ
comptime name_str = "continuous_batching"
scale_dtypeβ
comptime scale_dtype = DType.invalid
Methodsβ
__init__β
__init__(out self, blocks: LayoutTensor[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, Layout.row_major[6](), MutAnyOrigin], cache_lengths: LayoutTensor[DType.uint32, Layout(IntTuple(-1)), ImmutAnyOrigin], lookup_table: LayoutTensor[DType.uint32, Layout(IntTuple(-1)), ImmutAnyOrigin], max_seq_length: UInt32, max_cache_length: UInt32, scales: OptionalReg[LayoutTensor[DType.invalid, Layout.row_major[6](), MutAnyOrigin]] = None)
Construct from LayoutTensor params (MOGG boundary).
__init__(out self, blocks: TileTensor[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, Layout[*?, *?], MutAnyOrigin], cache_lengths: TileTensor[DType.uint32, Layout[*?, *?], ImmutAnyOrigin], lookup_table: TileTensor[DType.uint32, Layout[*?, *?], ImmutAnyOrigin], max_seq_length: UInt32, max_cache_length: UInt32)
Construct from TileTensor fields directly.
get_key_cacheβ
get_key_cache(self, layer_idx: Int) -> ContinuousBatchingKVCacheCollection[dtype_, kv_params_].CacheType
Returns:
ContinuousBatchingKVCacheCollection[dtype_, kv_params_].CacheType
get_value_cacheβ
get_value_cache(self, layer_idx: Int) -> ContinuousBatchingKVCacheCollection[dtype_, kv_params_].CacheType
Returns:
ContinuousBatchingKVCacheCollection[dtype_, kv_params_].CacheType
cache_lengthβ
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!