Understanding Quantization Without Pretending I’m a Mathematician

If you download local AI models for long enough, you start seeing filenames that look like somebody mixed a model name with a firmware revision number.

Qwen2.5-Coder-7B-Instruct-Q4_K_M.gguf

The first few parts are usually readable enough. Qwen2.5-Coder is the model family. 7B tells you the rough parameter count. Instruct means it was tuned to follow instructions instead of just continuing text like a very expensive autocomplete machine (which, I mean… they kind of all are anyway).

Then you hit Q4_K_M, and the whole thing starts looking like a part number for a dishwasher pump.

That section isn’t just decorative. It tells you something important about how the model was compressed, how much memory it probably needs, and what kind of quality tradeoff you are accepting before you even launch it.

That is quantization.

I’m not going to explain quantization by immediately diving into matrix math, floating-point formats, tensor blocks, and calibration. I am not against the math. The math matters. But most people trying to run a model locally do not need to start there. You need the practical version.

Bottom line: quantization means the model’s been compressed to lower precision so it uses less memory.

Still here? Want more info? Cool, let’s keep talking about it.

The Basic Problem

A language model is mostly a huge collection of numbers.

Those numbers are called weights. During inference (i.e. chatting with the model), the model uses them to process your prompt and predict what token should come next. It’s a very sophisticated version of the social media game where you write “My favorite thing about science is…” and then you press the middle auto-complete suggestion button thirty times and see what it says.

The model doesn’t read your question the way a person reads a question. It converts everything you typed and everything it responds with into tokens that it moves through layers of math using a giant pile of learned numeric relationships.

In other words: it’s just a giant fancy autocomplete.

The important part for local hardware is simple: all of those numbers have to be stored somewhere.

More parameters means more numbers need storing. More precise numbers need more memory. This is why model size and precision matter so much when you are trying to run something on a consumer GPU instead of a datacenter card that costs more than a used car.

A 7 billion parameter model stored in FP16 uses roughly 2 bytes per parameter. Back-of-the-napkin math puts that around 14GB for the weights alone. So your 16GB graphics card should be able to run it no problem, right? Well…

That 14GB requirement is before the context window. And runtime buffers. And GPU overhead. And Windows, Docker, Chrome, VS Code, Discord, and whatever other software is standing around the VRAM buffet with a plate in its hand.

So when I was trying to run models on an RTX 2060 with 6GB of VRAM, full precision was not a serious option for a lot of these models. The math just didn’t care how optimistic I felt. Quantization is the only reason that GPU could run useful models in this class.

What Quantization Actually Means

Quantization means representing the model’s weights with less precision so they take up less memory.

The Easy to Understand Version

Instead of storing a weight with the full 16-bit precision it might have been trained with (models are not universally trained in FP16; BF16, FP32, mixed precision, and other training/storage paths exist), you store it with fewer bits. Maybe 8. Or 6. Or 4.

As a rough example, you can think of it like this:

  • 16 bit: 1.051324765231459
  • 8 bit: 1.0513248
  • 6 bit: 1.05132
  • 5 bit: 1.0513
  • 4 bit: 1.051
  • 3 bit: 1.05
  • 2 bit: 1.0

The above example is a “bad-but-useful” one. This isn’t exactly how it works in computer reality, but it’s a good way to wrap our feeble human brains around the concept.

The Slightly More Accurate Version

For the purists out there, what’s really happening is we are taking a quantization range and the number of bits is really giving us a range of “buckets” that we can put that number into. For example, 16 bit means 2^16, which is 65,536 of these buckets. As an example, let’s say we’re trying to represent a number in a known range: between 0 and 2. We have an original value of 0.98765432.

  • 16 bit gives 65,536 possible buckets → 0.987655
  • 8 bit gives 256 possible buckets → 0.988235
  • 6 bit gives 64 possible buckets → 0.984127
  • 5 bit gives 32 possible buckets → 0.967742
  • 4 bit gives 16 possible buckets → 0.933333
  • 3 bit gives 8 possible buckets → 0.857143
  • 2 bit gives 4 possible buckets → 0.666667

So in reality, it’s not actually chopping decimals off the end of the number. It’s forcing the number into a smaller representation that can be saved in RAM.

So why not just quantize away and make the models all smaller? Well, the lower you go, the less memory each weight needs, but the more you risk damaging the model’s behavior.

An Example of Why This is Important

Let’s use a navigation example. You’re in an airplane flying around the world and trying to reach a destination 3000 miles away. You calculate your course with extreme precision: Fly heading 121.1471413547794. That’s your full precision heading. But, I mean… that’s a LOT of decimals to remember, right?

