Pidoku

llama.cpp and GGUF from the Inside

Module 29 Lesson 29.b 1h 30m Difficulty 4/5

Prerequisites 29.a, 15.e, 10.l, 12.e, 13.f


Before you start: words you need#

WordPlain meaning
ggmlThe small C tensor library under llama.cpp. It builds a graph of tensor operations and runs it on a “backend” (CPU, Metal, CUDA, Vulkan and others).
GGUFThe single-file model format ggml reads: a header, key-value metadata, a table of tensors, then the raw tensor bytes.
Block quantizationCutting a weight row into small blocks (32 or 256 weights) and storing each block as low-bit integers plus a scale.
Bits per weight (bpw)Average storage per weight including the scales. Q4_K is 4.5 bpw, not 4.
Importance matrix (imatrix)Statistics of how strongly each weight column is used, measured by running sample text. Quantizers use it to spend precision where it matters.
mmapMapping a file into memory so the OS loads pages on demand instead of the program reading the whole file first.
OffloadPutting some layers or tensors on a GPU and leaving the rest on the CPU.
SlotOne concurrent conversation in llama-server. Each slot owns a part of the KV cache.

1. What is it?#

llama.cpp is the C/C++ inference engine behind most local LLM use: Ollama, LM Studio, many phone apps and desktop tools run it, directly or through its library. GGUF is its file format. 15.e introduced both as tools; this lesson opens them up: what is in the file byte by byte, how a block of 4-bit weights is laid out and decoded, what the Q4_K_M name means, how the engine turns a model into a graph and spreads it over CPU and GPU, and which knobs matter.

State on 13 November 2026:

  • llama.cpp ships several numbered builds a day (b12340 on 13 November 2026) and, since August 2026, also semantic-version releases (v0.9.0, 4 November 2026, bundling ggml v0.29.0). The project notes that semantic versioning is still being worked out.
  • The front door is now one llama command (llama cli, llama serve); the separate binaries such as llama-server and llama-quantize remain.
  • Backends: CPU (x86, Arm, RISC-V), Metal, CUDA, HIP, Vulkan, SYCL, OpenCL (Adreno), Hexagon (Snapdragon NPU), CANN, MUSA, WebGPU, an in-progress OpenVINO backend, and RPC for spreading a model over several machines.

Facts checked on 13 November 2026.


2. Why does it matter?#

  • It is the reference for running quantized models on small hardware. Most new open models get a GGUF and llama.cpp support within days, and many on-device apps embed it.
  • Its formats are a lingua franca. “Q4_K_M” is how people describe a local model’s size and quality, even outside llama.cpp. Knowing what it means lets you predict memory, speed and quality.
  • Its design choices are the edge playbook in small: one file, memory-mapped; many hand-written kernels per backend; block quantization tuned for CPUs; CPU and GPU sharing one model.
  • When something goes wrong locally (garbled output, slow decode, out-of-memory), the fix is usually in the file’s metadata, its quantization mix or the offload settings. You need to see inside.

3. Simple analogy#

A GGUF file is a shipping container with a packing list taped inside the door. The packing list (the header and metadata) says what model this is, how its tokenizer works and where each crate is. The crates (tensors) are stacked at fixed, aligned positions, so a forklift (mmap) can lift out any crate without unpacking the others. Inside each crate, weights are vacuum-packed in small bags of 32 or 256 (blocks), each bag labelled with its own scale so it can be unpacked correctly.


4. Tiny example: one 4-bit block#

Q4_0 stores 32 weights in 18 bytes: one FP16 scale d (2 bytes) and 32 four-bit numbers (16 bytes). That is 18 × 8 ÷ 32 = 4.5 bits per weight.

To quantize, the reference code finds the weight with the largest magnitude, max, and sets d = max / -8. Each weight becomes q = round(x / d) + 8, a number from 0 to 15. To decode: x ≈ (q − 8) × d.

weights   +0.0322  +0.0493  +0.0432 ... +0.1100 (largest)
d = 0.1100 / -8 = -0.01375
q            6        4        5    ...    0
back     +0.0275  +0.0550  +0.0412  ... +0.1100

The largest weight comes back exactly; the others land on the nearest of 16 levels. One outlier stretches the step size for the whole block, which is why smaller blocks and smarter scales (the K and IQ formats) matter.


5. Technical explanation#

Inside a GGUF file#

