What's inside a model file? 🔬

2026-12-03 · interactive · ~30 min · opens real model files, on your machine

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

the program ~100 lines: multiply, add, normalise, softmax the numbers model.safetensors run it next-letter guess append it, run again 🐸 slender bush frog

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.

Demo 1 · A model in 8 bytes
The model file: two 32-bit numbers, 4 bytes each.
Drag the red handles to fit the line, and watch the 8 bytes change. Then type into a byte (try changing the last byte of w from 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.

Demo 2 · One number, bit by bit
format
number
Click any bit to flip it. Then switch to f16 and bf16: the same number in half the bytes. Which one can still store 70000? Which one keeps more digits of 0.1?
∑ 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.

Demo 3 · The file, end to end
byte 0← header · every tensor's bytes →end

Click the parts of the bar: the first 8 bytes, the header, then any tensor. In the header, click a tensor's line to jump to its bytes. If you trained your own model in the last article, open its file and every demo below switches to it.
🐍 Python

  

That's the entire format:

  1. 8 bytes: one integer, the length of the header.
  2. 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.
  3. 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.

Demo 4 · The tensors, by size

Each box is one tensor, sized by how many numbers it holds. Click one (or use the arrow keys) to see all its numbers as colours: red positive, teal negative. Start with 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:

namewhat it doesin the last article
wteone row of 64 numbers per tokenembeddings
wpeone row per position in the nameembeddings
h.N.ln_1, ln_2layer norm: rescale, then stretch and shiftthe block
h.N.attn.c_attnqueries, keys and values, fusedattention
h.N.attn.c_projmixes the heads back togetherattention
h.N.mlp.c_fc, c_projwiden to 256, bend, squeeze back to 64the block
ln_f, lm_headfinal norm, then one score per tokensoftmax 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.

Demo 5 · Same bytes, different program

Pick a different number of heads, or run fewer layers, or swap their order. Every tensor still fits, so nothing crashes. Does it still make frogs? loss is the average surprise on 400 real names it never trained on (lower is better); style match is how often a simple letter-pattern check guesses the type you asked for.
∑ 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.

Demo 6 · Brain surgery
Cut anything, and cuts add up. Which layer's MLP can it not live without? Which heads can it lose with barely a scratch? And what does swap 🐸 ↔ 🐍 rows do when you then ask for a 🐸?
▦ 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.

Demo 7 · Fewer bits per number
block of
every format

measuring…

held-out loss (lower is better) and the size of the numbers

Step from f32 down to int2 (or use the arrow keys). The top line is 32 real weights; the bottom line is where each one lands after rounding to the grid. Where do the names start to break?
∑ 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.

Demo 8 · The X-ray

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.

next to it
Hover a box for its name, shape and size, and click to select it. Start with GPT-2 small next to the frog-namer: same names, same shapes, just bigger. Then try a Llama, and the mixture-of-experts Qwen. The URL updates, so you can share what you're looking at.
▦ 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:

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.

Demo 9 · Size and speed
Pick a machine, or type your own numbers, and a number format. "Fits" leaves a quarter of the memory for everything else. The speed is an upper limit: bandwidth figures are spec-sheet peaks, and real programs get maybe half to four fifths of it. The highlighted row is the model in the X-ray.
∑ 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

thingwhat it means
modelprogram (architecture) + weights (numbers) + a loop that runs them
.safetensors8-byte length, JSON header (names, dtypes, shapes, offsets), raw numbers
.ggufllama.cpp's format: header with metadata, tokenizer and tensor list, then numbers
tensora named grid of numbers with a shape; params = the shape multiplied out
f32 / f16 / bf16sign + exponent + fraction in 32 / 16 / 16 bits; bf16 keeps f32's range
block quantizationper 32 weights: one scale \(s\), integers \(q = \text{round}(w/s)\), weight \(\approx q s\)
sizeparams × bits per weight ÷ 8
speed limittokens/s ≤ memory bandwidth ÷ bytes read per token
bufferstored 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.