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

Choosing an architecture

The model geometry determines the checkpoint layout the trainer writes and the server reads. Most users never set it explicitly: lora, qlora and full read the geometry — and the tokenizer — from the base checkpoint’s config.json. Only from-scratch requires an explicit geometry, because there is no checkpoint to read it from.

When do I need to set geometry?

MethodGeometry source
lora / qloraBase checkpoint config.json
fullBase checkpoint config.json
from-scratchFlags or the TOML [model] section (required)

Supported families

The --architecture flag selects the family:

Family--architecture
Llamallama
Qwen2qwen2
Qwen3qwen3
Mistralmistral
Gemmagemma
Gemma2gemma2
Gemma3gemma3

Geometry fields

FlagDescription
--hidden-sizeHidden dimension
--intermediate-sizeFeed-forward intermediate dimension
--num-hidden-layersNumber of transformer blocks
--num-attention-headsNumber of query heads
--head-dimHead dimension (default: hidden_size / num_attention_heads)
--num-key-value-headsNumber of key/value heads (GQA)
--vocab-sizeVocabulary size
--max-position-embeddingsMaximum sequence length
--rope-thetaRotary embedding base frequency
--rms-norm-epsRMS normalization epsilon
--tie-word-embeddingsInput and output embeddings share weights
--attention-biasAttention projections carry a bias
--sliding-windowSliding-window size
--sliding-window-patternGemma3 global/local alternation
--rope-local-base-frequencyGemma3 local RoPE base frequency
--query-pre-attention-scalarGemma2/Gemma3 attention scaling denominator
--logit-softcappingGemma2/Gemma3 final_logit_softcapping
--attention-logit-softcappingGemma2/Gemma3 attn_logit_softcapping

Fields left unset take the family default — head_dim derivation, soft-caps, Gemma3 local RoPE and window, attention bias — so the emitted config.json is always serveable by typed-lm-serve.

---
accTitle: Geometry defaults per family
accDescr: Explicit geometry fields fall back to family defaults so the emitted config.json is always serveable.
---
flowchart TB
  family["--architecture"]:::accent
  explicit["explicit geometry flags<br/>or [model] section"]:::primary
  defaults["family defaults<br/>head_dim · soft-caps · local RoPE"]:::warning
  config["emitted config.json"]:::success
  serveable["serveable checkpoint"]:::success

  family --> explicit
  family --> defaults
  explicit --> config
  defaults --> config --> serveable

  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 warning fill:#fef3c7,stroke:#d97706,color:#78350f,stroke-width:1.5px

Choosing a geometry for from-scratch

There is no “right” size for a from-scratch model; pick the smallest geometry that exercises your dataset and pipeline. A small model trains quickly and still produces a serveable checkpoint.

cargo run --release -p typed-lm-trainer -- train \
  --method from-scratch \
  --architecture qwen2 \
  --vocab-size 151936 \
  --hidden-size 512 \
  --intermediate-size 2048 \
  --num-hidden-layers 8 \
  --num-attention-heads 8 \
  --num-key-value-heads 4 \
  --max-position-embeddings 1024 \
  --tokenizer-file /path/to/tokenizer.json \
  --dataset resources/dataset.jsonl \
  --output-directory output/scratch \
  --seed 42 \
  --epochs 3 --batch-size 4 --learning-rate 1e-4

See Training from scratch for the caveats about the resulting model.

Next steps