A GGUF file has four parts, all little-endian by default:

  1. Header: the magic bytes GGUF, the format version (3 today), the number of tensors, and the number of metadata pairs.
  2. Metadata: typed key-value pairs. Keys are dotted lower-case names such as general.architecture (llama, qwen3, gemma4…), general.alignment, <arch>.block_count, <arch>.context_length, <arch>.attention.head_count_kv, tokenizer.ggml.tokens (the whole vocabulary), tokenizer.ggml.merges and tokenizer.chat_template (the Jinja template used to format chats). Everything needed to run the model is here; there is no config.json beside it.
  3. Tensor infos: for each tensor, its name (blk.12.attn_q.weight), up to four dimensions, its ggml_type (F16, Q8_0, Q4_K…) and its byte offset into the data section.
  4. Tensor data: the raw bytes, each tensor starting at a multiple of general.alignment (32 bytes if unset), so tensors can be mapped and read without copying.

The naming convention for files is <BaseName>-<SizeLabel>-<FineTune>-<Version>-<Encoding>.gguf, for example Qwen3-27B-v1.0-Q4_K_M.gguf. Two sidecar prefixes now exist: mmproj- for a multimodal projector (the vision or audio encoder, loaded beside the language model) and mtp- for multi-token-prediction heads used as a speculative-decoding drafter. Large models are split into shards named -00001-of-00003.gguf.

The type zoo#

enum ggml_type lists the formats a tensor can have. They fall into families:

FamilyTypesBlockIdea
FloatF32, F16, BF16, F8_E4M3 (new in v0.9.0)noneplain numbers
LegacyQ4_0, Q4_1, Q5_0, Q5_1, Q8_032one scale (and for _1, a minimum) per 32 weights
K-quantsQ2_K, Q3_K, Q4_K, Q5_K, Q6_K256 “super-block” of 8–16 sub-blockssub-block scales are themselves quantized (6 or 8 bits) against one FP16 super-scale, so scales cost little
I-quantsIQ1_S, IQ1_M, IQ2_XXS…IQ2_M, IQ3_XXS…IQ3_M, IQ4_NL, IQ4_XS256 (IQ4_NL: 32)weights snap to points of a fixed non-uniform grid or lattice; best quality at 1.5–3.5 bpw, slower to decode on some backends
Ternary and 1–2 bitTQ1_0, TQ2_0, Q1_0, Q2_0256, 128, 64for models trained to tolerate it (ternary weights, 1-bit models)
Microscaling FP4MXFP4, NVFP432, 64the FP4 formats from the data centre (13.g): E2M1 values with an E8M0 scale per 32 (MXFP4) or an E4M3 scale per 16 (NVFP4)

A file is rarely one type. A file type such as Q4_K_M is a recipe that picks a type per tensor. From llama-quant.cpp, Q4_K_M stores most weights as Q4_K but:

  • attn_v and ffn_down get Q6_K in “more bits” layers: the first eighth, the last eighth and every third layer in between (these tensors hurt most when squeezed);
  • fused attn_qkv tensors get Q5_K; the output head usually gets Q6_K.

So Q4_K_M averages about 4.89 bpw (4.58 GiB for Llama 3.1 8B), not 4.5. _S, _M and _L mean small, medium and large recipes. You can override any tensor yourself with llama-quantize --tensor-type attn_v=q6_k or a regular expression.

Quality: what the recipes cost#

llama.cpp’s quantizer prints its own reference table, measured on Llama-3-8B (perplexity increase against FP16; lower is better):

TypeSizePerplexity increase
Q8_07.96 GB+0.0026
Q6_K6.14 GB+0.0217
Q5_K_M5.33 GB+0.0569
Q4_K_M4.58 GB+0.1754
Q4_04.34 GB+0.4685
Q3_K_M3.74 GB+0.6569
Q2_K2.96 GB+3.5199

Read across: Q4_K_M is about the same size as Q4_0 with less than half the damage, because of sub-block scales and the mixed recipe. Below about 3.5 bpw the K-quants fall off a cliff; the I-quants with an importance matrix are the better choice there (29.f).

The importance matrix#

llama-imatrix runs the full-precision model on calibration text and records, for each weight matrix, the mean squared activation reaching each input column. Columns that see large activations matter more. The quantizer then picks scales (and, for I-quants, grid points) that minimise weighted error. It is the GGUF counterpart of the activation-aware ideas in AWQ and GPTQ (13.c). Use calibration text that resembles your real traffic, including code or other languages if your users send them.

