Compression Concepts
This section describes the concepts used in model compression and the principles of different compression methods.
Quantization
Quantization is a process of processing the weights and activations of a model into low bits for making the generated network model liter, thereby saving the storage space of the network model, reducing the transmission delay, improving the compute efficiency, and enhancing the performance.
AMCT separates quantization and model conversion to independently quantize quantizable operators in a model and output the quantized model. The resultant fake-quantized model can run on the CPU or GPU to complete accuracy simulation, while the quantized deployable model can run on the AI processor to improve inference performance.
Currently, this tool can quantize only network models of the float32 or float16 data type (the Caffe framework does not support the float16 data type). The following figure shows the working principles of quantizing a network model to the INT8 data type.
- Quantized data type
Indicates the data type after quantization.
Atlas 350 Accelerator Card: The supported quantized data types are HIFloat8 (HiF8), FLOAT8 (float8), MXFP8, MXFP4, FP4_E2M1, FP4_E1M2, INT8, and INT4.
Non-Atlas 350 Accelerator Card: Quantization based on torch module supports INT8 and INT4 quantized data types. QAT supports only INT8.Table 1 Quantized data types Quantized Data Type
Description
HIFloat8 (HiF8)
HIFloat8 (HiF8) is an AI processor-customized 8-bit floating-point data format, consisting of one sign bit (indicating positive/negative), dot bits, exponent bits (representing the value range), and mantissa bits (representing significant digits). HiF8 expands upon IEEE 754 by adding a dot field to dynamically adjust the exponent and mantissa bit widths.

