
When I built PocketBot, I had a simple goal: a chatbot that answers questions from a business's own...
When I built PocketBot, I had a simple goal: a chatbot that answers questions from a business's own FAQ, runs entirely in the browser, and never sends data to a server. No API keys, no per-request costs, no privacy worries. The hard part was size. A useful language model is usually measured in gigabytes. A browser tab is not.
This article explains the technique that made it possible — quantization-aware training (QAT) — using real numbers from the PocketBot build, and why the naive approach quietly destroys accuracy.
PocketBot starts from SmolLM2-135M, a 135-million-parameter language model. In full precision (FP32), 135 million parameters take roughly 540 MB. Even in FP16, you are around 270 MB. Browsers can technically load that, but "can" and "should" are different words. Download time, memory pressure on cheap laptops, and mobile data costs all say no.
Quantization shrinks the model by storing weights in fewer bits. At 4 bits per weight, 135 million parameters need only about 68 MB plus overhead — PocketBot ships at roughly 89 MB. That is the difference between a demo and a deployable product.
But there is a catch, and it is the whole story of this article.

A 4-bit weight can hold only 16 values. Naive rounding snaps and hopes; QAT trains with the snapping on.
The simplest quantization is post-training quantization (PTQ): take a trained model, round every weight to the nearest 4-bit value, ship it. It is fast and easy. It is also lossy in a way that matters.
Neural network weights are not evenly distributed. A small number of outlier weights carry outsized importance, and rounding them coarsely shifts the model's behavior. In my PocketBot experiments, plain 4-bit rounding dropped next-token accuracy to 88.8% (from the full-precision fine-tuned baseline). For a chatbot answering customer questions, that accuracy loss shows up as subtly wrong, less reliable answers — exactly what a business FAQ bot cannot afford.
The model still "works." It just works worse, in ways that are hard to notice in a quick demo and painful in production.
Quantization-aware training flips the order. Instead of quantizing after training, you simulate quantization during training. The model experiences the rounding noise while it is still learning, so it adapts: weights settle into values that survive 4-bit rounding with minimal damage.
Think of it like training an athlete with a weighted vest. The constraint is present during practice, so performance under the constraint becomes the thing being optimized.
In practice, QAT adds "fake quantization" operations in the forward pass: weights are rounded to 4-bit precision and immediately dequantized back, so gradients still flow, but the model learns under realistic rounding error. At export time, the weights convert cleanly to true 4-bit storage.

The QAT pipeline: fine-tune, simulate 4-bit rounding, adapt, export an 89 MB ONNX model.
Here is what this meant in the actual build:
An 8-point accuracy recovery at identical size is the difference between "interesting experiment" and "I would put this on a client's website." That is the entire argument for QAT in one line: same bytes, much better brain.

Same 89 MB file: 88.8% accuracy with naive rounding versus 97.0% with quantization-aware training.
QAT is not free. It makes training slower and more complex, and you need training infrastructure that supports fake-quantization ops. So when should you bother?
Use QAT when:
PTQ is probably fine when:
For small models at 4 bits — exactly the browser/edge scenario — QAT earns its keep. Small models have less redundancy to spare, so every point of accuracy matters.
Small, private, offline-capable models are becoming a real product category: support bots that never leak customer data, assistants on factory floors with no connectivity, tools for regions where bandwidth is expensive. Quantization-aware training is one of the key techniques that makes that category viable. It turns "the model is too big" from a dead end into an engineering problem with a known solution.
PocketBot is open source, and the approach generalizes: fine-tune small, quantize with awareness, ship where the users are. The browser, it turns out, is a perfectly good inference server — if you respect its limits.
Muhammad Faizan is an AI engineer and full-stack developer based in Saudi Arabia. He builds ML systems and developer tools including PocketBot and Gale Download Manager. More at faizzyhon.com.
Originally published at faizzyhon.com.