From file to graph#

What happens when you start llama-server -m model.gguf:

  1. Load. The loader reads the header and metadata, builds the vocabulary and chat template, and memory-maps the data section (--load-mode defaults to auto: mmap unless a device cannot use it; mlock pins pages, dio uses direct I/O).
  2. Place. Each tensor gets a buffer type: CPU memory, a GPU’s memory, or a special layout. With --fit on (the default) llama.cpp measures free device memory and chooses context size, GPU layers and expert placement to fit, leaving a 1 GiB margin per device; llama-fit-params prints its choices.
  3. Repack. On CPUs, --repack (on by default) rearranges blocks into interleaved layouts that match the SIMD instructions (Arm i8mm and SVE, x86 AVX-512/AMX). This is why old special types such as Q4_0_4_4 were removed from GGUF: the engine now does the interleaving at load time.
  4. Build the graph. For each micro-batch the model code builds a ggml compute graph: embeddings, then per layer RMSNorm, QKV projections, RoPE, attention (FlashAttention kernels where the backend has them), the feed-forward or MoE block, and the output head.
  5. Schedule. The ggml backend scheduler splits the graph into pieces per backend, inserts copies where data crosses from CPU to GPU, and runs them. The logical batch (-b, default 2048) is cut into physical micro-batches (-ub, default 512) for prefill.
  6. Sample. A chain of samplers (penalties, top-k, top-p, min-p, temperature, grammar) picks the next token (12.o).

Splitting a model between CPU and GPU#

Offload is how llama.cpp runs models bigger than the GPU:

  • -ngl N (auto by default) keeps N layers on the GPU and the rest on the CPU.
  • -ot <regex>=<buffer> overrides placement per tensor. The common MoE trick keeps attention and shared weights on the GPU and sends expert tensors to system RAM: -ot "blk\..*\.ffn_.*_exps\.=CPU", or more simply --n-cpu-moe N for the first N layers.
  • Why it works: in a MoE model each token touches only a few experts, so the CPU reads a small slice of a large tensor, while the GPU handles attention and the KV cache. Decode speed then depends on system-RAM bandwidth for the expert bytes actually read.

The server#

llama-server is a small but complete serving engine:

  • Slots (-np, automatic by default) give a few concurrent conversations continuous batching (12.j). By default the slots share one unified KV buffer, sized by -c.
  • Prompt cache in RAM (--cache-ram, 8 GiB by default) keeps idle slots’ KV state so a returning conversation does not re-read its history (12.m).
  • KV cache types (-ctk, -ctv): f16 by default; q8_0, q4_0, iq4_nl and others save memory (13.h).
  • Speculative decoding with a small draft model, an mtp- sidecar, or n-gram lookup (12.n).
  • Grammar-constrained output (GBNF grammars and JSON schema) for tool calls.
  • OpenAI-compatible endpoints, including /v1/responses, plus a built-in web UI.

6. Under the hood#

Writing and reading a GGUF#

This program writes a two-tensor GGUF in memory exactly as the specification lays it out, then parses it back the way a loader does.

Go
// gguf.go — write a tiny GGUF v3 file in memory, then parse it back the way a loader does.
package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
)

const (
	typeUint32 = 4
	typeString = 8
	ggmlF32    = 0
	ggmlQ8_0   = 8
	alignment  = 32
)

var le = binary.LittleEndian

func putString(b *bytes.Buffer, s string) {
	binary.Write(b, le, uint64(len(s)))
	b.WriteString(s)
}

func getString(r *bytes.Reader) string {
	var n uint64
	binary.Read(r, le, &n)
	s := make([]byte, n)
	r.Read(s)
	return string(s)
}

