IModelCompressionStrategy<T>
Interfaces · AiDotNet.Interfaces
Defines an interface for model compression strategies used to reduce model size while preserving accuracy.
Known implementations: ModelCompressionBase<T>
For Beginners
Model compression is the process of making AI models smaller and faster without significantly hurting their performance.
Think of it like compressing a video file - you want to reduce the file size so it’s easier to store and share, but you still want the video to look good. Similarly, model compression reduces the memory needed to store an AI model and can make it run faster, which is especially important for deploying models on mobile devices or in the cloud where storage and processing costs matter.
Different compression strategies work in different ways:
- Some group similar values together (clustering)
- Some remove less important parts (pruning)
- Some use clever encoding schemes to store data more efficiently (quantization, Huffman coding)
This interface supports ALL types of neural network data:
- Vectors (1D): Bias terms, embeddings
- Matrices (2D): Fully connected layer weights
- Tensors (N-D): Convolutional filters, attention weights
Methods
| Method | Summary |
|---|---|
Matrix<T> DecompressMatrix(Matrix<T> compressedWeights, ICompressionMetadata<T> metadata) |
Decompresses the compressed matrix weights back to their original form. |
Tensor<T> DecompressTensor(Tensor<T> compressedWeights, ICompressionMetadata<T> metadata) |
Decompresses the compressed tensor weights back to their original form. |
ValueTuple<Matrix<T>, ICompressionMetadata<T>> CompressMatrix(Matrix<T> weights) |
Compresses a 2D matrix of weights (e.g., fully connected layer). |
ValueTuple<Tensor<T>, ICompressionMetadata<T>> CompressTensor(Tensor<T> weights) |
Compresses an N-dimensional tensor of weights (e.g., convolutional filters). |
ValueTuple<Vector<T>, ICompressionMetadata<T>> Compress(Vector<T> weights) |
Compresses the given model weights. |
Vector<T> Decompress(Vector<T> compressedWeights, ICompressionMetadata<T> metadata) |
Decompresses the compressed weights back to their original form. |
double CalculateCompressionRatio(long originalSize, long compressedSize) |
Calculates the compression ratio achieved. |
long GetCompressedSize(Matrix<T> compressedWeights, ICompressionMetadata<T> metadata) |
Gets the size in bytes of the compressed tensor representation. |
long GetCompressedSize(Tensor<T> compressedWeights, ICompressionMetadata<T> metadata) |
Gets the size in bytes of the compressed tensor representation. |
long GetCompressedSize(Vector<T> compressedWeights, ICompressionMetadata<T> metadata) |
Gets the size in bytes of the compressed tensor representation. |