quant_codec_core/
codec.rs1use crate::{CodecId, CodecProfileDigest, KvSliceRequest, KvTensorShape};
2
3pub trait CodecProfile {
4 fn codec_id(&self) -> CodecId;
5 fn codec_version(&self) -> &str;
6 fn profile_digest(&self) -> CodecProfileDigest;
7 fn fixed_rate_bits(&self) -> Option<u16>;
8 fn block_dim(&self) -> Option<u16>;
9 fn is_lossy(&self) -> bool;
10}
11
12pub trait VectorCodec {
13 type EncodedBlock;
14 type Error;
15
16 fn encode_block(&self, input: &[f32]) -> Result<Self::EncodedBlock, Self::Error>;
17 fn decode_block(&self, block: &Self::EncodedBlock, out: &mut [f32]) -> Result<(), Self::Error>;
18}
19
20pub trait KvCacheCodec: VectorCodec {
21 type EncodedCache;
22
23 fn encode_kv_cache(
24 &self,
25 tensors: &[f32],
26 shape: KvTensorShape,
27 ) -> Result<Self::EncodedCache, Self::Error>;
28
29 fn decode_slice(
30 &self,
31 cache: &Self::EncodedCache,
32 request: KvSliceRequest,
33 out: &mut [f32],
34 ) -> Result<(), Self::Error>;
35}