GGUF Quantization Names: Four Decisions Inside Q4_K_M
The uppercase string at the end of a model filename is the most misread thing on the download page. Q4_K_M looks like "four bits, K version, medium size." It is actually four unrelated decisions, and one of those names does not exist in the tensor type table at all.
I treated this as evidence collection: no weights downloaded, just a few hundred-byte GGUF files written with gguf-py 0.19.0 and read back, then the two official tables placed side by side. The same name measures two different bits-per-weight values, with the widest gap at 25 percent; the two enums share 30 numeric values and 24 of them mean different things.
One name, two enums, three tables
Three things are colliding here.
The first is the tensor type table, GGMLQuantizationType. It describes how a block of binary data gets decompressed: 34 values covering F32, Q4_0, Q4_K, IQ4_XS, MXFP4 and the rest.
The second is the file type table, LlamaFileType, the value written into the general.file_type metadata key. It has 35 names (the 36th is GUESSED = 1024, which is not a real type), covering entries like MOSTLY_Q4_K_M and MOSTLY_Q3_K_L.
The third is the size table: how many gigabytes the thing actually occupies.
The three tables look alike. Their numbering does not.
The spec gives three sentences, and they explain every later mistake
The GGUF specification defines general.file_type as: *An enumerated value describing the type of the majority of the tensors in the file. Optional; can be inferred from the tensor types.*
Three consequences:
- majority means most tensors, not all of them
- Optional means it may be absent
- can be inferred from the tensor types means it is derivable, not authoritative
Put together: general.file_type is a label, not an instruction. Almost everyone reading a filename treats it as an instruction.
I wrote four files to check this
Environment: Windows 11 (10.0.26300), CPython 3.13.14, gguf-py 0.19.0, numpy 2.3.1. No model file was downloaded.
The method was simple: write a file with GGUFWriter, deliberately make the label and the tensor types disagree, read it back with GGUFReader, and see whether anything complains.
Trap 1: a wrong label reads back clean
The first file declares MOSTLY_Q4_K_M while its only tensor is stored as float32:
w.add_file_type(LlamaFileType.MOSTLY_Q4_K_M)
w.add_tensor("w", np.arange(8, dtype=np.float32).reshape(2, 4))
Reading it back gives general.file_type of 15 -> MOSTLY_Q4_K_M, a tensor tensor_type of F32, and a 224-byte file. No warning, no exception.
The second file goes the other way: it declares ALL_F32 while the tensor is packed Q4_K data (144 bytes):
w.add_file_type(LlamaFileType.ALL_F32)
w.add_tensor("q", np.zeros(144, dtype=np.uint8), raw_dtype=GGMLQuantizationType.Q4_K)
It reads back as file_type = 0 -> ALL_F32, tensor_type = Q4_K, shape = [256], n_bytes = 144, 320 bytes on disk. Also silent.
So "this file says it is Q4_K_M" does not imply "the tensors are 4-bit." The only way to know is to walk every tensor and read tensor_type.
One more wrinkle: if you omit general.file_type, get_field returns None, not 0. Writing GUESSED (1024) also stores and reads fine, and 1024 is not among the 35 real values — its meaning is precisely "the model file did not say."
Trap 2: 30 shared numbers, 24 different meanings
Lay the two enums out by value and they overlap on 30 numbers, because they started as one table and then diverged. Of those 30, 24 point at completely different things.
The sharpest pair is 15:
| Value | Tensor type | File type |
|---|---|---|
| 12 | Q4_K | MOSTLY_Q3_K_M |
| 13 | Q5_K | MOSTLY_Q3_K_L |
| 14 | Q6_K | MOSTLY_Q4_K_S |
| 15 | Q8_K | MOSTLY_Q4_K_M |
| 18 | IQ3_XXS | MOSTLY_Q6_K |
| 40 | NVFP4 | MOSTLY_Q1_0 |
If a log line says file_type = 15 and you translate it with GGMLQuantizationType(15), you get Q8_K, a 9.125 bpw type, when you meant the 4.8944 bpw Q4_K_M. That is not a typo. That is reading the wrong table.
GGMLQuantizationType(15) and LlamaFileType(15) are both valid, both silent, and they disagree.
The file type table also has six gaps: 4, 5, 6, 33, 34, 35. The first three are MOSTLY_Q4_1_SOME_F16 and the removed Q4_2 and Q4_3; the last three are Q4_0 runtime repack formats (the official comment reads "removed from gguf files, use Q4_0 and runtime repack"). Numbers are not contiguous here.
Trap 3: 13 names exist only at the file level
Worse: some names have no tensor type counterpart at all. I took the set difference.
- Names only in the file type table (13):
Q4_K_S,Q4_K_M,Q5_K_S,Q5_K_M,Q3_K_S,Q3_K_M,Q3_K_L,Q2_K_S,IQ3_XS,IQ3_M,IQ2_M,MXFP4_MOE,ALL_F32 - Names only in the tensor type table (12):
F32,F64,I8,I16,I32,I64,Q3_K,Q4_K,Q5_K,Q8_K,Q8_1,MXFP4
Note that Q4_K exists as a tensor type while Q4_K_M exists only as a file type, and Q8_K exists as a tensor type with no MOSTLY_Q8_K file type at all.
That is what S/M/L really are: not finer formats, but recipe names for "use this format at different tiers on different tensors." The official documentation says it plainly under --pure: *disable k-quant mixtures and quantizes all tensors to the same type*. K-quants are mixed by default; --pure turns the mixing off.
So a single Q4_K_M file may contain tensors at Q4_K, Q5_K and Q6_K, and which layers get bumped is an internal policy of the llama.cpp quantizer.
Trap 4: the number in the name is not a bit width
GGML_QUANT_SIZES is the only block arithmetic table in the package: how many elements per block, how many bytes per block. Multiply bytes by 8 and divide by elements to get pure tensor bpw:
| Type | Block elements | Block bytes | bpw |
|---|---|---|---|
| Q4_0 | 32 | 18 | 4.5 |
| Q4_K | 256 | 144 | 4.5 |
| Q5_0 | 32 | 22 | 5.5 |
| Q5_K | 256 | 176 | 5.5 |
| Q6_K | 256 | 210 | 6.5625 |
| Q8_0 | 32 | 34 | 8.5 |
| Q8_K | 256 | 292 | 9.125 |
| Q2_K | 256 | 84 | 2.625 |
| Q3_K | 256 | 110 | 3.4375 |
| IQ4_XS | 256 | 136 | 4.25 |
| IQ1_S | 256 | 50 | 1.5625 |
| TQ1_0 | 256 | 54 | 1.6875 |
| Q1_0 | 128 | 18 | 1.125 |
Three things stand out.
Q4 does not mean 4 bits. Q4_0 and Q4_K are both 4.5 bpw, one with 32-element blocks and one with 256-element blocks. The 4 is a tier name for the primary width, not an exact count.
Q8_K is bigger than Q8_0. 9.125 versus 8.5, because K-family superblocks store a scale and a minimum per block, and that overhead per weight costs more.
Same name, different block. Q4_0 packs 32 elements per block; Q4_K packs 256. That difference drives the size error in the next section, and it also decides whether a 1D tensor can be quantized at all (see Trap 8).
Trap 5: one name, two bpw values
tools/quantize/README.md in the llama.cpp repository carries a measured Llama-3.1-8B table listing whole-file bits per weight. Put it next to the block arithmetic and the gap appears:
| Name | Block arithmetic bpw | 8B file bpw | Difference |
|---|---|---|---|
| Q2_K | 2.6250 | 3.1593 | +20.4% |
| Q3_K_S | 3.4375 | 3.6429 | +6.0% |
| Q3_K_M | 3.4375 | 3.9960 | +16.2% |
| Q3_K_L | 3.4375 | 4.2979 | +25.0% |
| Q4_K_S | 4.5000 | 4.6672 | +3.7% |
| Q4_K_M | 4.5000 | 4.8944 | +8.8% |
| Q5_K_S | 5.5000 | 5.5704 | +1.3% |
| Q5_K_M | 5.5000 | 5.7036 | +3.7% |
| Q6_K | 6.5625 | 6.5633 | +0.0% |
| Q8_0 | 8.5000 | 8.5008 | +0.0% |
| IQ4_XS | 4.2500 | 4.4597 | +4.9% |
| IQ4_NL | 4.5000 | 4.6818 | +4.0% |
The pattern is clean: the purer the name, the closer the two numbers. Q6_K and Q8_0 differ by 0.0 percent because they are single types; Q3_K_L differs by 25 percent because it is the most heavily mixed of its family.
The extra bytes come from two structural sources. First, S/M/L mixing lifts some tensors to a higher width. Second, every file type enum entry carries the same trailing comment, // except 1d tensors — 1D tensors (normalization weights, biases) are not quantized, stay at F32 or F16, and their bytes still count in the average.
To estimate size, use the file-level bpw, not the block arithmetic. Computing a Q4_K_M 8B model at 4.5 underestimates it by about 8.8 percent.
Trap 6: S to M costs 5 percent, M to Q8 costs 74 percent
Same 8B table, sorted by GiB:
| Name | bpw | Size |
|---|---|---|
| Q2_K | 3.1593 | 2.95 GiB |
| Q4_K_S | 4.6672 | 4.36 GiB |
| Q4_K_M | 4.8944 | 4.58 GiB |
| Q5_K_M | 5.7036 | 5.33 GiB |
| Q6_K | 6.5633 | 6.14 GiB |
| Q8_0 | 8.5008 | 7.95 GiB |
| F16 | 16.0005 | 14.96 GiB |
As differences:
- Q4_K_S to Q4_K_M: +0.22 GiB, +5.0 percent
- Q4_K_M to Q5_K_M: +0.75 GiB, +16.4 percent
- Q4_K_M to Q6_K: +1.56 GiB, +34.1 percent
- Q4_K_M to Q8_0: +3.37 GiB, +73.6 percent
- Q4_K_M to F16: +10.38 GiB, +226.6 percent
"Where do the extra two gigabytes go when two models share a name" depends on which pair you compare. At 8B, Q4_K_M to Q6_K is 1.56 GiB and Q4_K_M to Q8_0 is 3.37 GiB, so two gigabytes sits between them.
S to M is only 0.22 GiB. Trading down for 220 MB is not worth much when an 8K-context KV cache dwarfs it.
Trap 7: four different sizes all starting with Q4
"Pick any Q4" is another common miss. Here is every Q4 entry in the official table:
| Name | File bpw | Size |
|---|---|---|
| IQ4_XS | 4.4597 | 4.17 GiB |
| Q4_K_S | 4.6672 | 4.36 GiB |
| IQ4_NL | 4.6818 | 4.38 GiB |
| Q4_K_M | 4.8944 | 4.58 GiB |
Four Q4 names, 0.41 GiB apart. And the order is counterintuitive: IQ4_XS is smaller than Q4_K_S, while IQ4_NL sits between Q4_K_S and Q4_K_M.
One layer out there is an inversion: Q3_K_L runs 4.2979 bpw and 4.02 GiB, smaller than Q4_K_S at 4.6672 and 4.36 GiB. "Q3_L is smaller than Q4_S" holds, but anyone reasoning "Q4 must be larger than Q3" gets it wrong.
The number in the name encodes family order, not size order.
Trap 8: 1D tensors are excluded because blocks do not align
// except 1d tensors appears so often it reads like boilerplate. It is actually a hard constraint: quantization works in blocks of 32 or 256, and a 1D tensor's length has no obligation to be a multiple of 256.
I tested both block sizes by feeding random float32 arrays straight into the quantizer:
n=256 Q4_0 ok -> (144,)
n=256 Q4_K NotImplementedError
n=255 Q4_K QuantError: Can't quantize tensor with shape (255,) to Q4_K
n=255 Q4_0 QuantError: Can't quantize tensor with shape (255,) to Q4_0
n=32 Q4_0 ok -> (18,)
n=30 Q4_0 QuantError: Can't quantize tensor with shape (30,) to Q4_0
At 255 elements both Q4_K and Q4_0 refuse. At 256, Q4_0 passes while Q4_K raises NotImplementedError (next section). At 30, even Q4_0 refuses.
Leaving 1D tensors at F32 or F16 is not caution; the block arithmetic simply does not apply. This is also why file-level bpw is always above block-arithmetic bpw.
Trap 9: gguf-py writes Q4_K but will not quantize it
That NotImplementedError deserves its own section. I fed all 34 types to gguf.quants.quantize():
- 11 succeeded: F32, F16, Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, BF16, TQ1_0, TQ2_0, MXFP4
- 23 raised
NotImplementedError
Of the 23, only 8 carry a message (the Quantization for Q8_K is not yet implemented form). The other 15 have an empty string as the exception message: Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, IQ2_XXS, IQ2_XS, IQ3_XXS, IQ1_S, IQ4_NL, IQ3_S, IQ2_S, IQ4_XS, IQ1_M, NVFP4.
An empty message means the log shows one line, NotImplementedError:, and nothing else. And the K and IQ families are exactly what people run today. In other words, the Python package can write 144 bytes of someone else's Q4_K data into a file; it cannot compress my float32 into Q4_K.
To actually quantize, use the llama-quantize C++ tool, or implement the block arithmetic yourself outside the package.
Trap 10: the package lags the header by two values
llama.cpp's include/llama.h (I pulled master) already reaches:
LLAMA_FTYPE_MOSTLY_Q1_0 = 40,
LLAMA_FTYPE_MOSTLY_Q2_0 = 41,
LLAMA_FTYPE_MOSTLY_F8_E4M3 = 42,
While gguf-py 0.19.0 stops at 40. So:
LlamaFileType(40) -> MOSTLY_Q1_0
LlamaFileType(41) -> ValueError: 41 is not a valid LlamaFileType
LlamaFileType(42) -> ValueError: 42 is not a valid LlamaFileType
Hitting this on a new model usually means the package is old, not that the file is broken. The tensor side tops out at 41 (Q1_0), so GGMLQuantizationType(42) is a ValueError too.
4.58 GiB and 4.9 GB are the same file
In the same official README, the quantization table lists the 8B Q4_K_M at 4.58 GiB while the memory and disk table lists it at 4.9 GB. That is not a typo: 4.58 GiB is 4.92 GB, which rounds to 4.9 GB.
GiB and GB differ by 7.4 percent, which is 0.34 GB at the 5 GB scale and over 1 GB at 15 GB. When a post says "two gigabytes apart," check the units first; sometimes it is only a conversion.
How to read a model filename
Five checks, in order:
- Look for S/M/L first. If present, it is a mixed tier: skip block arithmetic and use the official file-level bpw
- Read the family letter. Q is the early whole-block scheme (32-element blocks); K is 256-element superblocks; IQ is lattice quantization with an importance matrix; TQ is ternary. The letter sets the block structure; the digit only sets the tier
- Convert size as file-level bpw times parameter count divided by 8. 7.0e9 parameters at 4.8944 bpw is about 4.28 GB by arithmetic, excluding KV cache; that is a calculation, not a measurement
- For the smallest footprint, look at IQ4_XS. At 4.4597 bpw it beats Q4_K_S at 4.6672, and it still starts with a 4
- Never cross-look-up the numbers. Translate
general.file_typewithLlamaFileTypeand tensors withGGMLQuantizationType. The value 15 means two different things
Troubleshooting: four real errors
One: ValueError: Quantized tensor bytes per row (145) is not a multiple of Q4_K type size (144)
I deliberately passed 145 bytes for a Q4_K tensor. The check applies to bytes per row, not total bytes, so 144 is accepted (inferred as 256 elements) while 145 fails. Fix: supply an integer multiple of the block bytes from GGML_QUANT_SIZES[type].
Two: gguf.quants.QuantError: Can't quantize tensor with shape (255,) to Q4_K
255 is not a multiple of 256. Q4_K blocks are 256 elements, Q4_0 blocks are 32, so alignment depends on the type. Either pad to a whole number of blocks (which changes the data) or leave that tensor unquantized.
Three: NotImplementedError: with an empty message
gguf.quants.quantize() raises this for 15 types with no message. Do not expect str(e) to contain anything; map the type name into your own log line, or production will show one blank error.
Four: ValueError: 41 is not a valid LlamaFileType
general.file_type returned 41 or 42. The file is fine; gguf-py 0.19.0 has not caught up with llama.h. Upgrade the package, or handle the integer yourself with a local 41/42 mapping.
FAQ
Q: What does the M in Q4_K_M actually stand for?
The official documentation does not spell out the letters; it only says --pure disables k-quant mixing. The official bpw table does establish that S, M and L are three tiers within one family, and that M is the default recommendation: Q3 runs 3.6429 / 3.9960 / 4.2979, Q4 runs 4.6672 / 4.8944, Q5 runs 5.5704 / 5.7036. Reading M as "mixed more than S, less than L" fits the data.
Q: If file_type does not affect decoding, what is it for?
Three uses: a quick index telling tools and humans roughly how wide the file is; a fallback guess for loaders missing tensor information (that is what GUESSED = 1024 encodes); and a filterable name for model repositories. It never decodes anything; decoding reads each tensor's own tensor_type.
Q: Why not just use Q8_0 for everything?
Size. At 8B, Q8_0 is 7.95 GiB against 4.58 GiB for Q4_K_M, a 3.37 GiB gap. On a tight GPU that gap decides whether the model runs at all.
Q: Can I reuse the 7B arithmetic for an 8B model?
No. bpw is an average, and it shifts with parameter count, the share of 1D tensors, and vocabulary size. The 7.0e9 times 4.8944 divided by 8 above is a demonstration of the arithmetic; for real numbers, use the GiB figure the official table gives for that specific model.
Last word
The most useful result here is not any single number but that table of 30 shared values with 24 different meanings. It shows that a name like Q4_K_M has two identities by design: as a filename it is readable, filterable and shareable; as a value inside a program it requires the correct table.
In an earlier post on this site I broke down the eight cases where general.file_type gets written into a file and read back wrong (GGUF Metadata: Eight Fields That Read Back Wrong). That piece covered field round-trips. This one covers the name itself: the same word across two enums and two bpw tables.
Related reading: Five decode error handlers covers how bytes become strings, the mirror image of how bytes become weights here; TLS certificate verification has the same shape of silent failure, a default that turns verification off, much like a label that never decodes anything.
Every bpw and size figure above traces to one of two sources: the measured Llama-3.1-8B table in the llama.cpp repository at tools/quantize/README.md (master branch as of publication), and the GGML_QUANT_SIZES and LlamaFileType definitions inside gguf-py 0.19.0, with enum numbering cross-checked against include/llama.h. No benchmark numbers and no perplexity figures: I have no GPU here, so I do not publish those.
👉 Join Xiaomi MiMo Platform: Leading AI model platform with cost-effective inference
👉 Join Aliyun AI: Top AI products with exclusive coupons for business innovation
📌 This article was AI-assisted generated and human-reviewed | TechPassive — An AI-driven content testing site focused on real tool reviews
🔗 Recommended Tools
These are carefully selected tools. Using our affiliate links supports us to keep producing quality content:
As an Amazon Associate, I earn from qualifying purchases at no extra cost to you.