Let’s say instead of that you round it off a little to 121.14714. You fly that heading and maybe you end up within 20 feet of where you were trying to go. Hey, that’s not bad. That’s perfectly fine!

So let’s round it a little more. Now you’re flying 121.147. Well, now you ended up about 300 yards away from where you were trying to go, but that’s alright. You can still correct that. Let’s try rounding it down to 121 now.

Well… now you ended up in a different city altogether. In another country.

So we have learned that at a certain point, the quantization starts affecting the behavior enough that it stops being useful.

How This Applies to Large Language Models

A quantized 7B model will still have roughly 7 billion parameters. Quantization does not (usually) mean you removed half the model. It means each weight got cheaper to store.

That distinction matters because people sometimes talk about quantized models as if they are simply “smaller models.” They are compressed versions of larger models, not necessarily smaller architectures. A quantized 7B model is not the same thing as a 3B model. It still has the structure and parameter count of the 7B model, but its weights have been stored in a lower-precision format.

Quantization saves memory by accepting approximation.

The trick is finding out how much approximation the model can tolerate before the output gets worse in ways you actually care about.

Why This Helps So Much

The reason quantization matters is not subtle: memory pressure drops fast when you stop storing every weight in high precision.

A 7B model in FP16 can be far too large for a 6GB GPU. A 4-bit quantized version of that same general model may become realistic enough to run locally, especially with tools like llama.cpp and GGUF files designed for this kind of inference.

That does not mean the whole workload suddenly fits neatly and behaves perfectly. It means the weights themselves became much cheaper to store. That is enough to turn some models from “absolutely not” into “maybe, depending on context length and how much patience you brought with you.”

This is why Q4 models show up constantly in local AI setups. They often land in a useful middle ground. They are much smaller than FP16, they usually preserve enough of the model’s behavior to be useful, and they give ordinary GPUs a chance to participate.

Not always a good chance. But a chance.

On my RTX 2060, that mattered. I was not trying to win benchmark charts. I was trying to get useful local inference working on hardware that very clearly had opinions about the workload.

Reading Q4_K_M

Take this filename again:

Qwen2.5-Coder-7B-Instruct-Q4_K_M.gguf

The part we care about here is Q4_K_M.

Q4 tells you this is roughly a 4-bit quantized model. I say “roughly” because real quantization formats can get more complicated than “every number is stored in exactly four simple bits.” Different tensors may be treated differently, and modern quantization schemes use additional metadata to preserve more useful information than a naive conversion would.

For practical purposes, though, Q4 means the model has been compressed pretty aggressively.

The K refers to a family of quantization methods used in the llama.cpp / GGUF ecosystem. The M means medium. You may also see variants like S for small. The details matter if you are comparing quants closely, but at the beginner level the important point is that Q4_K_M usually represents a practical compromise: small enough to run on constrained hardware, but not usually as degraded as the more extreme low-bit options.

The .gguf extension is the file format. GGUF is commonly used with llama.cpp and related tools for running models locally.

So the practical translation of that filename is something like this:

This is a 7B instruction-tuned coding model, packaged for local inference, using a 4-bit-ish quantization scheme that tries to balance memory savings against output quality.

Quantization Is Not Free

The first mistake is thinking quantization ruins everything.

The second mistake is thinking it costs nothing.

Neither is true.

A well-quantized model can work extremely well. In casual chat, summarization, basic coding assistance, and experimentation, you may not notice much quality loss at all. Some quantized models feel much better than you would expect given how much smaller they are.

But compression still changes the model. Lower precision means the model has less detail available in its weights. Sometimes that does not matter. Sometimes it shows up as a slightly flatter writing style, weaker instruction following, sloppier code, worse reasoning, or more brittle behavior when a prompt gets complicated.

Coding is where I noticed this most. A chat model can get away with being a little vague. A coding model has fewer places to hide. If it invents a function, imports a package that does not exist, or confidently gives me the wrong method name, the problem becomes obvious very quickly.

That does not mean quantization caused every bad answer. Models make mistakes at full precision too. But lower precision can make some weaknesses easier to trigger, especially when the model is already being pushed by limited memory, long context, or awkward prompts.

This is why you cannot judge a quant only by whether it launches. A model can load successfully and still be the wrong quant for the job.

Q4 Is a Compromise, Not a Personality Trait

Q4 gets used a lot because it is practical. It often gives you enough memory savings to run models that would otherwise be out of reach while keeping enough quality to make the model useful.

That does not make Q4 the correct answer to every question.

Lower quants can save more memory, but they tend to carry more risk. A Q2 or Q3 model might be useful in some situations, especially if you are extremely constrained, but you should expect more degradation. Higher quants like Q5, Q6, or Q8 usually preserve more quality, but they demand more memory.