func main() {
	// ---- write ----
	var b bytes.Buffer
	b.WriteString("GGUF")                 // magic
	binary.Write(&b, le, uint32(3))       // version
	binary.Write(&b, le, uint64(2))       // tensor count
	binary.Write(&b, le, uint64(2))       // metadata key-value count
	putString(&b, "general.architecture") // KV 1: string
	binary.Write(&b, le, uint32(typeString))
	putString(&b, "llama")
	putString(&b, "llama.block_count") // KV 2: uint32
	binary.Write(&b, le, uint32(typeUint32))
	binary.Write(&b, le, uint32(1))

	type info struct {
		name string
		dims []uint64
		typ  uint32
		size uint64 // bytes of data
	}
	tensors := []info{
		{"blk.0.attn_norm.weight", []uint64{64}, ggmlF32, 64 * 4},
		{"blk.0.attn_q.weight", []uint64{64, 64}, ggmlQ8_0, 64 * 64 / 32 * 34}, // 34-byte blocks of 32
	}
	var off uint64
	for _, t := range tensors {
		putString(&b, t.name)
		binary.Write(&b, le, uint32(len(t.dims)))
		for _, d := range t.dims {
			binary.Write(&b, le, d)
		}
		binary.Write(&b, le, t.typ)
		binary.Write(&b, le, off) // offset relative to the start of the data section
		off += t.size
		off += (alignment - off%alignment) % alignment
	}
	for b.Len()%alignment != 0 { // pad so the data section starts aligned
		b.WriteByte(0)
	}
	dataStart := b.Len()
	b.Write(make([]byte, off)) // tensor bytes (zeros here)

	// ---- read ----
	r := bytes.NewReader(b.Bytes())
	magic := make([]byte, 4)
	r.Read(magic)
	var version uint32
	var nTensors, nKV uint64
	binary.Read(r, le, &version)
	binary.Read(r, le, &nTensors)
	binary.Read(r, le, &nKV)
	fmt.Printf("magic %q  version %d  tensors %d  metadata %d\n", magic, version, nTensors, nKV)
	for i := uint64(0); i < nKV; i++ {
		key := getString(r)
		var vt uint32
		binary.Read(r, le, &vt)
		switch vt {
		case typeString:
			fmt.Printf("  kv  %-22s = %q\n", key, getString(r))
		case typeUint32:
			var v uint32
			binary.Read(r, le, &v)
			fmt.Printf("  kv  %-22s = %d\n", key, v)
		}
	}
	for i := uint64(0); i < nTensors; i++ {
		name := getString(r)
		var nd uint32
		binary.Read(r, le, &nd)
		dims := make([]uint64, nd)
		binary.Read(r, le, dims)
		var typ uint32
		var o uint64
		binary.Read(r, le, &typ)
		binary.Read(r, le, &o)
		fmt.Printf("  tensor %-24s dims %v  type %d  offset %d\n", name, dims, typ, o)
	}
	headerEnd := len(b.Bytes()) - r.Len()
	fmt.Printf("header ends at byte %d, data starts at byte %d (aligned to %d), file is %d bytes\n",
		headerEnd, dataStart, alignment, b.Len())
}

Output:

magic "GGUF"  version 3  tensors 2  metadata 2
  kv  general.architecture   = "llama"
  kv  llama.block_count      = 1
  tensor blk.0.attn_norm.weight   dims [64]  type 0  offset 0
  tensor blk.0.attn_q.weight      dims [64 64]  type 8  offset 256
header ends at byte 215, data starts at byte 224 (aligned to 32), file is 4832 bytes

A real loader does the same, then maps the data section and points each tensor at dataStart + offset. Note what a reader must check: the magic, the version, that every offset is aligned and inside the file, and that string lengths are sane. A GGUF is untrusted input: llama.cpp has fixed several out-of-bounds bugs in its parser, so only load files from sources you trust and keep the engine updated.

Bits per weight, from the block layouts#

The second program computes bits per weight from the block structures in ggml-common.h, then runs the Q4_0 round trip from section 4.

Go
// blocks.go — bits per weight of GGUF block types, and a Q4_0 round trip.
package main

import (
	"fmt"
	"math"
)

