What's inside a model file? 🔬
You've downloaded a file called Llama-3.1-8B-Instruct-Q4_K_M.gguf. It's 4.9 gigabytes. What is it? A program? A database of everything on the internet? A tiny brain in a jar? Everyone talks about "the model", and almost nobody says what's actually in the file.
In the last article you trained a tiny GPT that invents names of frogs and snakes, then pressed Download and got a 430 KB file. Let's open it. Byte by byte, then tensor by tensor, then with a scalpel. Then we'll open the big one, and you'll see it's the same kind of thing.
Every figure is live. Under each one sit drawers: ▦ Numbers shows the actual values, ∑ Math the formulas with live numbers, and 🐍 Python runs NumPy right here in your browser on the same data. Nothing on this page sends your files anywhere.
Most figures also have a small 🎯 Challenge under the caption: a goal you reach with the demo itself, checked as you play. They are optional, and the page remembers which ones you solved.
The whole idea in one picture
A model is three things. A short program that says what arithmetic to do. A big file of numbers (the weights) that says what to do it with. And a loop that runs the program over and over, one token at a time. The file you download is only the middle box. Everything in this article is about that box: what's in it, how it's laid out, what happens when you change it, and why its size decides whether it runs on your laptop.
A model you can hold in 8 bytes: weights
Let's start with the smallest model there is. Say you measured how far some frogs jump, and you want to guess the jump of a frog you haven't measured. Draw a straight line through the points: jump = w × length + b. The line is the program. w and b are the weights. That's the whole model.
3e to bf) and watch the line jump. The points are made up.▦ Numbers
∑ Math
The program is one line; the file holds only its two numbers:
🐍 Python
Notice what's not in the file: the formula. The 8 bytes don't say "multiply the length by the first number and add the second". The program knows that. The file only makes sense to a program that already knows what the numbers are for. Hold on to that, it comes back in a big way later.
Why did the line jump so far when you changed one byte? Because those 4 bytes aren't a plain integer. They're a floating-point number, and different bytes mean very different things.
A number is four bytes: floats
A 32-bit float is scientific notation in binary: one bit for the sign, eight bits for an exponent (which power of 2), and 23 bits for the fraction (the digits). The last byte you edited held the sign and most of the exponent, which is why the line flipped and leapt.
∑ Math
For a normal number with sign bit \(s\), exponent bits \(E\) and fraction bits \(M\):
f32 has 8 exponent bits (bias 127) and 23 fraction bits. f16 has 5 and 10 (bias 15), so it runs out at 65504. bf16 keeps f32's 8 exponent bits and only 7 fraction bits: the same range as f32, with about 2 to 3 decimal digits.
🐍 Python
Two lessons for later. First, a model's size is mostly "how many numbers × how many bytes each". Second, the bytes per number is a choice. Most big models are shared as bf16: half the size of f32, the same range, fewer digits. Neural networks turn out to need the range much more than the digits.
Opening your frog-namer: the header and the body
Now the real thing. Here's the frog-namer from the last article, as the exact file Download gives you: a .safetensors file. It has three parts, laid out end to end.
🐍 Python
That's the entire format:
- 8 bytes: one integer, the length of the header.
- The header: plain JSON text. Every tensor's name, its number type (
F32), its shape, and which bytes of the body hold it. Plus__metadata__: free-form notes. Ours carries the vocabulary and the config, so the program knows how to read the rest. - The body: raw numbers, back to back, 4 bytes each. No separators, no labels. Over 99% of the file.
There's no code anywhere. No "if", no loop, no text about frogs. You could open a 16 GB Llama .safetensors the same way: read 8 bytes, read the JSON, and you know where every one of its eight billion numbers sits.
Every number has a name: tensors
A tensor is a named grid of numbers with a shape: a list ([64]), a table ([64, 256]), or more dimensions. The names aren't decoration. They're how the program finds the numbers for each step, so they follow a convention. Ours uses GPT-2's names on purpose, and you'll see why in the X-ray.
wte.weight: one row per token, with the emoji at the top.▦ Numbers
Read the names like an address. h.0.attn.c_attn.weight means: hidden layer 0, attnention, the matrix that makes queries, keys and values. Here's the whole map:
| name | what it does | in the last article |
|---|---|---|
wte | one row of 64 numbers per token | embeddings |
wpe | one row per position in the name | embeddings |
h.N.ln_1, ln_2 | layer norm: rescale, then stretch and shift | the block |
h.N.attn.c_attn | queries, keys and values, fused | attention |
h.N.attn.c_proj | mixes the heads back together | attention |
h.N.mlp.c_fc, c_proj | widen to 256, bend, squeeze back to 64 | the block |
ln_f, lm_head | final norm, then one score per token | softmax and the loss |
Two things to notice. The layers h.0 and h.1 have exactly the same tensors with the same shapes. A deeper model just has more of them. And the biggest boxes are the matrices inside each layer: most of a model is its layers, not its vocabulary. (In big models with 100K-token vocabularies, the embeddings get a lot bigger too.)
The file is not the program: architecture
Remember the 8-byte line: the file didn't contain the formula. Same here. The file says h.0.attn.c_attn.weight is a 64 × 192 grid. It doesn't say "cut each 64-number query into 4 heads of 16". That's in the program, and in the config the program reads. So let's lie to the program. Same bytes, different config.
∑ Math
The heads are just a way of cutting the same vector. With \(H\) heads, each query \(q\) of width \(d\) is split into \(H\) pieces, and each piece only compares with the matching piece of each key:
Change \(H\) and the same 64 numbers get grouped differently, with a different \(\sqrt{d/H}\). The weights were trained for one particular cut.
🐍 Python
On the pretrained model, changing the number of heads turns the names into frog-flavoured mush, and swapping the two layers turns them into letter soup. Running only layer 0 is the surprise: the names get worse, but they're still names. The second layer polishes; it doesn't carry everything.
This is why model files come with a config (config.json next to a Hugging Face model, or the metadata inside a GGUF), and why "this model needs a newer version of llama.cpp" happens: a model is only usable by a program that knows its architecture. The weights are meaningless on their own.
Brain surgery: what each part does
If the numbers are all there is, we can find out what each part does by removing it. Neuroscientists wish they had it this easy. Each cut below edits a copy of the weights: zeroing one head's slice of c_proj, zeroing a whole attention or MLP output, wiping the position embeddings, or swapping two rows of wte.
▦ Numbers
🐍 Python
Here's what the pretrained model does. Cut layer 0's MLP and the names collapse into runs of the same few letters, like riarirrrrriarrrr: the first layer carries the basic spelling. Cut layer 1's MLP or attention and the names get sloppier but stay recognisable. The heads in layer 0 matter more than the ones in layer 1. Small noise barely hurts it: the weights aren't fragile, precise values. That will matter in the next section.
And the swap: the prompt lives in one row of 64 numbers. Swap the 🐸 and 🐍 rows and asking for a 🐸 gets you snakes, like spotted ground boa. The emoji is just a token, and everything the model "knows" about frogs-as-a-request is that row, plus the weights that learned to react to it.
Interpretability research does this kind of surgery for real on big models (it's called ablation). It's harder there, because ideas are smeared across many heads and layers, but the move is the same: change the numbers, watch the output.
Squeezing the numbers: quantization
Noise didn't hurt much. So do we need 32 bits per number? This is quantization: store each weight in fewer bits. The simplest kind takes a block of 32 weights, finds the biggest one, and stores every weight as a small integer step of biggest ÷ 7 (for 4 bits), plus that one scale. It's what llama.cpp's Q4_0 does, and what the Q4_K_M in the Llama filename is a smarter version of.
measuring…
held-out loss (lower is better) and the size of the numbers
∑ Math
For a block of 32 weights and \(b\) bits: one scale \(s\), and each weight becomes an integer \(q\) between \(-(2^{b-1}-1)\) and \(2^{b-1}-1\). Here's the first weight of the block:
The storage cost is \(b\) bits per weight plus 16 bits for \(s\) per 32 weights, so 4-bit costs 4.5 bits per weight. Biases and layer norms stay in f32: they're a tiny share of the bytes.
🐍 Python
On the pretrained model, f16, bf16 and 8-bit give the same held-out loss as f32 (to three decimals), at a quarter of the size for 8-bit. 4-bit is only a little worse, and the names are still fine. At 3 bits the names start to break, and 2 bits is gibberish. Big models behave similarly, which is why 4-bit is the popular sweet spot for running them at home. (A tiny model isn't a perfect stand-in: big models have more redundancy, and the clever formats protect the weights that matter most.)
That 4.9 GB Llama file from the top of the page? Its Q4_K_M uses about 4.9 bits per weight. In bf16, the same model is 16 GB.
The X-ray: open any model
You've now seen everything a model file contains. So let's look inside the big ones. Drop any .safetensors or .gguf file from your disk, the 70 GB kind too. The page reads only the header (a few kilobytes to a few megabytes), so it's instant, and nothing is uploaded: it all happens in this tab. No model file handy? Pick one of ours; their headers were fetched from the real files.
Drop a .safetensors or .gguf file here
Read on your machine, header only. Nothing is uploaded. For a model split into shards, drop all the shards together.
▦ Numbers
∑ Math
Parameters are just the shapes multiplied out and added up. For a GPT-2-style model with width \(d\), vocabulary \(V\), context \(T\) and \(L\) layers, every layer has \(12d^2 + 13d\):
🐍 Python
Things to look for:
- The repetition. The layer strip is a row of identical bars. GPT-2 small is the same layer 12 times; Llama 3.1 8B is a slightly different layer 32 times. "Deeper" literally means "more copies".
- The same names. Every tensor name in the frog-namer is in GPT-2 too, with the same role, only wider. The one exception is
lm_head: GPT-2 reuseswteas its output head (the X-ray says "tied"), while ours has its own. Your 430 KB file and a famous 2019 model are the same kind of object. - The vocabulary. Our model has 38 tokens; GPT-2 has 50,257 and Llama 3 has 128,256 subword tokens. That's why
wteis a speck in the frog-namer and a big slab in Llama. - Different families, different names. Llama splits
c_attnintoq_proj,k_proj,v_proj, has a third MLP matrix (gate_proj), and has no biases. Same ideas, different program, so a GPT-2 program can't run Llama's weights. - Buffers. GPT-2's file also stores
h.N.attn.bias: not a learned weight but the causal mask, a fixed triangle of ones that hides future letters. The X-ray counts its bytes but not as parameters. - Experts. The Qwen3 model has 30.5 billion numbers, but each token only goes through 8 of each layer's 128 experts (the
ffn_*_expstensors). A smallffn_gate_inp"router" picks which ones.
Why not .bin or .pt files? Those are Python pickles, and loading a pickle can run any code hidden inside it. That's exactly why .safetensors was invented: a format that can only ever contain a header and numbers.
Will it run on my machine? size and speed
Two questions decide whether you can run a model. Does it fit? That's the file size: parameters × bits per number. And how fast is it? Here's the surprise: to generate each token, the program has to read every weight once (one multiply each, and there are billions). A laptop can do the arithmetic much faster than it can fetch the numbers from memory. So the speed limit is memory bandwidth ÷ bytes per token.
∑ Math
For the model in the X-ray, on this machine:
A mixture-of-experts model only reads the experts a token uses, so its bytes per token come from its active parameters, while its size still counts all of them.
This is why quantization matters so much at home: 4-bit numbers are smaller and faster, since there are 4× fewer bytes to stream than in f16. It's why Apple's chips with wide memory buses are popular for local models, and why mixture-of-experts models feel quicker than their size suggests.
From here to the big ones
Here's the frog-namer next to three real models, computed from their file headers:
Same ingredients all the way up: named tensors, repeated layers, a config, and a program that knows what to do with them. The big ones add a real tokenizer (a vocabulary of subword pieces, which lives inside a GGUF or in a separate tokenizer.json), cleverer number formats, and sometimes experts. What they don't add is anything other than numbers. There's no hidden database of facts in there: whatever Llama "knows" about frogs is spread across those eight billion weights, the same way our model's frog-ness is spread across 107 thousand.
Cheat sheet
| thing | what it means |
|---|---|
| model | program (architecture) + weights (numbers) + a loop that runs them |
| .safetensors | 8-byte length, JSON header (names, dtypes, shapes, offsets), raw numbers |
| .gguf | llama.cpp's format: header with metadata, tokenizer and tensor list, then numbers |
| tensor | a named grid of numbers with a shape; params = the shape multiplied out |
| f32 / f16 / bf16 | sign + exponent + fraction in 32 / 16 / 16 bits; bf16 keeps f32's range |
| block quantization | per 32 weights: one scale \(s\), integers \(q = \text{round}(w/s)\), weight \(\approx q s\) |
| size | params × bits per weight ÷ 8 |
| speed limit | tokens/s ≤ memory bandwidth ÷ bytes read per token |
| buffer | stored but not learned (a causal mask, rotary tables); not a parameter |
Conclusion
A model file is a list of named grids of numbers, with a short JSON note in front saying where each grid starts. That's all. The intelligence, such as it is, lives in which numbers they are, and it only comes alive when a program that knows the architecture runs them, one token at a time. Change the program and the same numbers babble. Change the numbers and the same program forgets how to spell, or makes snakes when you ask for frogs. Round the numbers to 4 bits and almost nothing changes, which is why a model that needs 16 GB in bf16 runs from a 4.9 GB file on a laptop.
Haven't trained your own yet? Train a tiny GPT on your GPU in about a minute, download it, and open it in Demo 3: every experiment on this page then runs on your model.
If you want to go further: open a real model in Python with the safetensors library and compare what you see with the X-ray; read llama.cpp's gguf docs and its K-quant formats; and look up ablation and mechanistic interpretability for brain surgery done on real models. Happy opening! 🔬📦✨
🎯 challenges ·
Data: model headers fetched from Hugging Face (links in the X-ray). Frog, snake and plant names from Wikidata (CC0), as in the last article.