# Quantization Aware Training (QAT)

## Overview

Quantization Aware Training (QAT) is a technique for improving the accuracy of models which are quantized by applying “fake” quantizations to the model’s weights (and optionally, activations) during training. This fake quantization allows for the model to adjust for noise introduced by the quantization, so when the model is eventually quantized, the accuracy loss is minimized. We use the quantization techniques implemented in torchao to provide support for QAT and post-training quantization (PTQ) in axolotl.

We recommend reviewing the excellent QAT tutorial in the torchtune library, and the QAT documentation in the torchao library, for more details.

## Configuring QAT in Axolotl

To enable QAT in axolotl, add the following to your configuration file:

    qat:
      activation_dtype: # Optional[str] = "int8". Fake quantization layout to use for activation quantization. Valid options are "int4" and "int8"
      weight_dtype: # Optional[str] = "int8". Fake quantization layout to use for weight quantization. Valid options are "int4" and "int8"
      group_size: # Optional[int] = 32. The number of elements in each group for per-group fake quantization
      fake_quant_after_n_steps: # Optional[int] = None. The number of steps to apply fake quantization after

Once you have finished training, you must quantize your model by using the same quantization configuration which you used to train the model with. You can use the `quantize` command to do this.