func main() {
	// Block sizes from ggml-common.h: weights per block and bytes per block.
	blocks := []struct {
		name    string
		weights int
		bytes   int
		layout  string
	}{
		{"Q8_0", 32, 2 + 32, "fp16 scale + 32 int8"},
		{"Q4_0", 32, 2 + 16, "fp16 scale + 32 nibbles"},
		{"MXFP4", 32, 1 + 16, "E8M0 scale + 32 FP4 (E2M1)"},
		{"NVFP4", 64, 4 + 32, "4 E4M3 scales (one per 16) + 64 FP4"},
		{"Q4_K", 256, 2 + 2 + 12 + 128, "fp16 d, dmin + 8 six-bit scales/mins + nibbles"},
		{"Q5_K", 256, 2 + 2 + 12 + 32 + 128, "as Q4_K + 1 high bit each"},
		{"Q6_K", 256, 128 + 64 + 16 + 2, "4+2 bits each + 16 int8 scales + fp16 d"},
		{"Q3_K", 256, 32 + 64 + 12 + 2, "2+1 bits each + 16 six-bit scales + fp16 d"},
		{"Q2_K", 256, 16 + 64 + 2 + 2, "2 bits each + 16 four-bit scales/mins + d, dmin"},
		{"IQ4_XS", 256, 2 + 2 + 4 + 128, "non-linear 4-bit grid + six-bit scales"},
	}
	fmt.Println("type    weights  bytes   bits/weight  layout")
	for _, b := range blocks {
		fmt.Printf("%-7s %7d %6d %12.4f  %s\n", b.name, b.weights, b.bytes, float64(b.bytes*8)/float64(b.weights), b.layout)
	}

	// Q4_0, as ggml's reference quantizer does it: the value with the largest
	// magnitude maps to -8, so d = max / -8 and q = round(x/d) + 8 in [0, 15].
	x := make([]float32, 32)
	for i := range x {
		x[i] = float32(math.Sin(float64(i)*0.7)) * 0.05 // weights are small numbers
	}
	x[5] = 0.11 // one outlier
	var amax, max float32
	for _, v := range x {
		if a := float32(math.Abs(float64(v))); a > amax {
			amax, max = a, v
		}
	}
	d := max / -8
	var sq float64
	for i, v := range x {
		q := int(v/d + 8.5)
		if q > 15 {
			q = 15
		}
		y := float32(q-8) * d
		e := float64(v - y)
		sq += e * e
		if i < 4 || i == 5 {
			fmt.Printf("x[%2d] = %+.4f  q = %2d  back = %+.4f\n", i, v, q, y)
		}
	}
	fmt.Printf("scale d = %.5f  (step between levels)\n", d)
	fmt.Printf("RMS error %.5f on weights whose RMS is %.5f\n", math.Sqrt(sq/32), rms(x))
}

func rms(x []float32) float64 {
	var s float64
	for _, v := range x {
		s += float64(v) * float64(v)
	}
	return math.Sqrt(s / float64(len(x)))
}

Output:

type    weights  bytes   bits/weight  layout
Q8_0         32     34       8.5000  fp16 scale + 32 int8
Q4_0         32     18       4.5000  fp16 scale + 32 nibbles
MXFP4        32     17       4.2500  E8M0 scale + 32 FP4 (E2M1)
NVFP4        64     36       4.5000  4 E4M3 scales (one per 16) + 64 FP4
Q4_K        256    144       4.5000  fp16 d, dmin + 8 six-bit scales/mins + nibbles
Q5_K        256    176       5.5000  as Q4_K + 1 high bit each
Q6_K        256    210       6.5625  4+2 bits each + 16 int8 scales + fp16 d
Q3_K        256    110       3.4375  2+1 bits each + 16 six-bit scales + fp16 d
Q2_K        256     84       2.6250  2 bits each + 16 four-bit scales/mins + d, dmin
IQ4_XS      256    136       4.2500  non-linear 4-bit grid + six-bit scales
x[ 0] = +0.0000  q =  8  back = -0.0000
x[ 1] = +0.0322  q =  6  back = +0.0275
x[ 2] = +0.0493  q =  4  back = +0.0550
x[ 3] = +0.0432  q =  5  back = +0.0412
x[ 5] = +0.1100  q =  0  back = +0.1100
scale d = -0.01375  (step between levels)
RMS error 0.00397 on weights whose RMS is 0.03994

The bits per weight match the comments in ggml-common.h (“effectively 4.5 bits per weight” for Q4_K, 6.5625 for Q6_K, 2.625 for Q2_K). Q4_K and Q4_0 cost the same 4.5 bpw, but Q4_K gives every 32 weights their own 6-bit scale and minimum, which fits real weight distributions better. The round trip shows the cost of one outlier: about 10% RMS error on this block.

How a quantized dot product runs#

Kernels do not dequantize whole tensors to FP16 first. On the CPU, for decode, the activation vector is quantized on the fly to 8 bits (Q8_K or Q8_0), and the kernel multiplies 4-bit weights by 8-bit activations with integer dot-product instructions (Arm sdot/i8mm, x86 VNNI), applying the two scales once per block. Integer maths on packed data keeps both the memory traffic and the instruction count low. On GPUs (CUDA, Metal, Vulkan), llama.cpp has “MMVQ” kernels for batch-1 decode that read quantized blocks directly, and “MMQ” or dequantize-then-GEMM paths for prefill.


