train_gpt.py is driven by environment variables. This page is a consolidated reference organized by subsystem.
Quick-Start Example
Training Hyperparameters
All variables in this section are read by theHyperparameters class at process startup. Unset variables fall back to the listed defaults.
Data Paths
string
default:"./data/datasets/fineweb10B_sp1024"
Root directory for tokenized dataset shards. Train and val glob patterns (
fineweb_train_*.bin and fineweb_val_*.bin) are derived from this path.string
default:"./data/tokenizers/fineweb_1024_bpe.model"
Path to the SentencePiece
.model file. Used to build look-up tables for the tokenizer-agnostic BPB metric. Must match VOCAB_SIZE exactly or training raises an error.string
default:"random UUID"
Human-readable identifier for this run. Determines the log filename at
logs/<RUN_ID>.txt.integer
default:"1337"
Global random seed applied to Python, NumPy, and PyTorch (including
cuda.manual_seed_all) before training.Validation
integer
default:"524288"
Total token budget across all ranks per validation pass. Must provide at least one full
TRAIN_SEQ_LEN-length sequence per rank.integer
default:"1000"
Run validation every N training steps. Set to
0 to disable periodic validation (final evaluation still runs at the end).integer
default:"200"
Log a
train_loss line every N steps. Steps 1–10 are always logged regardless of this setting.Training Length
integer
default:"20000"
Maximum number of gradient update steps before training stops. The wallclock cap may cause an earlier stop.
integer
default:"1200"
Number of steps (or equivalent wallclock duration) over which the learning rate linearly decays to zero at training end.
integer
default:"20"
Number of pre-training “warmup” steps that prime compiled kernels. Model and optimizer state are fully reset after warmup completes, so effective training always starts from the true initialization.
integer
default:"524288"
Total tokens consumed per gradient update across all ranks. Gradient accumulation steps =
8 // WORLD_SIZE.integer
default:"1024"
Sequence length for both training and validation. Affects memory usage and the minimum
VAL_BATCH_SIZE.float
default:"600.0"
Hard cap on training time in seconds. When elapsed training time reaches this limit, training stops after the current step finishes. Set to
0 to disable the cap.float
default:"1.5"
Initial value for the per-head learnable
q_gain parameter in each attention block. Scales query vectors before the dot product.Model Shape
integer
default:"1024"
Vocabulary size. Must exactly match the SentencePiece tokenizer’s vocab size.
integer
default:"9"
Total number of transformer blocks. Split evenly into encoder and decoder halves for U-Net-style skip connections.
integer
default:"4"
Number of key/value heads for Grouped Query Attention (GQA). Must evenly divide
NUM_HEADS.integer
default:"512"
Hidden/embedding dimension. Must be divisible by
NUM_HEADS, and MODEL_DIM // NUM_HEADS must be even (required for RoPE).integer
default:"8"
Number of query attention heads.
integer
default:"2"
MLP hidden-layer multiplier. The feedforward hidden size is
MLP_MULT * MODEL_DIM.integer
default:"1"
Set to
1 to tie input embedding and output projection weights (saves parameters). Set to 0 for a separate lm_head.float
default:"10000.0"
Base frequency for Rotary Position Embeddings.
float
default:"30.0"
Logit soft-cap. Applied as
softcap * tanh(logits / softcap) before cross-entropy. Must be positive.Optimizer
float
default:"0.6"
Adam learning rate for the token embedding when
TIE_EMBEDDINGS=0.float
default:"0.008"
Adam learning rate for the untied
lm_head when TIE_EMBEDDINGS=0.float
default:"0.05"
Adam learning rate for the token embedding when
TIE_EMBEDDINGS=1.float
default:"0.005"
Standard deviation for normal initialization of the tied embedding weight.
float
default:"0.04"
Muon learning rate for 2D matrix parameters in transformer blocks.
float
default:"0.04"
Adam learning rate for scalar and vector parameters (scales, norms, gains) in transformer blocks.
float
default:"0.95"
Steady-state momentum for the Muon optimizer.
integer
default:"5"
Number of Newton-Schulz iterations used to orthogonalize gradient matrices in Muon.
float
default:"0.85"
Starting Muon momentum value at step 0, linearly warmed up to
MUON_MOMENTUM over MUON_MOMENTUM_WARMUP_STEPS steps.integer
default:"500"
Steps over which Muon momentum is linearly warmed from
MUON_MOMENTUM_WARMUP_START to MUON_MOMENTUM.float
default:"0.9"
Adam β₁ (first-moment decay). Applies to all Adam optimizer groups.
float
default:"0.95"
Adam β₂ (second-moment decay). Applies to all Adam optimizer groups.
float
default:"1e-8"
Adam numerical stability epsilon. Applies to all Adam optimizer groups.
float
default:"0.0"
Global gradient norm clip threshold. Set to
0.0 to disable gradient clipping.Quantization
These variables control which tensors are kept in floating-point during int8 post-training quantization.string
Comma-separated list of name substrings. Any parameter whose name contains one of these patterns is treated as a “control tensor” — kept in fp32 during training and excluded from int8 quantization. These are typically low-dimensional scalar/vector parameters that are sensitive to precision loss.
string
default:"same as CONTROL_TENSOR_NAME_PATTERNS"
Comma-separated list of name substrings. Tensors matching these patterns are kept in full fp32 in the quantized artifact rather than being downcast to fp16. Defaults to the same value as
CONTROL_TENSOR_NAME_PATTERNS.Tensors with 65,536 elements or fewer are always kept as floating-point (stored as fp16) rather than quantized to int8, regardless of these patterns. Large 2D float tensors use per-row int8 quantization; other large float tensors use per-tensor int8 quantization.
Distributed Training
These variables are set automatically bytorchrun. You do not need to set them manually.
integer
Global rank of the current process across all nodes. Process 0 is the master process that writes logs and saves checkpoints.
integer
Total number of processes in the distributed job. Must divide 8 so that gradient accumulation steps (
8 // WORLD_SIZE) remain an integer. Valid values: 1, 2, 4, 8.integer
Rank of the current process on its local node. Used to select the CUDA device (
cuda:<LOCAL_RANK>).Data Pipeline
These variables configure the dataset download and tokenization scripts indata/.
string
default:"willdepueoai/parameter-golf"
Hugging Face dataset repository ID to download shards and tokenizers from.
string
default:"datasets"
Subdirectory prefix within the HF repo under which dataset shards and manifest are stored.
integer
Batch size for SentencePiece tokenizer encoding during shard export. Useful for tuning CPU-heavy export throughput.
integer
Number of threads for the tokenizer encoding pool during shard export.
integer
Number of threads for tiktoken encoding during shard export (used when tokenizing with the tiktoken backend).
integer
Batch size for GPT-2 decoding during the blobstore docs-cache path. Useful for tuning memory vs. throughput tradeoff.
MLX-Only Variables
These variables are specific totrain_gpt_mlx.py and have no effect on train_gpt.py.
integer
default:"8192"
Maximum tokens per sub-batch within each logical microbatch. MLX splits each microbatch into smaller chunks of at most this size to reduce peak memory pressure on Apple Silicon without changing the effective optimizer batch size.
integer
default:"8"
Number of gradient accumulation steps per optimizer update in
train_gpt_mlx.py. In train_gpt.py this is always derived as 8 // WORLD_SIZE and is not independently configurable.string
default:"logs"
Output directory for log files and model artifacts in
train_gpt_mlx.py. In train_gpt.py the log directory is always logs/ and is not configurable.integer
default:"0"
Number of tokens per logit computation chunk in
train_gpt_mlx.py. Set to a positive value to reduce peak memory by computing the final projection and cross-entropy loss in chunks. 0 (default) computes all tokens in a single matmul.