LLM Developer DocsLLM Docs

Loading the search index ...

↑ ↓ move, Enter open, Esc close

GitHub

LLM Developer Docs

This is a small language model built from scratch. This documentation shows the mathematics behind it, the code that implements the mathematics, and how the pieces work together.

The model at a glance

Read from config.py at the pinned commit.

SettingName in config.pyValue
Model
Layersnum_layers2
Headsnum_heads2
Widthemb_dim32
Head width No module reads this constant.head_dim16
FFN widthff_dim128
Window lengthseq_len16
Context lengthcontext_len32
Tokenizer
BPE mergesnum_merges500
Optimizer
Largest learning ratelr_max1e-3
Smallest learning ratelr_min1e-4
Warmup stepswarmup_steps50
Beta 1beta10.9
Beta 2beta20.999
Adam epsilonadam_eps1e-8
Weight decayweight_decay0.01
Gradient clipgrad_clip1.0
Sampling defaults
Temperaturetemperature0.8
Top-k 0 turns it off.top_k0
Top-ptop_p0.9
New tokens in talk.pymax_new_tokens50

The pipeline

Every step the code runs, from text to generated tokens. Shapes are for one sequence: the model has no batch dimension.

Text to training windows
Embeddings
Blocks, repeated num_layers = 2 times transformer.py:162
Output
  1. 14. Logits(T, V)(16, V)transformer.py:168
Loss and update
Generation
  1. 19. Generation(V,)Samples from the last row of logits.generate.py:33
Plain names have no page yet. The link under each name opens the real lines at the pinned commit.

Questions this site answers

Labels used on this site

Illustrative Example
Hand-picked numbers. These are not learned values.
Actual Model Output
Numbers produced by running the repository, with their source stated.
Derived from implementation
Mathematics the code implements but the reference PDF does not state.