7. Performance implications#

  • Decode speed tracks file size. In llama.cpp’s own table for Llama 3.1 8B, text generation runs at about 29 tokens per second at F16, 51 at Q8_0, 72 at Q4_K_M and 80–90 at 2–3 bpw. Speed rises more slowly than size falls, because unpacking low-bit blocks costs instructions.
  • Prefill barely changes with quantization (about 760–920 tokens per second across all types in the same table): it is compute-bound, and the weights are dequantized for matrix-matrix work.
  • I-quants can be slower than K-quants of the same size on some backends, because grid lookups cost more than shifts and masks. Measure on your target.
  • Partial offload is limited by the slowest part. If 20% of the bytes per token come from system RAM at 80 GB/s and the rest from a GPU at 1 TB/s, the RAM part dominates the token time.
  • Flash attention and KV quantization (-fa auto, -ctk q8_0) cut memory and help long contexts; quantized V caches need flash attention on most backends.
  • Use llama-bench (pp512 for prefill, tg128 for decode) to compare builds, types and flags on the same machine.

8. Production implications#

  • Pin the build. llama.cpp changes daily. Pin a release or build number, and re-run your quality and speed checks when you move it.
  • Pin and hash the file. A GGUF re-uploaded with a fixed chat template is a different model in practice. Store the SHA-256 and the quantization recipe.
  • Check the chat template. It lives in the file’s metadata (tokenizer.chat_template). A wrong template is the most common cause of “the local model is dumber than the API” (28.f).
  • Measure quality with KL divergence, not just perplexity. llama-perplexity can save the full-precision model’s logits (--kl-divergence-base) and compare a quantized model against them (--kl-divergence); KLD and “same top token” rates catch damage that average perplexity hides (28.e).
  • Treat GGUF files as untrusted input and llama-server as a network service: bind to localhost or put authentication in front (23.i).
  • Ship the right quant for the device: Q4_K_M or IQ4_XS for laptops, Q4_0 where the NPU or GPU backend only accelerates the legacy types (check the backend’s supported-ops table).

9. Common mistakes#

  1. Reading Q4 as “4 bits”. Scales and the mixed recipe make Q4_K_M about 4.9 bpw.
  2. Re-quantizing a quantized file (--allow-requantize). Errors compound; always start from BF16 or F16.
  3. Using an imatrix built from the wrong text, for example English prose for a code model.
  4. Assuming a GGUF is portable across llama.cpp versions forever. New architectures and metadata keys need a new enough engine; very old files may need re-conversion.
  5. Forgetting the mmproj sidecar for vision models, then wondering why image input fails.
  6. Offloading attention to the CPU and experts to the GPU in a MoE model. It is the other way round: dense, every-token tensors belong on the fast device.

10. Hands-on exercise#

  1. Run gguf.go. Add a third tensor of type Q4_K (144-byte blocks of 256 weights, shape 256 × 64) and check that its offset is aligned.
  2. Extend the reader to open a real GGUF from disk (read only the header and tensor infos) and print the metadata keys and the count of tensors per type. Compare with the output of the gguf-py tools shipped with llama.cpp.
  3. In blocks.go, move the outlier to 0.5 and watch the RMS error. Then split the 32 weights into two blocks of 16 with their own scales. How much does the error fall, and how many bits per weight does the extra scale cost?
  4. Quantize a 1–4B model to Q8_0, Q4_K_M, IQ4_XS and Q2_K, with and without an imatrix. Run llama-bench and llama-perplexity --kl-divergence on each. Plot KL divergence against file size.
  5. Run a MoE model larger than your GPU with --n-cpu-moe set to different values. Plot decode speed against the number of layers whose experts sit in system RAM.

11. Interview questions#

  1. Walk through the layout of a GGUF file. Why are tensor offsets aligned, and why does that matter for mmap?
  2. Q4_0 and Q4_K are both 4.5 bpw. Why does Q4_K give better quality?
  3. What does Q4_K_M do differently for attn_v and ffn_down, and why those tensors?
  4. What is an importance matrix, how is it computed, and how does it relate to AWQ or GPTQ?
  5. Explain how llama.cpp runs a 100B-parameter MoE model on a 24 GB GPU and what limits its speed.
  6. Why does quantization speed up decode much more than prefill?

12. Further reading#

Checked on 13 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in