The right choice depends on the workload.

If I am testing a model casually, Q4 may be perfectly fine. If I am using the model for coding help and I care about reliability, I may want Q5 or Q6 if the hardware can handle it. If I am trying to squeeze something onto a tiny GPU just to see whether it works, I may accept a lower quant and lower my expectations accordingly.

The best quant is not the highest one you can technically load. It is the one that gives you the best practical balance of quality, speed, memory use, and stability for the thing you are actually doing.

A model that produces slightly better answers but runs so slowly that I stop using it is not better in any meaningful workflow sense.

Quantization Does Not Fix the Whole Workload

Quantization reduces the memory needed to store the model weights. That is a huge deal, but weights are not the entire workload.

When you run a model, the machine also needs memory for the context and other runtime data. In llama.cpp discussions, you will often see people talk about the KV cache. You do not need to understand every detail of that term to understand the practical consequence: longer context windows require more memory while the model is running.

For simplicity, think of the context window as the LLM’s short term memory. Once you exceed the window, it has to drop those tokens and it can’t remember them anymore unless you intentionally put them back in (which will cause other tokens to fall out of context).

The implication is that a quantized model can fit into your GPU at 4096 tokens and become painful or impossible at 32768 tokens.

The model didn’t change. The workload changed.

This is what makes “it fits” such a slippery phrase in local AI. Fits with what context length? Fits with how many layers on the GPU? Fits with what batch settings? Fits while the computer is also doing normal computer things? Fits at a speed that will not make me wander away and reorganize the garage while waiting for an answer?

Quantization helps with one major part of the memory problem. It does not repeal the laws of the rest of the system.

As an example of why this matters, I found that 4096 tokens was a perfectly acceptable context size for just casual chatting with a simple model. I found that the same context size on a reasoning model would use almost all of it thinking through its response to the point that I would only be able to get one or two prompts to it before it forgot what we were doing. It was like talking to Dory from Finding Nemo.

Then, on a coder model, the 4096 context was almost worthless for me. It was enough to get the model to make a scaffold function, but anything more serious than that and it crashed and burned.

Higher Precision Is Not Always Better in Practice

It is tempting to treat quantization like a simple quality ladder.

Q8 must be better than Q6. Q6 must be better than Q5. Q5 must be better than Q4. Q4 must be better than whatever cursed artifact lives below that.

In one narrow sense, that is usually the right direction. Higher precision generally preserves more of the original model. If memory and speed were free, you would usually prefer less compression.

Memory and speed are not free.

If a higher-precision quant forces part of the workload out of VRAM and into system RAM, the model may become miserable to use. If a Q5 model stays mostly on the GPU and runs smoothly while Q8 crawls, Q5 may be the better local setup even if Q8 is more faithful to the original weights.

This is the part that makes local AI feel like systems work instead of shopping.

You are not choosing the “best” file in a vacuum. You are choosing the file that behaves best on your actual hardware, with your actual context length, for your actual task, under the conditions you are actually willing to tolerate.

That is less glamorous than downloading the largest file in the list.

It also works better.

What I Look For Now

When I look at a model file now, I pay attention to three things before anything else: the model size, the quantization, and the context I expect to use.

The model size tells me the rough class of machine I am dealing with. A 3B model, a 7B model, and a 20B model are not asking the same thing from the hardware.

The quantization tells me how aggressively the weights have been compressed. Q4 means the file has been pushed down hard enough to become practical on smaller machines. Q5 and Q6 may preserve more quality if I can afford the memory. Q8 is heavier still. FP16 is where small GPUs start pretending they did not hear the question.

The context length tells me how much working room the model needs once it starts running. This is the part that can turn a model from usable to painful even when the quantized file itself looks reasonable.

So the question changes. Instead of asking, “What is the biggest model I can run?” I ask, “What is the smallest and fastest version of this model that still does the job well enough?”

That sounds boring. It is also the difference between a local AI setup that you actually use and one that exists mostly as a screenshot.

Current Thoughts

Quantization is not a magic trick. It is a memory tradeoff.

You store the model’s weights with less precision so the machine can fit and run something that would otherwise be out of reach. In exchange, you accept some amount of approximation, and that approximation may or may not matter depending on the model, the task, and how aggressive the quantization is.

That is the gist of it.

Once you understand that, filenames like Q4_K_M stop looking like nonsense and start looking like hardware notes.

Still ugly hardware notes.

But readable ones.

Rights notice: Editorial content and published media for this entry are © 2026 Pacific Wharf. All rights reserved. Site code and layout are licensed separately under MIT.

Back to tech blog