QATTrainingHook<T>

Models & Types · AiDotNet.Deployment.Optimization.Quantization.Training

Quantization-Aware Training (QAT) hook that applies fake quantization during training. Simulates quantization effects in the forward pass while allowing gradients to flow through.

For Beginners

QAT trains the model with quantization simulation so it learns to be robust to low-precision inference. This hook inserts “fake quantization” operations that quantize and immediately dequantize values, simulating the precision loss.

How It Works

How It Works:

Key Components:

Reference: Jacob et al., “Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference” (2018)

Constructors

Constructor Summary
QATTrainingHook(QuantizationConfiguration config) Initializes a new instance of the QATTrainingHook.

Properties

Property Summary
bool IsQuantizationEnabled { get; } Gets whether quantization is currently enabled.
int CurrentEpoch { get; } Gets the current epoch number.

Methods

Method Summary
QuantizationState GetLayerState(string layerName) Gets the current quantization state for a layer.
Vector<T> ApplyFakeQuantization(Vector<T> weights, string layerName) Applies fake quantization to weights during the forward pass.
Vector<T> ApplyFakeQuantizationToActivations(Vector<T> activations, string layerName) Applies fake quantization to activations during the forward pass.
Vector<T> StraightThroughEstimator(Vector<T> gradOutput, Vector<T> quantizedWeights, Vector<T> originalWeights) Applies the Straight-Through Estimator for gradient computation.
void OnEpochStart(int epoch) Called at the start of each training epoch to manage warmup and quantization state.
void Reset() Resets the quantization state for all layers.
void UpdateScales(string layerName, double learningRate) Updates quantization scales based on observed statistics (for learnable scales).