Hot AI News

Quantization-aware training: How a model learns to live with 4-bit weights

Quantization-aware training lets a model practice with 4-bit numbers during training, so shrinking it later costs little accuracy. Baidu and Moonshot AI both use it.

Quantization-aware training: How a model learns to live with 4-bit weights
Image: Baidu, official Hugging Face model card

Quantization-aware training (QAT) is a way of training an AI model while it pretends to use low-precision numbers, such as 4-bit weights. Because the model learns to cope with the rounding error, the small version it ships as loses far less accuracy than one that is simply squeezed afterward.

Plain quantization is covered in our news story on Baidu’s ERNIE 5.5 Flash Preview and elsewhere on the site. QAT is the training-time half of that story.

Practicing with the rounding before the exam

Imagine a student who will take an exam with a basic calculator that rounds every result to one decimal. A student who only ever practiced with a full scientific calculator will be surprised by the errors. A student who practiced with the rounding calculator learns tricks that keep the answers right anyway.

QAT is that second kind of practice. A model’s weights are the numbers it has learned. Normally they are stored with 16 bits each. Cutting them to 4 bits saves memory and speeds up serving, but every weight gets nudged to the nearest allowed value. Post-training quantization applies that nudge once, after training is finished. QAT applies it during training, so the model adapts to it.

Advertisements

Fake quantization and a gradient shortcut

During QAT, the training code keeps a full-precision copy of every weight, often called the master weights. On each forward pass, it rounds a copy of them to the low-precision grid and then converts them back to normal numbers. This is called fake quantization: the arithmetic still runs in a wide format, but the values carry the rounding error they will have in production.

There is one catch. Training needs gradients, which say how to adjust each weight. Rounding is a staircase function, and its slope is zero almost everywhere, so a gradient cannot pass through it. The standard fix is the straight-through estimator: on the backward pass, the code pretends rounding was an identity function and lets the gradient through unchanged. The update then lands on the full-precision master weights.

When training ends, the weights are rounded for real and packed into the small format. The model has already seen exactly that rounding thousands of times.

Scaling matters too. Weights are usually split into small groups that each get their own scale factor. In an open reproduction of the method, the SGLang team used groups of 32 values with 4-bit integers and clipped to the range -7 to 7.

From 8-bit phones to billion-parameter models

The idea is older than large language models. In 2017, Benoit Jacob and colleagues at Google published a scheme that simulated 8-bit integer arithmetic during training and then ran inference with integers only. Their results centered on MobileNets running on phone-class ARM processors, with about a 4x memory reduction against 32-bit floats. The paper appeared at CVPR in 2018.

For language models, Zechun Liu and colleagues at Meta published LLM-QAT in 2023. Full training data for a large model is often unavailable, so they let the original model generate its own training text and used it to teach the quantized version. They tested LLaMA models of 7B, 13B and 30B parameters at down to 4 bits. They reported gains over training-free methods, especially at the lowest bit widths. They also quantized the KV cache, the memory a model uses to remember earlier tokens.

Advertisements

Who uses it now, including Baidu

Reasoning models make the problem sharper. They write very long answers, and small errors can add up over thousands of generated tokens. Moonshot AI, the maker of Kimi, wrote in the Kimi K2 Thinking model card that quantization often causes big performance drops for such models. The company applied QAT during post-training, with 4-bit integer weights on its mixture-of-experts layers. It says this gave roughly a 2x generation speedup, and that all its benchmark scores were reported at INT4 precision. Those are Moonshot’s own claims.

Baidu’s ERNIE-5.5-Flash-Preview does something similar. Its model card says the routed experts, which hold most of the parameters, are stored in a 4-bit floating-point format called MXFP4 and run as W4A8. That label means 4-bit weights and 8-bit activations, the intermediate values a layer passes along. Baidu says it applied this QAT during post-training, and that the fake quantization uses the same granularity, scaling and rounding rules as inference, so training and serving agree numerically.

That is why the ERNIE release can be deployed without conversion or calibration, as Baidu puts it. The default download holds the 4-bit experts. Separate FP8 and BF16 copies exist for hardware without 4-bit kernels, and Baidu recommends the BF16 copy as the starting point for fine-tuning.

Costs, limits and what to watch

QAT is not free. It needs the training run itself, so it is something the model’s maker does, not the user who downloads the weights. The SGLang team reports that fake quantization makes training noticeably slower than plain BF16 training. Baidu’s card says its training throughput is largely unaffected. The two accounts cover different setups and are the authors’ own measurements.

The benefits also depend on hardware. The SGLang team notes that on H-series GPUs, 4-bit weights with 16-bit activations still run on 16-bit tensor cores, so the speedup over FP8 is not large. The gain is mostly smaller memory use, which lets a roughly 1 TB model fit on a single node.

Format also matters. Kimi uses integers, Baidu uses MXFP4, and the two are not interchangeable. A model trained for one grid is not guaranteed to survive a different one.

Three things are worth watching: whether independent evaluations confirm the lossless claims, whether QAT moves from post-training into pretraining, and whether more open-weight releases ship low-bit checkpoints as the default download.

Sign Up for the Daily AI Pulse

One email a day. All the stories that matter.

Daniel ReedAI Research, Safety & Ethics Analyst

Daniel Reed currently works as an AI Research, Safety & Ethics Analyst at Aiholics, writing about how changes in artificial intelligence are affecting and will affect scholarship,…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like