KVCacheDType#

class sdm.cache.KVCacheDType#

Base class for the storage dtype of cached key/value projections.

abstractmethod quantize(tensor: Tensor | QuantizedTensor) → Tensor | QuantizedTensor#

Returns tensor in this storage dtype, or as is if quantized.

Parameters:

tensor (Tensor | QuantizedTensor) – Key or value projections as computed by attention.

Return type:

Tensor | QuantizedTensor

KVCacheEntry#

class sdm.cache.KVCacheEntry(key: Tensor | QuantizedTensor, value: Tensor | QuantizedTensor)#

Cached key/value projections for a single transformer block.

Parameters:
  • key (Tensor | QuantizedTensor) – Key projections with shape [..., KV, H, C].

  • value (Tensor | QuantizedTensor) – Value projections with shape [..., KV, H, C].

dequantize(dtype: dtype) → tuple[Tensor, Tensor]#

Returns key and value with quantized ones dequantized to dtype.

Parameters:

dtype (dtype) – The target dtype.

Return type:

tuple[Tensor, Tensor]