S indicates the HiF8 sign field value, E indicates the HiF8 exponent field value, and M indicates the HiF8 mantissa field value. When the Dot bit is 0b'0000, the HiF8 data is a denormal value.
The conversion principles are as follows. You can configure this type in the configuration file. For details, see config.
- float32, bfloat16, or float16 NAN is converted to HiF8 NaN.
- float32, bfloat16, or float16 INF is converted to HiF8 INF with the sign bit unchanged.
- Values of float32/bfloat16/float16 whose absolute value exceeds the maximum representable value of HiF8 are converted to the maximum value in HiF8 with the sign bit unchanged.
- Values of float32, bfloat16, or float16 whose absolute value is less than the minimum representable value of HiF8 are converted to 0 in HiF8.
Other values are converted in rounding mode.
Note: Due to the inherent precision limitations of HiF8 and float8, if the source input data contains values whose absolute value is less than 1.5 × 2^–10, the precision cannot be guaranteed during conversion to float8; if the source input data contains values whose absolute value is less than 1.5 × 10^–24, the precision cannot be guaranteed during conversion to HiF8.
FLOAT8 (float8)
float8 is a derivative of float16 and has two encoding formats: E4M3 and E5M2. Currently, only the E4M3 encoding format is supported.- E4M3 contains a 4-bit exponent, a 3-bit mantissa, and a 1-bit sign bit, and is used in forward propagation during training.
- E5M2 contains a 5-bit exponent, a 2-bit mantissa, and a 1-bit sign bit, and is used in backward propagation during training. E4M3 has a smaller data range than E5M2 but higher precision. It is used for inference.
The conversion principles are as follows. You can configure this type in the configuration file. For details, see config.
- float32, bfloat16, or float16 NaN is converted to float8 NaN.
- Values of float32, bfloat16, or float16 whose absolute value exceeds the maximum representable value of float8 are converted to the maximum value in float8 with the sign bit unchanged.
- Values of float32, bfloat16, or float16 whose absolute value is less than the minimum representable value of float8 are converted to 0 in float8.
Other values are converted in Round to the Nearest, Ties to Even (RINT) mode.
Note: Due to the inherent precision limitations of HiF8 and float8, if the source input data contains values whose absolute value is less than 1.5 × 2^–10, the precision cannot be guaranteed during conversion to float8; if the source input data contains values whose absolute value is less than 1.5 × 10^–24, the precision cannot be guaranteed during conversion to HiF8.
MXFP8
MXFP8 is a low-precision 8-bit floating-point representation based on the microscaling format. It consists of a scaling factor and elements, with multiple elements sharing one scaling factor. Compared with traditional 16-bit floating-point (fp16) or 32-bit floating-point (fp32) formats, MXFP8 significantly reduces data storage and transmission requirements and decreases memory usage for LLMs, thereby improving inference performance.
FP8_E4M3FN is a type of FP8 data format. It is an 8-bit floating-point quantization format, consisting of a 4-bit exponent, a 3-bit mantissa, and a 1-bit sign bit (FP8_E4M3FN). Compared with FP8, MXFP8 has an additional shared exponent (a data representation method in which multiple elements share one exponent). By using the microscaling technology, MXFP8 can provide higher precision and finer quantization than FP8.
The conversion principles are as follows. You can configure this type in the configuration file. For details, see config.
- Conversion from float32, bfloat16, or float16 to float8:
- float32, bfloat16, or float16 NaN is converted to float8 NaN.
- Values of float32, bfloat16, or float16 whose absolute value exceeds the maximum representable value of float8 are converted to the maximum value in float8 with the sign bit unchanged.
- Values of float32, bfloat16, or float16 whose absolute value is less than the minimum representable value of float8 are converted to 0 in float8.
Other values are converted to FP8_E4M3FN in RINT mode.
MXFP4
MXFP4 is a low-precision 4-bit floating-point representation based on the microscaling format. It consists of a scaling factor and elements, with multiple elements sharing one scaling factor. Compared with traditional 16-bit floating-point (fp16) or 32-bit floating-point (fp32) formats, MXFP4 significantly reduces data storage and transmission requirements and decreases memory usage for LLMs, thereby improving inference performance.
FP4_E2M1 is a type of FP4 data format. It is a 4-bit floating-point quantization format, consisting of a 2-bit exponent, a 1-bit mantissa, and a 1-bit sign bit (FP4_E2M1). Compared with FP4, MXFP4 has an additional shared exponent (a data representation method in which multiple elements share one exponent). By using the microscaling technology, MXFP4 can provide higher precision and finer quantization than FP4.
The conversion principles are as follows. You can configure this type in the configuration file. For details, see config.
- Conversion from float16 or bfloat16 to FP4_E2M1: Values less than the minimum value of FP4_E2M1 are converted to the minimum value of FP4_E2M1, and values greater than the maximum value of FP4_E2M1 are converted to the maximum value of FP4_E2M1. NaN and INF cannot be converted to each other. Other values are converted to FP4_E2M1 in RINT mode.
- MXFP4 data format conversion: For the weight tensor data of the torch.nn.Linear operator, a shared exponent is calculated for every 32 data elements in the -1 axis direction. The calculation formula is as follows:
FP4_E2M1
FP4_E2M1 is a type of FP4 data format. It is a 4-bit floating-point quantization format, consisting of a 2-bit exponent, a 1-bit mantissa, and a 1-bit sign bit (FP4_E2M1).
The conversion principles from high-precision float16 or bfloat16 to low-precision FP4_E2M1 are as follows. You can configure this type in the configuration file. For details, see config.
Values less than the minimum value of FP4_E2M1 are converted to the minimum value of FP4_E2M1, and values greater than the maximum value of FP4_E2M1 are converted to the maximum value of FP4_E2M1. NaN and INF cannot be converted to each other. Other values are converted to FP4_E2M1 in RINT mode.
FP4_E2M1 can represent 16 values: {±0, ±0.5, ±1, ±1.5, ±2, ±3, ±4, ±6}.
FP4_E1M2
FP4_E1M2 is also a type of FP4 data format. It is a 4-bit floating-point quantization format, consisting of a 1-bit exponent, a 2-bit mantissa, and a 1-bit sign bit (FP4_E1M2).
The conversion principles from high-precision float16 or bfloat16 to low-precision FP4_E1M2 are as follows. You can configure this type in the configuration file. For details, see config.
Values less than the minimum value of FP4_E1M2 are converted to the minimum value of FP4_E1M2, and values greater than the maximum value of FP4_E1M2 are converted to the maximum value of FP4_E1M2. NaN and INF cannot be converted to each other. Other values are converted to FP4_E1M2 in RINT mode.
FP4_E1M2 can represent 16 values: {±0.0, ±0.25, ±0.5, ±0.75, ±1.0, ±1.25, ±1.5, ±1.75}. Conversion from low precision to high precision does not involve mantissa rounding or handling of special values such as NaN and INF.
INT8
The 8-bit INT8 data is used to represent 32-bit float32 data, and a float matrix multiplication operation is converted into an INT8 matrix multiplication operation. This reduces the model size, speeding up computing.
In PTQ scenarios, weight quantization supports only the INT8 mode. Activation quantization supports the INT8 and INT16 modes. Currently, only INT8 quantization is supported.
INT4
The 4-bit INT4 data is used to represent 32-bit float32 data. Compared with INT8 quantization, INT4 quantization delivers better compression performance but may result in greater precision loss.
INT16
The 16-bit INT16 data is used to represent 32-bit float32 data, and a float32 convolution operation (multiply-add operation) is converted into an INT16 convolution operation. This reduces the model size, speeding up computing.
If INT8 quantization fails to meet the precision requirements, you are advised to adopt INT16 quantization.
General Description
- HiF8 achieves a better balance between precision and dynamic range than float8, while MXFP8 and MXFP4 reduce memory usage for LLMs.
- MXFP8 and MXFP4 feature dedicated hardware acceleration units for faster quantization factor processing.
- For FP4_E2M1 and FP4_E1M2, use FP4_E1M2 for uniformly distributed data and FP4_E2M1 for Gaussian-distributed data.
- PTQ
PTQ refers to quantization executed after the model training is complete. Weights of the trained model are quantized from floating-point values to low-bit integers, and activations are calibrated and quantized during inference with a small amount of calibration data to minimize precision loss introduced by quantization. PTQ is easy to use and requires only a small calibration dataset, which is applicable to scenarios where ease of use and resource saving take priority.
In general, after model training, the weights are determined. Therefore, the quantization parameters of a weight can be calculated offline based on the determinate weight value. In contrast, activations are input online. As such, the accurate value ranges are hard to be obtained and a small representative dataset is required to simulate the distributions of online activations. To obtain the quantization parameters of an activation, use the said dataset to run forward passes for the intermediate floating-point results, and calculate the quantization parameters of the activation offline based on the results. The following figure shows the working principles.
Figure 2 PTQ principles
- QAT
QAT acts by including quantization in the retraining process to address the effects of quantization on the model accuracy. QAT, which generally requires a complete training dataset, emulates the errors incurred by quantization in forward passes by introducing fake-quantization (quantizing floating-point numbers to fixed-point ones, and then dequantizing them to floating-point ones) in the training process, and updates weights in training on top of the said errors, ensuring less accuracy drop in quantization.
QAT is often better than PTQ for model accuracy, but it is more time-consuming and requires a complete training dataset.
The following figure shows the working principles.
Figure 3 QAT principles
- Weight quantization and activation quantization
Currently, the AI processor supports symmetric and asymmetric quantization for activations, and only symmetric quantization for weights. (Quantization can be classified into symmetric quantization and asymmetric quantization based on whether the data center point is 0 after quantization. For details about the quantization algorithm principles, see Quantization Algorithm Principles.)
- Weight quantization refers to quantizing weights into lower-bit formats according to the distribution of weight values.
- In PTQ, the weight quantization is conducted offline. Weights are read directly from your inference model, and are quantized using the quantization algorithm. After that, the quantized weights are written back to your model for activation quantization.
- In QAT, the original floating-point weights are quantized during the forward pass, and the resulting quantized weights are used for forward computation. In the backward pass, the received gradients are applied to update the original floating-point weights.
- Activation quantization, also referred to as data quantization, means quantizing input activations into low-bit formats based on their value distribution. As the value distribution of each layer is unknown and wide-ranging until the forward pass (inference or training), activation quantization must be performed during inference or training.
- In PTQ, online quantization is adopted. The inference model is modified by inserting bypass quantization nodes at target layers to collect input activations, and the quantization factors scale and offset are obtained via calibration. A small dataset is typically used during inference to approximate the value distribution of the full dataset, featuring simple operation and fast execution.
- In QAT, the quantization factors scale and offset for activations are trainable parameters. During the forward pass, activations are quantized using the corresponding scale and offset. In the backward pass, backward gradients are utilized to calculate and update these scale and offset values.
- Weight quantization refers to quantizing weights into lower-bit formats according to the distribution of weight values.
- Test dataset
The test dataset is a dataset subset for the final test of model accuracy.
- Calibration
Calibration refers to the process of performing forward inference to obtain data quantization factors in PTQ.
- Calibration dataset
The calibration dataset is used for forward inference in PTQ. Its distribution should represent that of the full dataset. When selecting the calibration dataset, ensure it is representative; a subset of the test dataset is recommended. If the calibration dataset does not match the model or lacks representativeness, the quantization factors calculated from it will perform poorly on the full dataset, resulting in large quantization loss and low post-quantization accuracy.
- Training dataset
The training dataset is a subset of the user's training network dataset, used for model training.
- Quantization factors
Quantization factors are the parameters used to quantize floating-point values to integers. The factors include scale and offset. The formula for quantizing floating-point values to integers (using INT8 as an example) is as follows:

