int4 Quantization-Aware Training: How to Estimate and Choose Deployment GPU Memory

    This article explains how int4 quantization reduces deployment weight memory, why QAT does not reduce training memory, and how to estimate weights, KV cache, activations, and framework overhead. It also covers PTQ versus QAT selection, deployment validation, rollback planning, and common troubleshooting steps.

    1. Conclusion First: int4 Mainly Compresses Deployment Weight Memory

    int4 quantization compresses each weight from 16 bits to 4 bits, so weight memory is roughly one quarter of the original. This benefit occurs during inference and deployment. Quantization-aware training (QAT) itself does not reduce training memory; it is usually higher because training must keep high-precision master weights, gradients, and optimizer states. Therefore, when deciding whether to introduce int4, separate two questions: whether the model can fit during deployment, and whether you can afford the training cost of QAT.

    During LLM inference, GPU memory must hold model weights, KV cache, intermediate activations, and runtime framework overhead at the same time. Weights usually account for the largest share. With 16-bit floating-point storage, each parameter takes 2 bytes. A 27-billion-parameter (27B) model alone requires about 54GB just for weights, exceeding the memory capacity of most consumer-grade GPUs.

    2. Quantization Basics: From Floating Point to Integer

    Quantization maps continuous floating-point values to a finite set of integers. A signed 4-bit integer can represent values in the range [-8, 7], for 16 levels in total. A common formula is:

    1. q = clip(round(x / s) + z, q_min, q_max)
    2. x_hat = s * (q - z)

    Here, x is the original value, s is the scale factor, z is the zero point, and x_hat is the approximate value after dequantization. The error mainly comes from two steps: round and clip. clip truncates values outside the range, so the choice of scale directly affects the error size.

    In practice, scale factors are usually calculated group-wise rather than shared across an entire tensor. Smaller groups make each group’s distribution closer to local characteristics and reduce error, but they require more scale parameters to be stored. A common approach is to share one set of scale parameters for every 128 weights. The exact value should be based on evaluation results for the framework and model being used.

    For the zero point, symmetric quantization sets z to 0. This is simple to implement and suitable for weights with approximately symmetric distributions. Asymmetric quantization uses a nonzero z, which can better cover skewed distributions, but it requires storing an additional zero-point parameter and makes computation slightly more complex.

    Based on when quantization occurs, mainstream methods fall into two categories:

    • Post-training quantization (PTQ): Quantize after model training is complete, relying on a small amount of calibration data to determine scale factors. The process is short and low-cost, but accuracy loss at 4 bits is usually more obvious.
    • Quantization-aware training (QAT): Simulate quantization error during training so that parameters adjust under quantization constraints. Accuracy at low bit widths is usually better, at the cost of higher training expense.

    3. How Quantization-Aware Training Works

    The core of QAT is fake quantization. During the forward pass, weights are first quantized and then dequantized. The network sees values with quantization error, so the loss function can reflect the impact of quantization.

    The round and clip operations in the quantization function are non-differentiable. A common approach is to approximate gradients with a straight-through estimator (STE): during backpropagation, ignore the derivative of round and pass the gradient directly to the original floating-point weights. STE is only an approximation. It does not change the forward computation and does not guarantee convergence to an optimal solution.

    The following schematic code only illustrates the idea and cannot be used directly in production:

    1. def fake_quantize_int4(w, scale, zero_point=0):
    2. # Forward: quantize then dequantize to simulate deployment error
    3. q = clamp(round(w / scale) + zero_point, -8, 7)
    4. return scale * (q - zero_point)
    5. # Key steps in the training loop:
    6. # 1. Use w_hat = fake_quantize_int4(w, s) in the forward pass
    7. # 2. In the backward pass, gradients pass through the straight-through estimator to the floating-point weights w
    8. # 3. The optimizer updates the high-precision copy of w

    A real implementation requires support from the framework’s quantization operators. It also requires preparing a calibration set, choosing fine-tuning epochs, and comparing accuracy on an evaluation set. scale and zero point can be fixed or treated as learnable parameters during training. This choice affects training stability and memory usage, and should be set according to the documentation of the method being used.

    Training memory deserves a separate estimate. Taking mixed precision plus Adam as an example, a common rule of thumb is about 16 bytes per parameter, including 16-bit weights, 32-bit master weights, gradients, and two optimizer states. Under this rule of thumb, a 27B model requires about 430GB just for training states, excluding activations. Therefore, the training threshold for QAT is usually much higher than for inference. You should first confirm whether training resources are sufficient before deciding whether to take the QAT route.

    4. Estimating Memory Benefits

    4.1 Estimation Formulas

    Weight memory (GB) ≈ number of parameters (billions) × bits per parameter ÷ 8

    Here, GB is calculated in decimal terms, i.e., 10^9 bytes. This formula only estimates weights and does not include other components.

    Total deployment memory should be estimated as follows:

    1. Total memory ≈ weights + KV cache + activations + framework overhead + headroom

    A rough formula for KV cache is:

    1. KV cache (bytes) = 2 × layers × KV heads × head dimension × context length × concurrency × bytes per element

    The coefficient 2 represents the two copies for K and V. It is recommended to reserve 10% to 20% headroom for memory fragmentation and peak fluctuations.

    4.2 Three Data Points

    Parameter scale 16-bit weights int4 weights (theoretical) Reported int4 value Reduction (based on reported value)
    27B About 54GB 13.5GB About 14.1GB About 73.9%
    12B About 24GB 6.0GB About 6.6GB About 72.5%
    1B About 2GB 0.5GB About 0.5GB About 75%

    The source 12B occupied figure was back-calculated from a 72% reduction to about 23.6GB. Calculating 12B × 2 bytes gives 24GB for 16-bit weights. Therefore, the reduction should be recalculated from 24GB, giving about 72.5%.

    There are two main sources of the gap between theoretical values and reported values. First, group scaling parameters. If every 128 weights are paired with one 16-bit scale value, each parameter adds an average of 0.125 bits, for a total of 4.125 bits. On this basis, 27B is about 13.9GB, and 12B is about 6.2GB. Second, unquantized layers, such as embedding layers, normalization layers, and output layers, usually remain at higher precision. The remaining difference needs to be confirmed against the actual model file.

    The data scope is limited. The original source did not provide the model name, inference framework, context length, concurrency, or measurement method, so the statistical scope of the values cannot be confirmed. The table should be treated as an order-of-magnitude reference. Before use, retest with your own model on the target framework, and record both weight memory and runtime peak memory.

    5. Deployment Selection and Implementation Steps

    1. Define constraints. Record the target hardware’s memory capacity, latency ceiling, expected concurrency, and maximum context length. These numbers determine the budget for the following steps.
    2. Estimate the memory budget. Use the formulas in Section 4 to calculate weights, KV cache, activations, and framework overhead, then add 10% to 20% headroom. If the total exceeds the available GPU memory, the int4 single-GPU plan is insufficient. You need to reduce concurrency or context length, or use a GPU with more memory.
    3. Establish a baseline. Test the 16-bit (or higher-precision) model on the same evaluation set, and record accuracy, output quality, and latency. Without a baseline, it is impossible to judge the loss caused by int4.
    4. Choose the quantization route. When budget is limited or training resources are insufficient, try PTQ first. If the accuracy drop after PTQ exceeds the acceptable business range, then consider QAT. The calibration set should cover real business inputs. A common practice is to take hundreds to thousands of representative samples.
    5. Acceptance and rollback. Define acceptance criteria in advance, such as an accuracy drop relative to the baseline no greater than the business threshold, and peak memory below a certain ratio of the target value. After acceptance, first release to a small canary traffic share, and keep the 16-bit version as a rollback plan.

    5.1 When int4 Is and Is Not Suitable

    Scenario Suitable for int4? Recommendation
    Tight single-GPU memory, short context, moderate accuracy tolerance Suitable Deploy int4 directly and validate according to the process in Section 5
    Long context or high concurrency Use with caution KV cache share rises, and the benefit of int4 weights is diluted. Consider KV cache quantization, reducing concurrency, or using a different GPU
    Accuracy-sensitive workloads (code generation, mathematical reasoning, medical or financial) Use with caution Evaluate int8 first, or keep a high-precision model. int4 requires extensive evaluation
    Limited training resources PTQ first Do not perform QAT yourself. You can use published quantized weights and evaluate them yourself

    6. Common Troubleshooting

    Symptom Possible cause Action
    OOM at startup Weights plus framework overhead exceed GPU capacity Check the actual size of the weight file, confirm it is loaded as int4, and reduce context length or batch size
    OOM during long dialogue or high concurrency KV cache grows with context and concurrency Limit maximum context length, reduce concurrency, and evaluate KV cache quantization
    Obvious accuracy drop Group size too large, calibration set does not match the business, or sensitive layers are quantized Reduce group size, change the calibration set, and keep sensitive layers at higher precision
    Increased latency Framework lacks int4 kernels, or dequantization overhead is high Confirm whether the framework provides corresponding kernels, and compare throughput across batch sizes
    NaN or abnormal output values scale close to zero or overflow, or abnormal value distribution in some layers Set a lower bound for scale (such as a very small positive eps), and inspect the weight distribution of abnormal layers

    7. Summary

    int4 quantization can effectively reduce deployment-stage weight memory, but the benefit is mainly in the weight portion, and the training cost of QAT is higher. First calculate the deployment budget and establish an accuracy baseline, then decide whether to use PTQ or QAT. This makes the decision more reliable.