Skip to main content

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. It does own the Pointer[NDBuffer[dtype, 3]] and valid_lengths buffer

Parameters

Fields

  • cache_lengths (LayoutTensor[DType.uint32, Layout(IntTuple(-1)), ImmutAnyOrigin]):
  • lookup_table (LayoutTensor[DType.uint32, Layout(IntTuple(-1)), ImmutAnyOrigin]):
  • blocks (LayoutTensor[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].blocks_layout, MutAnyOrigin]):
  • 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, KVCollectionT, Movable, UnknownDestructibility

Aliases

__copyinit__is_trivial

comptime __copyinit__is_trivial = True

__del__is_trivial

comptime __del__is_trivial = True

__moveinit__is_trivial

comptime __moveinit__is_trivial = True

blocks_layout

comptime blocks_layout = Layout.row_major(ContinuousBatchingKVCacheCollection[dtype_, kv_params_].blocks_shape)

blocks_shape

comptime blocks_shape = IntTuple(-1, -1, -1, -1, Int(ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params), Int(ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params))

blocks_type

comptime blocks_type = LayoutTensor[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].blocks_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"

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)

get_key_cache

get_key_cache(self, layer_idx: Int) -> ContinuousBatchingKVCache[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params]

Returns:

ContinuousBatchingKVCache

get_value_cache

get_value_cache(self, layer_idx: Int) -> ContinuousBatchingKVCache[ContinuousBatchingKVCacheCollection[dtype_, kv_params_].dtype, ContinuousBatchingKVCacheCollection[dtype_, kv_params_].kv_params]

Returns:

ContinuousBatchingKVCache

cache_length

cache_length(self, bs_idx: Int) -> Int

Returns:

Int

Was this page helpful?