Class CompressionOptimizer<T>
Automatically finds the best compression configuration for a model.
public class CompressionOptimizer<T>
Type Parameters
TThe numeric type used for calculations (e.g., float, double).
- Inheritance
-
CompressionOptimizer<T>
- Inherited Members
Remarks
CompressionOptimizer uses automated machine learning techniques to find the optimal compression configuration for a neural network model. It evaluates different compression techniques and hyperparameters, tracking metrics like compression ratio, accuracy loss, and inference speed.
For Beginners: Think of this as an automated assistant that tries different ways to compress your model and finds the best one for your needs.
Instead of manually trying:
- Different pruning levels (50%, 70%, 90% of weights removed)
- Different quantization settings (8-bit, 5-bit, etc.)
- Different compression techniques (pruning, clustering, Huffman)
The optimizer automatically:
- Generates compression configurations to try
- Applies each configuration and measures results
- Tracks which configurations work best
- Returns the best compression settings found
Example usage:
var optimizer = new CompressionOptimizer<double>(options);
var bestCompression = await optimizer.OptimizeAsync(modelWeights, evaluator);
Console.WriteLine($"Best technique: {bestCompression.Technique}");
Console.WriteLine($"Compression ratio: {bestCompression.Metrics.CompressionRatio}x");
Constructors
CompressionOptimizer(CompressionOptimizerOptions?)
Initializes a new instance of the CompressionOptimizer class.
public CompressionOptimizer(CompressionOptimizerOptions? options = null)
Parameters
optionsCompressionOptimizerOptionsConfiguration options for the optimizer.
Properties
BestTrial
Gets the best compression trial found so far.
public CompressionTrial<T>? BestTrial { get; }
Property Value
TrialHistory
Gets the history of all compression trials.
public IReadOnlyList<CompressionTrial<T>> TrialHistory { get; }
Property Value
Methods
GetSummary()
Gets a summary of the optimization results.
public string GetSummary()
Returns
- string
A formatted string containing optimization results.
Optimize(Vector<T>, Func<Vector<T>, T>)
Runs the compression optimization process.
public CompressionTrial<T> Optimize(Vector<T> weights, Func<Vector<T>, T> evaluateAccuracy)
Parameters
weightsVector<T>The model weights to compress.
evaluateAccuracyFunc<Vector<T>, T>A function that evaluates model accuracy given compressed weights.
Returns
- CompressionTrial<T>
The best compression trial found.
Remarks
For Beginners: This method tries different compression settings and returns the best one.
The evaluateAccuracy function should:
- Take compressed weights
- Apply them to your model
- Run inference on validation data
- Return the accuracy (0.0 to 1.0)
The optimizer will call this function many times with different compression settings.