- scale: scaling factor for floating-point values. This parameter is further divided into:
- scale_d: scale factor for activation quantization. Only uniform activation quantization is supported.
- scale_w: scale factor for weight quantization. Scalar (uniform quantization for weights of the current layer) and vector (channel-wise quantization for weights of the current layer) modes are supported. For more details about the parameters, see Record Files (PyTorch is used as an example. For details, see the record files of specific frameworks.)
- offset: quantization factor, indicating the offset. This parameter is further divided into:
- offset_d: offset factor for activation quantization. Only uniform activation quantization is supported.
- offset_w: offset factor for weight quantization. Similar to scale_w, this parameter supports both scalar and vector modes, and its dimension must be the same as that of scale_w. For more details about the parameters, see Record Files (PyTorch is used as an example. For details, see the record files of specific frameworks.)
- scale: scaling factor for floating-point values. This parameter is further divided into:
- Quantization sensitivity
Model outputs vary at different precision levels. A model generally delivers better inference accuracy in high precision. Quantization, which reduces the precision of a model or certain layers, may hurt the model's inference accuracy. To quantify the impact, the concept of quantization sensitivity is introduced.
Quantization sensitivity is used to measure the degree to which network models or quantizable layers are affected by quantization. Quantization sensitivity is calculated by comparing the output discrepancies of the entire network or individual layers before and after quantization. Common metrics include Mean Square Error (MSE) and cosine similarity.
- Bit complexity
The floating-point computation amount of a model layer is denoted as Flops. Bit complexity (bitops) combines Flops with data precision, describing the computational resource differences across different precision levels (such as float32, float16, INT8, and INT4).
The calculation formula is as follows, where Flops indicates the floating-point calculation amount, act_bit indicates the activation precision, and wts_bit indicates the weight precision.

