config.py
Hyperparameters as module-level constants, plus two import-time assertions
Where it fits
talk.pyreadsseq_len,temperature,top_k,top_p,max_new_tokens,seed.train.pyreadscontext_len,emb_dim,num_heads,ff_dim,num_layers,seq_len,corpus_path,corpus_column,max_rows,num_merges,val_fraction,stride,batch_size,epochs,grad_clip,lr_max,lr_min,warmup_steps,beta1,beta2,adam_eps,weight_decay,temperature,top_k,top_p,seed.
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.pyread them. - Used by, in tests
- No file
Mathematics used
Functions and constants
This file defines no functions.
Source
# ---------- 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