103. Model Weights 2 - Tensors, Layers and Checkpoints

See how weights are organised into tensors and layers, and how that organisation becomes a file you load.

By Jacques Botte, founder of Toptronic®. Last updated 17 October 2026.

The lesson

Weights are not a flat list; they are tensors with shapes. A linear layer holds a matrix that maps an input vector of one width to an output of another, so its shape is output width by input width. Attention holds separate projection matrices for queries, keys and values. Embeddings hold one vector per vocabulary entry. Reading a model's shape list is the fastest way to understand where its memory actually goes.

The embedding table is often the surprise. A 100,000-token vocabulary at 4,096 dimensions is about 410 million weights before anything else, and some models tie the output projection to it. Attention projections across dozens of layers add up quickly too. Feed-forward layers usually hold the majority of the parameters, which is why mixture-of-experts designs can have enormous totals while activating only a fraction per token.

A checkpoint is a directory or a file holding those tensors plus a config that describes the architecture and a tokenizer. Formats differ mainly in how tensors are laid out and named: safetensors stores a header of shapes and offsets followed by raw data, which allows memory-mapping so the operating system loads only the pages actually used. That is why a 40 GB model can start on a machine with less free RAM than its file size, and then fail later when it touches everything.

Quantized checkpoints are the same structure with different dtypes, plus scale tensors alongside. A 4-bit file still contains a tensor per layer; the values are packed, and the loader unpacks or the kernel reads them packed. This is why you cannot simply rename a Q4 file to Q8 or edit one in place: the layout and the metadata both encode the precision.

Practically, the shape view answers real questions. If a model supports a longer context, look for the position-encoding configuration. If it runs out of memory during generation rather than load, suspect the KV cache and its per-layer shapes. And if two checkpoints claim the same parameter count but different file sizes, the difference is precision, not architecture: compare the config's dtype fields before believing either label.

Check yourself

Question 1: What is stored in an embedding tensor?
  1. One number per layer
  2. One vector per vocabulary entry — correct
  3. The tokenizer's merge rules
  4. The attention mask

Answer: One vector per vocabulary entry

The embedding table maps each vocabulary entry to a vector; its size is vocabulary by hidden dimension.

Question 2: Why can a large safetensors model start on a machine with less free RAM than the file size?
  1. Because it is compressed
  2. Because it is memory-mapped and only the pages actually used are loaded — correct
  3. Because the tokenizer is stored separately
  4. Because the GPU holds it

Answer: Because it is memory-mapped and only the pages actually used are loaded

Memory-mapping defers loading; the failure comes later, when the whole file is touched.

Question 3: Two checkpoints claim the same parameter count but have different file sizes. What differs?
  1. The architecture
  2. The precision the weights are stored at — correct
  3. The licence
  4. The vocabulary

Answer: The precision the weights are stored at

Same parameters, fewer bytes each: the dtype is the difference.

← Previous lesson · All 106 lessons · Next lesson →

The full course — 106 lessons and 318 quiz questions — ships inside the app. Get TPEE to study it offline.