{"slug": "quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule", "title": "Quantize a Small LLM to INT8: I Shrank Two Models by Half or More, and a 98% Rule Said No to Both", "summary": "A developer quantized two small decision models to INT8 as the final lesson of the free e=mc² build-an-LLM course, and both failed the project's 98% precision gate on unseen questions. The from-scratch 0.84M-parameter decider shrank from 3.37 MB to 1.10 MB and kept 99.0% agreement on a 300-question check, but its median decision time rose from 0.68 ms to 1.30 ms because its 128-wide matrices are too small for integer arithmetic to pay off. Applying the same one-line dynamic quantization to Qwen2.5-0.5B with a merged adapter preserved only 44.7% of decisions, which improved to 94.29% after per-channel scales and keeping seven outlier layers in fp32, at a cost of 1,976 MB to 1,000 MB and roughly flat latency.", "body_md": "*Part 10 of ten. Each post is a short, plain-words tour of one lesson from [e=mc²](https://theaivibe.org/emc2), a free build-an-LLM-from-scratch course; the full lesson, notebook and numbers are on the site.*\n\n**Shrinking a model is the easy part. Proving it has earned its place is the work.** For the last lesson of e=mc² I took the two small decision models from Lesson 9, wrote their weights with fewer digits, measured how much smaller and faster they got, and then handed them to a judge that does not care how clever the trick was. The judge said no to both. The idea inside it is one you can hold in your hand.\n\nA model is millions of dials, and every dial is a number. Normally each one is stored as a float with about seven digits of precision, four bytes each; the engineers call that **fp32**. **int8 quantization** rounds each dial to a one-byte whole number times a single scale. Fewer digits, a quarter of the bytes, and the hope that whole-number arithmetic is also faster.\n\nIn the lesson's story, **Momo** the monkey (he is the model) has learned to dispatch, fill in forms, and has studied the teacher's decisions. Before he gets his own desk, **Ella** the elephant lays down the house rule: act alone only if, on questions you have never seen, you are right 98 times in 100. And travel light. His notes go into a smaller backpack, written with fewer digits.\n\nThe desk has a name in the software this lesson plugs into. pankhllm, a small open-source router that decides which operation a plain-English request wants, calls a decision engine it trusts first a **lane**. A lane earns its place only if it holds 98% precision on unseen questions and decides more of them than the 262 KB regression pankhllm already ships. That is the contract. Everything below is measured against it.\n\nThe from-scratch decider has 0.84 million parameters. The one-line PyTorch quantizer, applied to every linear layer, worked beautifully on paper: its decisions were unchanged on 99.0% of a 300-question check, and on 99.59% of all 2,172 test questions. The file went from 3.37 MB to 1.10 MB.\n\nAnd it got slower. A decision took 1.30 milliseconds at the median against 0.68 before. The reason is size, in the other direction: its matrices are only 128 wide, so the cost of converting activations to whole numbers and back is bigger than what the integer multiply saves. int8 pays off on large matrices where fetching the weights, not the arithmetic, is the slow part. On a tiny model the backpack is lighter and the walk is longer.\n\nThen the same one-liner on Qwen2.5-0.5B with Lesson 9's adapter merged in. It kept only **44.7%** of its decisions. Not slightly worse; broken.\n\nThe glossary word for why is **outlier**, and the Momo version is \"one shout that drowns every whisper\". Dynamic quantization gives each activation tensor one shared scale. Measuring every linear layer's input on 200 calibration questions found a few feed-forward inputs near 1,700, while everything around them was small. Round all of that to one byte on one scale and the whispers become zero. The LLM.int8() paper from 2022 describes exactly this.\n\nTwo more tries. Per-channel scales (one per output row instead of one per matrix) with the output head left in fp32 got 48.7%. Keeping the seven outlier layers in fp32 brought agreement to 92.0% on the check and 94.29% across all test questions. The lesson says plainly that attempts two and three were chosen after seeing attempt one.\n\nSize fell from 1,976 MB to 1,000 MB, half rather than a quarter, because Qwen's 545 MB embedding table stays fp32. Speed was about the same, 42.4 milliseconds before and 40.5 after. The whole quantization-and-serve recipe is a few lines:\n\n``` python\nfrom torch.ao.quantization import quantize_dynamic, per_channel_dynamic_qconfig\nattempt1 = quantize_dynamic(model, {nn.Linear}, dtype=torch.qint8) # the one-liner\nkeep = {\"lm_head\", *outlier_layers} # inputs above 100 on calibration questions\nspec = {n: per_channel_dynamic_qconfig for n, m in model.named_modules()\n if isinstance(m, nn.Linear) and n not in keep}\nattempt3 = quantize_dynamic(model, spec, dtype=torch.qint8)\n\n# what pankhllm sends the lane, and what the stdlib server answers\n{\"state\": \"who covers T-412?\", \"questions\": {\"operation\": {\"type\": \"choice\",\n \"criteria\": {\"coverage_owner\": \"...\", \"prescriber_list\": \"...\", \"UNSUPPORTED\": \"...\"}}}}\n{\"answers\": {\"operation\": {\"choice\": \"coverage_owner\", \"answer_confidence\": 0.999851}}}\n```\n\nInstead of grading the models myself, I served them the way pankhllm talks to outside engines: one POST to /v1/systemone, carrying the question and a choice among the operations it structurally fits, with UNSUPPORTED last. The server is plain Python standard library, nothing installed, and a round trip took 1.62 milliseconds. It also applies pankhllm's known-words gate: if fewer than 70% of a question's words were seen in training, the lane stays quiet and pankhllm falls back to its planner.\n\nAsk it \"who covers T-412?\" and the lane answers:\n\n{\"answers\": {\"operation\": {\"choice\": \"coverage_owner\", \"answer_confidence\": 0.999851}}}\n\nThen pankhllm's own 0.1.1 binary ran its offline scorer, decide-eval, against the lanes. First a sanity check: trained on 20,000 templates alone, pankhllm's regression decided 52.45% of held-out templates at 100% precision, 1,049 right and none wrong. The published figure is 52.5%. Reproduced, on my CPU, before judging anything of mine.\n\nOn Lesson 9's teacher-written questions, with the gate on:\n\nOne run, 11 October 2026, on an Apple Silicon Mac CPU. The whole notebook took 181.5 seconds. It was not timed on Colab.\n\nTwo things I will carry from this. First, quantization is easy to do and easy to get wrong: check agreement with fp32 before you look at megabytes, and expect no speed-up on a model this small. Second, every decider in the lesson holds 98% on held-out templates, and none holds it on questions a different author wrote, pankhllm's regression included. The number format was never the problem. Precision on other people's phrasings was.\n\nSo the lane config the lesson ships starts in **shadow mode**: Momo answers on paper beside the planner, and nobody acts on his answers until real traffic brings real labels. That is what a 98% rule looks like when you actually apply it, and I would rather end the series on a true \"not yet\" than a flattering \"done\".\n\nThe full lesson has the three-attempt quantization table, the complete decide-eval table with the published rows beside the measured ones, the glossary in Momo's words, and the notebook that does all of it on any CPU.\n\nThis post is the postcard. The lesson is the trip. **Lesson 10 of e=mc²** on theaivibe.org walks you through every piece with widgets you can poke, a notebook that runs on a free GPU in minutes, and the honest numbers at every step. No account, no paywall, nothing to install.\n\nThat is the whole journey. If you did all ten, you now hold a language model you trained from random dials, read the mind of, fine-tuned, taught to take instructions, LoRA'd with 2% of its weights, turned into a decision model, made to fill a form, distilled from real phrasings, and finally quantized and judged. The hub lists all ten in order, so if you joined late, start at lesson one.", "url": "https://wpnews.pro/news/quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule", "canonical_source": "https://dev.to/aiexplore369zoho/quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule-said-no-to-both-509b", "published_at": "2026-11-24 12:30:02+00:00", "updated_at": "2026-11-24 12:43:16.831571+00:00", "lang": "en", "topics": ["machine-learning", "large-language-models", "ai-tools", "ai-infrastructure"], "entities": ["pankhllm", "Qwen2.5-0.5B", "PyTorch", "LLM.int8()", "e=mc²"], "also_reported_by": [], "takeaway": "Dynamic INT8 quantization kept 99% agreement on a 0.84M-parameter model but made it slower (1.30 ms vs 0.68 ms median) because 128-wide matrices can't amortize activation conversion, while on Qwen2.5-0.5B it preserved only 44.7% of decisions until per-channel scales and fp32 outlier layers raised ag", "recommendation": {"advice": "Before shipping INT8 dynamic quantization, measure agreement on unseen questions and latency yourself: keep outlier layers and the output head in fp32 and use per-channel scales, since a one-line quantizer cut a 0.5B model to 44.7% agreement and slowed a tiny model down.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule", "markdown": "https://wpnews.pro/news/quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule.md", "text": "https://wpnews.pro/news/quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule.txt", "jsonld": "https://wpnews.pro/news/quantize-a-small-llm-to-int8-i-shrank-two-models-by-half-or-more-and-a-98-rule.jsonld"}}