# Mission 9.2: Q4 or Q8?

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/einsatz-9-2

Belongs to [Chapter 9: Number formats and quantization](https://llm.yoga/en/09-quantisierung.md).

Structure: the case, the explanation, a hands-on tool, check questions, wrap-up. The answers to all questions are collected at the end.

## The case

**Aylin**, Development:

> “Our code assistant runs locally with qwen3:1.7b, Ollama’s default, so Q4_K_M. Sometimes it produces junk. The model also comes in Q8_0. Is that worth it, or is it just twice the size for nothing?”

When a local model makes mistakes in everyday use, people ask you whether a bigger version would help and what it costs. qwen3:1.7b is a small, openly available model; Ollama is the program that runs it on the computer. Q4_K_M and Q8_0 are two levels of **quantization**: the billions of weights, the model’s learned numbers, are stored with about 4 or 8 bits instead of 16. So quantizing means rounding, like saying “twenty past ten” instead of giving the time to the millisecond. First, a prediction about the rounding itself.

**Question 1 (prediction):** A block of eight weights (0.12 · −0.45 · 0.33 · 0.08 · −0.91 · 0.27 · −0.05 · 0.60) is rounded to 4 bits. Now −0.91 turns into a single outlier of −3.0. What happens to the small weights 0.12, 0.08 and −0.05?

- A) Almost nothing; the outlier only affects itself.
- B) They grow along with it, because the block is rescaled.
- C) All three are rounded to zero.

## What’s behind it

In the method shown here, the weights are split into small blocks, for example 32 numbers each. Each block gets a scale factor, usually chosen so that the number with the largest magnitude just fits on the outermost step. Then each number is rounded to the nearest step. With 4 bits there are 16 steps, with 8 bits 256. The more steps, the finer the grid and the smaller the rounding error.

Outliers can substantially reduce accuracy: a single large value makes the steps coarse for the whole block. Real models have outliers like this, which is why newer methods work with smaller blocks, scales for the scales, and more precise storage of sensitive parts. Q4_K_M is one of these methods. This extra information takes up space itself: Q4_K_M needs 4.89 bits per weight on average, not 4.

Perplexity measures how surprised a model is by a text; lower is better. For the model tested there, llama.cpp reports an increase of 0.0026 at Q8_0, 0.18 at Q4_K_M and 3.5 at Q2_K. Those figures do not guarantee the quality of every model. Ollama uses Q4_K_M as the default for many models.

More precise weights generally mean more data to read per token. If memory bandwidth limits generation, the larger file can reduce tokens per second. The actual ratio has to be measured.

Aylin needs to compare code quality on actual tasks. Even for a model with fewer than 8 billion weights, size alone does not establish the benefit of higher precision. A single wrong token can introduce a programming error.

### In more detail: the math for the block

Signed 4 bits allow −8 to 7, used symmetrically −7 to 7. Largest magnitude 0.91, scale d = 0.91 ÷ 7 = 0.13. Divide each number by 0.13 and round: 1, −3, 3, 1, −7, 2, 0, 5. Converted back: 0.13 · −0.39 · 0.39 · 0.13 · −0.91 · 0.26 · 0.00 · 0.65. Largest error 0.06, mean absolute error 0.036.

Space: 8 × 4 bits plus a 16-bit scale = 48 bits, 6 bits per weight. With blocks of 32 numbers it would be (32 × 4 + 16) ÷ 32 = 4.5 bits; that is also the storage cost of Q4_0. Its specific rounding differs from this example.

## Try it

**Rounding with an outlier**

**Task:** Drag the red outlier to the left until three small weights fall to zero. Then switch to 8 bits and see what happens to the error.

Without JavaScript, the two cases from chapter 9: with −0.91 the scale is 0.13, only −0.05 becomes zero, mean error 0.036. With −3.0 the scale is 0.43, 0.12, 0.08 and −0.05 become zero, 0.60 becomes 0.43, mean error 0.088.

## Decide

**Question 2 (decision):** What do you advise Aylin for her code assistant with qwen3:1.7b?

- A) Test Q8_0; if space is short, Q6_K or Q5_K_M.
- B) Stay with Q4_K_M; Q8_0 does nothing for code.
- C) Switch to Q2_K; it’s smaller and faster.

**Question 3 (check question):** For qwen3:1.7b, Q8_0 is 2.2 GB instead of 1.4 GB. How does the theoretical ceiling change under the simplified bandwidth estimate?