- Quantization granularity
Quantization granularity refers to the quantization computation levels applied to different input tensors of matrix operators such as MatMul in a neural network. Common quantization granularities are as follows.
- The variables m, n, and k indicate the sizes of different axes of a tensor.
- The left matrix and right matrix refer to the two input tensors used for matrix multiplication computation in the cube operator. Generally, the left matrix represents activation, and the right matrix represents weight. Verify against your actual implementation.
- Per-channel quantization
Shortened as C quantization. This scheme quantizes the right matrix, with independent quantization parameters assigned to each channel. Assume that the shape of the right matrix is (k, n), where k is the reduce axis. The shape of the generated quantization parameter is (n, ).
Figure 4 Per-channel quantization
- Per-group quantization
Shortened as G quantization. This scheme supports quantization for either the left or right matrix (only the right matrix is supported in AMCT). Data is grouped along the reduce axis, with each group using independent quantization parameters.
Assume that the shape of the right matrix is (k, n), where k is the reduce axis. If data is grouped along the k axis with a group size of gs, the shape of the generated quantization parameters is (k/gs, n).
Figure 5 Per-group quantization
- Per-tensor quantization
Shortened as T quantization. This scheme can quantize either the left or right matrix, where each tensor uses a shared quantization parameter.
Assume that the shape of the left matrix is (m, k) and the shape of the right matrix is (k, n), where k is the reduce axis. The shape of the generated quantization parameter is (1, ).
Figure 6 Per-tensor quantization
- Per-token quantization
Shortened as K quantization. This scheme quantizes the left matrix, with independent quantization parameters assigned to each token.
Assume that the shape of the left matrix is (m, k), where k is the reduce axis. The shape of the generated quantization parameters is (m, ).
Figure 7 Per-token quantization
Sparsity
Sparsity refers to implementing weight sparsification for certain operators in a model via structured pruning, to generate a less computationally expensive model with fewer parameters. Currently, AMCT has two sparsity modes: filter-level sparsity and 2:4 structured sparsity. For compressible operators at the same layer, only one sparsity mode can be enabled at a time.
Compared with 2:4 structured sparsity, filter-level sparsity has a larger granularity and has a greater impact on model accuracy, but can obtain more performance benefits. You can select a sparsity mode based on your need.
- Filter-level sparsity
Filter-level sparsity reduces the number of network channels (filters) based on retraining, to achieve fewer model parameters and smaller computational demand with network functionality intact. Filter-level sparsity prunes less important channels. However, channel pruning may cause significant degradation in model accuracy, which necessitates retraining the sparsified model. The filter-level sparsity is a two-step process. The first is filter selection, where a proper filter set is selected to retain the most information; the second is the reconstruction of the next-layer output using the selected filters. The following figure shows the principles of filter-level sparsity.
Figure 8 Filter-level sparsity
- 2:4 structured sparsity
Due to hardware restrictions, the Atlas 350 Accelerator Card,
Atlas inference product andAtlas training product do not support the 2:4 structured sparsity feature.2:4 structured sparsity, based on retraining, reserves two greater weights among every four consecutive weights, and sets the remaining weights to 0. This sparsity mode features smaller granularity, and therefore can retain a larger amount of important information. It can also reduce the computing workload on specially designed hardware, enjoying the performance advantage of structured sparsity. Unlike filter-level sparsity, 2:4 structured sparsity does not change the shape of the weight, and therefore does not affect the operator of the upper or lower layer.
The following figure shows the principles of this sparsity mode. Four adjacent elements in the cin dimension form a group. The two elements with the largest absolute values in each group are reserved. If cin is not a multiple of 4, 0 is padded until the value becomes a multiple of 4.
Figure 9 2:4 structured sparsity
Compression Combination
Compression combination, as its name suggests, applies a combination of sparsity and quantization. It goes through two phases: sparsity based on the configuration file and quantization. In the first phase, the sparsity operator is inserted based on the corresponding algorithm. In the next phase, the quantization layer for activations and weights and a searchN layer are inserted into the sparsified model to generate a compressed model, for achieving a higher performance benefit. Then you retrain the said model and save it as a model that can be used for both accuracy simulation and inference deployment.
Layer-wise Distillation
Distillation is a model compression method, which uses the supervision information of the original model to train the quantized model, achieving a higher quantization accuracy.
This method uses the pre-trained original model as the teacher network, and performs the supervised training on the student network. By computing the loss of the predicted values output by the teacher network and student network, the gradients are updated to obtain a quantized model with higher accuracy.
- Compared with PTQ, the knowledge distillation can achieve better accuracy results.
- Compared with QAT, the knowledge distillation does not require labeled datasets and can obtain good quantization results in a shorter time.
Tensor Decomposition
Deep learning computation, especially in the context of computer vision (CV), involves a large volume of convolution operations. Tensor decomposition converts a convolution kernel into two continuously-multiplied smaller convolution kernels (low-rank tensors), resulting in smaller storage and computational demands and lower inference overhead.
Take a 64 × 64 × 3 × 3 convolution as an example. Decomposing it into the 32 × 64 × 3 × 1 and 64 × 32 × 1 × 3 convolution cascades can save 66.7% computation workload, that is, 1 – (32 × 64 × 3 × 1 + 64 × 32 × 1 × 3)/(64 × 64 × 3 × 3), and produce more cost-effective performance benefits with inconsequential accuracy drop. The following figure shows the working principles of tensor decomposition in the PyTorch framework.
Model Optimization for Deployment
The optimization involves mainly operator fusion, which refers to fusing the operators in a model into single-operators through mathematical equivalence and reduces the amount of computation in forward passes. For example, a convolutional layer and a BN layer can be fused into a new convolutional layer.
The following figure shows the working principles in the PyTorch framework.

