GPT-2 124M (bf16), Muon + rotary + QK-norm, trained with llm.mojo
A GPT-2 124M-class model (12 layers, 12 heads, 768 channels) trained from scratch on the FineWeb classic 10B-token sample with llm.mojo, using the recipe from its modded-nanogpt adoption campaign. It is a training-run artifact and reproducibility reference, not a capable language model.
This is not a stock GPT-2. It uses rotary position embeddings and QK-norm, so a stock GPT-2 loader computes a different model from these weights. The weights are provided in two formats, and both require the llm.mojo code to run correctly:
model.safetensorswithconfig.json(model_type: llm_mojo_gpt2), the weights in Hugging Face tensor names;model_5700.bin, llm.mojo's raw checkpoint, plusstate_5700_0.bin(optimizer and trainer state, for resuming).
Results
Validation is FineWeb val, 320 batches (10,485,760 tokens).
| tokens | val loss | |
|---|---|---|
| First eval at or below 3.28 (step 5600) | 2.94B | 3.2795 |
| This checkpoint (step 5700) | 2.99B | 3.2704 |
AdamW, gpt2-124m-fineweb-mojo model.safetensors (7 GPUs, 458,752 tokens/step) | 10.25B | 3.2784 |
AdamW, same repo, llm_mojo_raw_checkpoint/model_19552.bin (524,288 tokens/step) | 10.25B | 3.2900 |
The 3.2704 above is the training run's logged value (3.2703533, pre-fusion kernels). Re-measured on the current fused rotary/QK-norm kernels over the same full 320-batch val, both formats (model_5700.bin and model.safetensors) score 3.2703578; the difference from the logged value is floating-point rounding between the two kernel generations.
This recipe passes the better AdamW checkpoint's 3.2784 between steps 5600 and 5700 (by 2.99B tokens, about 3.4x fewer than that run's total), and the other's 3.2900 at step 5500 (2.88B tokens, 3.2892). The AdamW runs' own crossing points on this val set were not measured.
Limits of this result:
- One seed. A three-seed confirmation exists only at 600 steps and 131k tokens/step.
- The figure belongs to this recipe and horizon together. The same recipe with a 3800-step horizon ended at 3.3249 after 1.99B tokens. Other horizons were not tried.
- This run resumed from step 2000 of that 3800-step run, where the two schedules are identical. Its discarded steps 2001-3800 are not counted in the tokens above.
- HellaSwag was not evaluated on this checkpoint.
Files
| file | contents | sha256 prefix |
|---|---|---|
model.safetensors | bf16, 147 tensors, HF GPT-2 names with Conv1D transposes; wte cut to 50257 rows; no transformer.wpe.weight (it is all zero and unused under rotary); tied lm_head not stored | 540566164813ec7c |
config.json | model_type: llm_mojo_gpt2, llm_mojo_arch_flags: 5, rotary, qk_norm, attn_scale, dropout 0.0 (llm.mojo has no dropout), the exact rotation in rotary_note | |
generation_config.json, tokenizer.json, tokenizer_config.json | the GPT-2 tokenizer files, as in the other llm.mojo repos | |
model_5700.bin | bf16 model weights, llm.mojo model file version 5, architecture flags = 5 (rotary + QK-norm); wpe is present but all zero | 394d3a6ae33f24e8 |
state_5700_0.bin | optimizer and trainer state, for resuming only; flags = 5 | e07337124a7218ef |
The .bin files were corrected
The first upload of model_5700.bin (sha256 prefix 9ab731c3073e9ef2) and state_5700_0.bin
(067a41fd93a0e966) recorded only the rotary flag (flags = 1) because the QK-norm bit did not exist when
they were written. The files here differ from those by that one flag byte in the header (byte 81 in the model
file and byte 177 in the state file, value 1 changed to 5) and nothing else. This repo's history was squashed on 2026-11-02 to remove
those earlier versions, so if you downloaded a file with one of those prefixes, replace it.
Why it matters: a rotary-only build (-D LLMM_ROTARY=1 without -D LLMM_QK_NORM=1) loads a flags = 1 file
without complaint and computes the wrong model (loss about 8.55 on the check batch instead of 3.29). With the
corrected files such a build refuses to load them, and so does a build with neither flag. If you downloaded the
first versions, re-download, or write a corrected copy with scripts/set_checkpoint_arch_flags.py in llm.mojo.
Loading
Use llm.mojo. AutoConfig, AutoModelForCausalLM and pipeline refuse this checkpoint by design (they raise
"does not recognize this architecture" for llm_mojo_gpt2), instead of loading it as GPT-2. An explicit
GPT2LMHeadModel.from_pretrained(dir) still loads it, with a model-type warning and a load report that
transformer.wpe.weight is MISSING (a randomly initialised position table), and it computes the wrong model:
a stock GPT-2 has neither rotary nor QK-norm.
Generate
Requires pixi and an NVIDIA GPU; these commands were run on one NVIDIA GB10 only.
Needs gpt2_tokenizer.bin in the directory you run from (make gpt2_tokenizer.bin fetches it). Download the
files from this repo into a directory (below, hf/).
git clone https://github.com/ulmentflam/llm.mojo && cd llm.mojo
make gpt2_tokenizer.bin
make build-infer-bf16 INFER_BIN_BF16=build/infer_gpt2_bf16_recipe MOJO_DEFINES="-D LLMM_ROTARY=1 -D LLMM_QK_NORM=1"
# raw checkpoint
pixi run -e cuda ./build/infer_gpt2_bf16_recipe hf/model_5700.bin 48 1337
# safetensors (reads hf/config.json next to it)
pixi run -e cuda ./build/infer_gpt2_bf16_recipe hf/model.safetensors 48 1337
Both commands print the same text for the same seed. Both flags are required: the loader checks
llm_mojo_arch_flags (safetensors) or the header flags (.bin) and refuses a build that lacks either one.
infer_gpt2 --hf ulmentflam/gpt2-124m-fineweb-muon-rotary-qknorm-mojo 24 1337 fetches this repo directly; tested on the same build.
To score a batch of FineWeb val: ./build/infer_gpt2_bf16_recipe --loss hf/model_5700.bin <val shard> 4 1024
(both formats print loss= 3.2883191 on the first 4 x 1024 tokens of fineweb_val_000000.bin).
These commands were tested with the fused rotary/QK-norm kernels on llm.mojo main plus the export changes. The
model was trained with the earlier unfused kernels at commit 21a2e4c, and the two differ only by
floating-point rounding. The safetensors file passes scripts/check_hf_export.py (every tensor bit-identical
to the .bin, an independent PyTorch forward at 3.2880 on the same batch).
Training recipe
GPT-2 124M, bf16, 524,288 tokens per step (-b 32 -t 1024 -d 524288), one NVIDIA GB10:
-D LLMM_ROTARY=1 -D LLMM_QK_NORM=1
-opt muon -l 4.8e-3 -c 0.1 -gc 1.0 -x 5700 -v 100 -m 320 -qk_clip 0
-k wsd -u 0 -cooldown 0.4 -decay_shape linear -q 0.1
-mu_start 0.85 -mu 0.95 -mu_warmup 300
Full report, figures and logs:
docs/ai/modded_nanogpt_adoption_results_2026-10-30.md.
License
Weights are released under ODC-BY, matching the other llm.mojo FineWeb checkpoints. The llm.mojo code is MIT.
Written with AI assistance (Claude Code, Opus 5.5 agent), directed by Evan Owen.