LLM Developer DocsLLM Docs

Loading the search index ...

↑ ↓ move, Enter open, Esc close

GitHub

config.py

Hyperparameters as module-level constants, plus two import-time assertions

Where it fits

Imports and used by

Imports from this repository
None
Other imports
None
Imported by
talk.py, train.py
Used by, in the pipeline
No calls, because this file defines only constants. talk.py, train.py read them.
Used by, in tests
No file

Mathematics used

ConceptWhat this file doesLinesStatus
HeadsWrites it in place44Implemented

Functions and constants

This file defines no functions.

ConstantLinesRead by
context_len = 32 # suppose 5 tokens then theres 5x32 rows, the model can look 32 texts at once2train.py:48
emb_dim = 32 # size of the vector that flows through the entire model with same width at each layer3train.py:48
num_heads = 2 # emb_dim must be divisible by this, model splits each vector into 2 halves of 16 numbers and runs attention separately4train.py:49
ff_dim = 128 # in the feed forward step, vector is stretched from 32 to 128 temporarily to allow model compute richer things5train.py:49
num_layers = 2 # number of layers of the LLM6train.py:49
seq_len = 16 # each training example is a 16 rows table, we cut the input corpus into pieces of 16 tokens7talk.py:24, train.py:44, train.py:45, train.py:73
ln_eps = 1e-5 # tiny number added inside layer norm so we never divide by zero8Nothing
corpus_path = "data/corpus.csv" # file the text is read from11train.py:40
corpus_column = "text" # which column of the csv holds the text12train.py:40
max_rows = 2000 # only read this many rows, keeps training fast13train.py:40
num_merges = 500 # how many times BPE glues the most common pair into a new token, more merges = bigger vocab14train.py:41
val_fraction = 0.1 # last 10% of the token stream is kept aside to test the model on text it never trained on15train.py:43
stride = 1 # how far the window slides each time, 1 = every possible window (neighbours overlap by 15 tokens)16train.py:44, train.py:45
batch_size = 16 # how many windows we average the gradient over before one update19train.py:54, train.py:60
epochs = 20 # how many full passes over the training windows20train.py:55, train.py:59
grad_clip = 1.0 # if the whole gradient is longer than this, shrink it to this length so one bad batch cant blow up the model21train.py:62
lr_max = 1e-3 # biggest learning rate, reached right after warmup24train.py:65
lr_min = 1e-4 # smallest learning rate, where the cosine decay ends25train.py:65
warmup_steps = 50 # number of steps spent ramping the learning rate up from near 0, a fresh model is fragile26train.py:64
beta1 = 0.9 # how much of the old gradient direction Adam keeps (momentum)27train.py:51
beta2 = 0.999 # how much of the old squared gradient Adam keeps (typical gradient size)28train.py:51
adam_eps = 1e-8 # tiny number so Adam never divides by zero29train.py:51
weight_decay = 0.01 # each step shrinks the weight matrices slightly, only matrices, not biases or layer norm30train.py:51
temperature = 0.8 # below 1 = safer and more repetitive, above 1 = more random, 0 = always pick the top token33talk.py:25, train.py:74
top_k = 0 # only sample from the k most likely tokens, 0 = turned off34talk.py:25, train.py:74
top_p = 0.9 # only sample from the smallest group of tokens whose probabilities add up to 0.935talk.py:25, train.py:74
max_new_tokens = 50 # how many tokens talk.py writes after your prompt36talk.py:24
seed = 42 # fixes the random numbers so a run can be repeated exactly39talk.py:9, train.py:37
head_dim = emb_dim // num_heads # width of one head, 32 / 2 = 1644Nothing

Source

config.py44 linesGitHub: config.py
# ---------- model shape ----------context_len = 32 # suppose 5 tokens then theres 5x32 rows, the model can look 32 texts at onceemb_dim     = 32 # size of the vector that flows through the entire model with same width at each layernum_heads   = 2 # emb_dim must be divisible by this, model splits each vector into 2 halves of 16 numbers and runs attention separatelyff_dim      = 128 # in the feed forward step, vector is stretched from 32 to 128 temporarily to allow model compute richer thingsnum_layers  = 2 # number of layers of the LLMseq_len     = 16 # each training example is a 16 rows table, we cut the input corpus into pieces of 16 tokensln_eps      = 1e-5 # tiny number added inside layer norm so we never divide by zero# ---------- data ----------corpus_path   = "data/corpus.csv" # file the text is read fromcorpus_column = "text" # which column of the csv holds the textmax_rows      = 2000 # only read this many rows, keeps training fastnum_merges    = 500 # how many times BPE glues the most common pair into a new token, more merges = bigger vocabval_fraction  = 0.1 # last 10% of the token stream is kept aside to test the model on text it never trained onstride        = 1 # how far the window slides each time, 1 = every possible window (neighbours overlap by 15 tokens)# ---------- training ----------batch_size   = 16 # how many windows we average the gradient over before one updateepochs       = 20 # how many full passes over the training windowsgrad_clip    = 1.0 # if the whole gradient is longer than this, shrink it to this length so one bad batch cant blow up the model# ---------- optimizer (AdamW) ----------lr_max       = 1e-3 # biggest learning rate, reached right after warmuplr_min       = 1e-4 # smallest learning rate, where the cosine decay endswarmup_steps = 50 # number of steps spent ramping the learning rate up from near 0, a fresh model is fragilebeta1        = 0.9 # how much of the old gradient direction Adam keeps (momentum)beta2        = 0.999 # how much of the old squared gradient Adam keeps (typical gradient size)adam_eps     = 1e-8 # tiny number so Adam never divides by zeroweight_decay = 0.01 # each step shrinks the weight matrices slightly, only matrices, not biases or layer norm# ---------- generation ----------temperature    = 0.8 # below 1 = safer and more repetitive, above 1 = more random, 0 = always pick the top tokentop_k          = 0 # only sample from the k most likely tokens, 0 = turned offtop_p          = 0.9 # only sample from the smallest group of tokens whose probabilities add up to 0.9max_new_tokens = 50 # how many tokens talk.py writes after your prompt# ---------- misc ----------seed = 42 # fixes the random numbers so a run can be repeated exactly# ---------- sanity checks ----------assert emb_dim % num_heads == 0, "emb_dim must be divisible by num_heads"assert seq_len <= context_len, "a training window cannot be longer than the position table"head_dim = emb_dim // num_heads # width of one head, 32 / 2 = 16