Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Configuring a run (CLI and TOML)

Any train invocation can be shortened with --configuration-file <path.toml>. Values resolve with the precedence CLI flag > TOML key > default: an explicit flag always wins, an absent flag takes the TOML value, and an absent key takes the built-in default.

cargo run --release -p typed-lm-trainer -- train \
  --configuration-file training.toml

Sections

The file is organized in five sections that mirror the runtime concerns:

SectionPurpose
[run]Training method, hyper-parameters and execution settings
[model]Architecture geometry (needed by from-scratch/full)
[initialization]Weight initializers for from-scratch
[dataset]Dataset location
[tokenizer]Tokenizer artifact
---
accTitle: Configuration resolution
accDescr: Each parameter resolves from the CLI flag first, then the TOML key, then the built-in default.
---
flowchart LR
  flag["CLI flag"]:::primary
  toml["TOML key"]:::accent
  default["built-in default"]:::neutral
  value["effective value"]:::success

  flag -- "present" --> value
  flag -- "absent" --> toml
  toml -- "present" --> value
  toml -- "absent" --> default --> value

  classDef primary fill:#ede9fe,stroke:#7c3aed,color:#3b0764,stroke-width:1.5px
  classDef accent fill:#dbeafe,stroke:#2563eb,color:#0c4a6e,stroke-width:1.5px
  classDef success fill:#d1fae5,stroke:#059669,color:#064e3b,stroke-width:1.5px
  classDef neutral fill:#f4f4f5,stroke:#a1a1aa,color:#18181b,stroke-width:1.5px

Full example

[run]
method = "from-scratch"
seed = 42
output_directory = "output/scratch"
model_id = "Qwen/Qwen2.5-1.5B-Instruct"
quantization = "none"
quantization_mode = "post-training"
device = "auto"
maximum_gradient_norm = 1.0
minimum_improvement = 0.0
early_stop_patience = 0
max_sequence_length = 1024
warmup_steps = 10
weight_decay = 0.0
learning_rate = 1e-4
batch_size = 4
gradient_accumulation_steps = 1
epochs = 3
lora_rank = 16
lora_alpha = 32.0
lora_dropout = 0.0

[model]
architecture = "qwen3"
vocab_size = 151936
hidden_size = 1024
intermediate_size = 4096
num_hidden_layers = 16
num_attention_heads = 16
num_key_value_heads = 4
max_position_embeddings = 4096
rope_theta = 1000000.0
rms_norm_eps = 1e-6
tie_word_embeddings = true

[initialization]
initializer_range = 0.02
embedding_std = 0.02
norm_weight = 1.0
bias_value = 0.0

[dataset]
path = "resources/dataset.jsonl"

[tokenizer]
file = "tokenizer.json"

[run]

TOML keyTypeCLI flagDefault
methodstring--methodlora
seedinteger--seed42
output_directorystring--output-directoryoutput/train
model_idstring--model-idQwen/Qwen2.5-1.5B-Instruct
quantizationstring--quantizationnone
quantization_modestring--quantization-modepost-training
devicestring--deviceauto
maximum_gradient_normfloat--maximum-gradient-norm1.0
minimum_improvementfloat--minimum-improvement0.0
early_stop_patienceinteger--early-stop-patience0
max_sequence_lengthinteger--max-sequence-length1024
warmup_stepsinteger--warmup-steps10
weight_decayfloat--weight-decay0.0
learning_ratefloat--learning-rate1e-4
batch_sizeinteger--batch-size4
gradient_accumulation_stepsinteger--gradient-accumulation-steps1
epochsinteger--epochs3
lora_rankinteger--lora-rank16
lora_alphafloat--lora-alpha32.0
lora_dropoutfloat--lora-dropout0.0

The device value accepts auto, cpu or cuda and mirrors the CLI choices.

[model]

Explicit architecture geometry, used by --method full/from-scratch when the shape must not come from a checkpoint config.json. Each key maps to the same-named CLI flag.

TOML keyTypeCLI flag
architecturestring--architecture
vocab_sizeinteger--vocab-size
hidden_sizeinteger--hidden-size
intermediate_sizeinteger--intermediate-size
num_hidden_layersinteger--num-hidden-layers
num_attention_headsinteger--num-attention-heads
head_diminteger--head-dim
num_key_value_headsinteger--num-key-value-heads
max_position_embeddingsinteger--max-position-embeddings
rope_thetafloat--rope-theta
rms_norm_epsfloat--rms-norm-eps
tie_word_embeddingsboolean--tie-word-embeddings
attention_biasboolean--attention-bias
sliding_windowinteger--sliding-window
sliding_window_patterninteger--sliding-window-pattern
rope_local_base_frequencyfloat--rope-local-base-frequency
query_pre_attention_scalarinteger--query-pre-attention-scalar
logit_softcappingfloat--logit-softcapping
attention_logit_softcappingfloat--attention-logit-softcapping

Any key left absent falls back to the family default: head_dim derives from hidden_size / num_attention_heads, Gemma2/Gemma3 fill query_pre_attn_scalar, the logit soft-caps, the Gemma3 local RoPE base frequency and its sliding-window pattern automatically. This guarantees the emitted config.json can be served back for every dense family.

[initialization]

Weight initializers for --method from-scratch. These keys have no CLI flag; they are applied over the built-in defaults. Absent keys keep their default.

TOML keyTypeDefaultMeaning
initializer_rangefloat0.02Standard deviation of attention and MLP projection weights
embedding_stdfloat0.02Standard deviation of the token-embedding (and untied head) weights
norm_weightfloat1.0Constant written to every RMSNorm weight
bias_valuefloat0.0Constant written to every attention-projection bias

[dataset]

TOML keyTypeCLI flagDefault
pathstring--dataset— (required: CLI or TOML)

[tokenizer]

TOML keyTypeCLI flagDefault
filestring--tokenizer-file— (required by from-scratch)

Precedence

Each parameter resolves with the rule CLI flag > TOML key > default. Worked example, using epochs (default 3) and this file:

[run]
epochs = 9
InvocationResultRule
train --dataset data.jsonl --epochs 2 --configuration-file training.tomlepochs = 2flag set → wins
train --dataset data.jsonl --configuration-file training.tomlepochs = 9flag absent + TOML present → TOML
train --dataset data.jsonlepochs = 3both absent → default

The rule is applied per key, not per section: in one file some keys can come from the CLI and others from the TOML at the same time.

Errors

Unknown keys and wrong types are rejected rather than silently ignored. Both surface as a typed configuration-file error naming the file and the offending key, for example:

configuration file error in 'training.toml': unknown field `epocs`, expected one of ...
configuration file error in 'training.toml': invalid type: string "three", expected usize ...

A missing file is reported as an I/O error carrying the path.

Next steps