CompressionMetrics<T>
Models & Types · AiDotNet.ModelCompression
Provides metrics and statistics for model compression operations.
For Beginners
CompressionMetrics helps you measure how well compression worked.
When you compress a model, you want to know:
- How much smaller did it get? (compression ratio)
- How much memory did we save? (size reduction)
- Did it get faster? (inference speed)
- Is it still accurate? (accuracy preservation)
This class tracks all these important measurements so you can:
- Compare different compression techniques
- Decide if the compression is worth it
- Find the best balance between size and accuracy
Example:
- Original model: 100 MB, 95% accuracy, 10ms inference
- Compressed model: 10 MB, 94% accuracy, 5ms inference
- Metrics show: 10x compression, 1% accuracy loss, 2x speedup
- Conclusion: Great compression! The small accuracy loss is worth the huge size reduction.
How It Works
CompressionMetrics tracks important statistics about the compression process, including compression ratio, model size reduction, inference speed impact, and accuracy preservation. These metrics help evaluate the effectiveness of different compression strategies.
Constructors
| Constructor | Summary |
|---|---|
CompressionMetrics() |
Properties
| Property | Summary |
|---|---|
T AccuracyLoss { get; set; } |
Gets or sets the accuracy loss percentage. |
T BitsPerWeight { get; set; } |
Gets or sets the number of bits per weight after quantization. |
T CompressedAccuracy { get; set; } |
Gets or sets the compressed model accuracy (after compression). |
T CompressedInferenceTimeMs { get; set; } |
Gets or sets the compressed model inference time in milliseconds. |
T CompressionRatio { get; set; } |
Gets or sets the compression ratio (original size / compressed size). |
T CompressionTimeMs { get; set; } |
Gets or sets the time taken to perform compression in milliseconds. |
T DecompressionTimeMs { get; set; } |
Gets or sets the time taken to decompress in milliseconds. |
T InferenceSpeedup { get; set; } |
Gets or sets the inference speedup factor. |
T MemoryBandwidthSavings { get; set; } |
Gets or sets the memory bandwidth savings ratio. |
T OriginalAccuracy { get; set; } |
Gets or sets the original model accuracy (before compression). |
T OriginalInferenceTimeMs { get; set; } |
Gets or sets the original inference time in milliseconds. |
T ReconstructionError { get; set; } |
Gets or sets the reconstruction error (for lossy compression). |
T SizeReductionPercentage { get; set; } |
Gets or sets the percentage of size reduction. |
T Sparsity { get; set; } |
Gets or sets the sparsity level achieved (fraction of zero weights). |
long CompressedSize { get; set; } |
Gets or sets the compressed model size in bytes. |
long EffectiveParameterCount { get; set; } |
Gets or sets the effective number of unique parameters after compression. |
long OriginalParameterCount { get; set; } |
Gets or sets the number of parameters in the original model. |
long OriginalSize { get; set; } |
Gets or sets the original model size in bytes. |
string CompressionTechnique { get; set; } |
Gets or sets the compression technique used. |
Methods
| Method | Summary |
|---|---|
CompressionMetrics<T> FromDeepCompressionStats(DeepCompressionStats stats, string technique) |
Creates a CompressionMetrics instance from a DeepCompressionStats object. |
T CalculateCompositeFitness(double accuracyWeight, double compressionWeight, double speedWeight) |
Calculates a composite fitness score for multi-objective optimization. |
bool IsBetterThan(CompressionMetrics<T> other, double accuracyWeight, double compressionWeight, double speedWeight) |
Compares this compression result to another and determines which is better. |
bool MeetsQualityThreshold(T maxAccuracyLossPercentage, T minCompressionRatio) |
Determines if the compression meets the specified quality threshold using default values. |
bool MeetsQualityThreshold(double maxAccuracyLossPercentage, double minCompressionRatio) |
Determines if the compression meets the specified quality threshold using default values. |
string ToString() |
Gets a human-readable summary of the compression metrics. |
void CalculateDerivedMetrics() |
Calculates all derived metrics from the base measurements. |