- A) It halves, because it’s twice as many bits.
- B) It falls to roughly two thirds of the initial rate.
- C) It stays the same; only the memory needs grow.

**Question 4 (check question):** In the full version with 16 bits per weight (FP16), Llama 3.1 8B is 16 GB. How big is the file in Q4_K_M?

- A) About 4.9 GB, a bit more than a quarter.
- B) Exactly 4 GB, because 4 of 16 bits is a quarter.
- C) About 8 GB, because the scales double the requirement.

## Done

**What you can do now**

- You can explain quantization as rounding to steps with one scale per block, and you’ve seen how a single outlier pushes small weights to zero.
- You can compare the levels: Q8_0 usually has low loss, Q4_K_M is common, and lower precision needs careful quality checks. Higher precision usually requires more memory.
- When a small local model makes coding errors, compare several tasks with Q8_0 to investigate the effect of quantization.

### Two cards for review

**Card 1:** True or false? “When rounding, a single outlier in a block only affects itself.”

**Card 2:** A small local model in Q4_K_M makes mistakes when programming. What do you try, and what does it cost?

- [Next mission: Which model for the team laptop with 16 GB?](https://llm.yoga/en/einsatz-9-3.md)
- [Try it on your Mac](https://llm.yoga/en/mac-9-2.md)

## Read more in the chapter

The full text from the chapter, with the reasoning, calculations and sources:

- [What quantization is](https://llm.yoga/en/09-quantisierung-1.md)
- [The quantization levels in the GGUF format](https://llm.yoga/en/09-quantisierung-2.md)
- [Which level pays off when](https://llm.yoga/en/09-quantisierung-3.md)

## Answers: only reveal them after the learner has answered or explicitly asks

**Question 1:** The correct answer is C.
- A: In this method, a block’s steps depend on its largest magnitude. With the outlier, all steps become just over three times as wide, and the small weights fall to zero.
- B: The steps get wider, but each weight is rounded to the nearest step. With steps 0.43 wide, that’s zero for all three.
- C, correct: The steps become 3.0 ÷ 7 = 0.43 wide instead of 0.13. 0.12, 0.08 and −0.05 are then all closer to zero than to the first step. The mean absolute error rises from 0.036 to 0.088.

**Question 2:** The correct answer is A.
- A, correct: Chapter 9 recommends this comparison. Q8_0 usually has low quantization loss and can help investigate its contribution to code errors. The file grows from 1.4 to 2.2 GB. More bytes can reduce speed, and sufficient memory must be available.
- B: The claim that higher precision never helps with code is unsupported. Compare both versions on the same tasks; the more precise version can still make mistakes.
- C: In the llama.cpp speed test, Q2_K is only eleven percent faster than Q4_K_M for Llama 3.1 8B. A separate quality test shows substantial loss: perplexity rises by 3.5 instead of 0.18.

**Question 3:** The correct answer is B.
- A: What counts is the whole file, and it doesn’t double: 1.4 to 2.2 GB is about two thirds, not half.
- B, correct: File size approximates the data read per token. The estimated ceiling is bandwidth divided by file size: on the MacBook Air M4 with 120 GB/s, about 86 tokens per second at 1.4 GB and about 55 at 2.2 GB.
- C: This calculation assumes weight reads are the bottleneck. At the same bandwidth, more bytes per token lower the ceiling.

**Question 4:** The correct answer is A.
- A, correct: Scales and parts stored more precisely cost extra, 4.89 bits per weight on average. The file in Ollama’s library is 4.9 GB, 31 percent of the FP16 size.
- B: Calculated with pure bit counts, it would be 25 percent. But scales and parts stored more precisely cost extra: the real file is 4.9 GB, 31 percent.
- C: The scales don’t cost that much. 8 GB would be roughly Q8_0 at 8.5 GB. The Q4_K_M file is 4.9 GB, 31 percent of the FP16 size.

**Card 1:** **False.** A block’s steps depend on its largest magnitude. If −0.91 turns into an outlier of −3.0, they are 0.43 wide instead of 0.13, and small weights like 0.12, 0.08 and −0.05 fall to zero. The mean error rises from 0.036 to 0.088.

**Card 2:** Compare several tasks with Q8_0, or Q6_K or Q5_K_M if memory is limited. Q8_0 can reduce quantization errors but does not guarantee correct answers. It needs more memory and can be slower when bandwidth limits generation. File size provides only a rough performance estimate.
