Quantization-Aware Training, Explained With a Real 89 MB Browser Model
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 worri
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.
The problem: big models, small tabs
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.
Why naive 4-bit rounding hurts
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.
What quantization-aware training does differently
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.
The PocketBot numbers
Here is what this meant in the actual build:
- Base model: SmolLM2-135M, fine-tuned on FAQ-style data.
- Plain 4-bit rounding (PTQ): next-token accuracy fell to 88.8%.
- With quantization-aware training: accuracy recovered to 97.0% at the same 4-bit size.
- Final size: ~89 MB, running in the browser via ONNX Runtime.
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.
When QAT is worth it — and when it is not
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:
- The model must run on constrained hardware (browsers, phones, edge devices).
- Accuracy at low precision is a product requirement, not a nice-to-have.
- You control the training pipeline end to end.
PTQ is probably fine when:
- You are quantizing to 8 bits (losses are usually small).
- The model is large enough that redundancy absorbs rounding error.
- You need a quick deployment and can tolerate a small quality drop.
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.
Practical tips from the build
- Fine-tune first, then QAT. Get the model good at your task in full precision, then run a QAT phase so it adapts to rounding without relearning the task from scratch.
- Measure the right thing. I tracked next-token accuracy on held-out FAQ data, not just perplexity. Task metrics tell you what users will feel.
- Export and test in the real runtime. Accuracy in PyTorch is a promise; accuracy in ONNX Runtime in an actual browser tab is the truth. Test where users live.
- Watch memory, not just file size. The downloaded model is ~89 MB, but runtime memory during inference is what crashes tabs. Budget for both.
Why this matters beyond one chatbot
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.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.