CorX Labs

Build notes

Training small AI models on four CPU cores.

Bantam is a toolkit for training and fine-tuning small language and weather models in plain PyTorch, and every number behind it came from a 4-core CPU. This is what saved compute, what did not, what an earlier version got wrong, and what is still unknown.


The short version

Bantam is a small toolkit for training and fine-tuning small language and weather models in plain PyTorch, made in Jamaica by CorX Labs. It is on PyPI as bantamtrain under the MIT licence, and since version 0.4 it also compresses larger models to 2, 3 or 4 bits per weight. Every number in this post came from one CPU sandbox: 4 cores and 16 GB of RAM. Nothing has run on a GPU yet.

The best pretraining recipe needs about 29% less compute than a plain baseline for the same loss, at one small size and with 2 seeds. A fine-tuning race against Hugging Face matched its loss 1.36 times faster with 38% less memory. And the model Bantam trains is still behind every published TinyStories model.

Why a CPU

Renting a GPU is the expensive step, so Bantam is built for the step before it: testing training ideas at small scale, seeing how training works, and estimating with bantam memory whether a bigger run fits a card before paying for one.

The core needs only PyTorch, NumPy and zstandard, and one command, bantam, covers the path: prepare a dataset, pretrain a small GPT at a fixed compute budget, fine-tune a Hugging Face model with LoRA, QLoRA or DoRA, train a small weather forecaster, and talk to the result. It does not replace the GPU tools. Unsloth, Axolotl, TRL with PEFT and LLaMA-Factory have fused kernels, multi-GPU training and RL; Bantam has none of those.

How every number was measured

  • Same compute for every arm. Language-model runs get a fixed budget of 6.8e13 model FLOPs, weather runs 5.5e13. A recipe wins only if it reaches a lower held-out loss on the same budget.
  • Compute to match. How much more compute the plain baseline needs to reach a recipe’s loss, read off baseline runs at 1, 1.25, 1.5 and 2 times the budget.
  • Seeds are counted. Headline results have 2 or 3 seeds; most ablations have 1.
  • One known gap. Muon’s own optimizer FLOPs, about 20% of the model FLOPs at this size, are not charged to the budget.

What saved compute

The test model is a 5.8M-parameter GPT on TinyStories, about 117M training tokens. Switching the optimizer from AdamW to Muon was the biggest single win: validation loss 2.737 against 3.332 at the same budget. That comparison changes two things at once, because in Muon runs the parameters left on AdamW also get a 16 times higher learning rate, and the AdamW side is one seed.

Validation loss at equal compute and the compute the Muon baseline needs to match, by recipe
RecipeLossBaseline compute to matchSeeds
Muon baseline2.7371.00×3
Zoom2.6851.12×3
QK-norm2.6391.24×2
QK-norm and Zoom2.5891.41×2

Zoom merges each pair of neighbouring tokens into one position for the first part of training. It is a variant of patch-level training, whose authors report about half the training cost at 370M to 2.7B parameters. At 5.8M parameters Bantam measured much less, 1.12 times, and QK-norm, a known trick, beat it. The two stack: together they need about 29% less compute for that loss. Version 0.4 adds progressive depth growth, and on top of that recipe the baseline needs 1.55 times the compute to match, at a loss of 2.551.

Fine-tuning gained too. Against Hugging Face Trainer with PEFT, on SmolLM2-135M with the same optimizer and settings, Bantam reached the same held-out loss (2.259 against 2.260) in 9.7 minutes instead of 13.2, with 2.57 GB of peak memory instead of 4.17. Most of that is packing: several examples share one window, so no padding is computed. And 8-bit optimizer state with bf16 weights made the model’s training state 2.7 times smaller (50.4 MB to 18.5 MB) at a loss of 2.728, and it ran 1.6 times slower on this CPU.

What did not

  • Published models are ahead. On 1,000 held-out TinyStories stories, Bantam’s plain baseline scored 1.029 bits per byte. TinyStories-1M scores 0.822, with about 3,350 times more compute. Bantam beats llama2.c’s stories260K, a model with 22 times fewer parameters.
  • Zoom hurt the weather model. With Muon, merging grid cells early raised the 6-hour forecast error from 0.124 to 0.159. Training on a coarser grid first, a known method, lowered it to 0.112 in one run.
  • Several upgrades did not help at this size: a WSD schedule, ReLU², the Polar Express orthogonalizer and Zoom schedules with k=4. The first Zoom schedule lost on all 3 seeds.
  • Fewer steps cost loss. Packing also means fewer, larger optimizer steps: with 58 steps instead of 200, the fine-tuned model lost 0.056.
  • Three more misses. Muon on the LoRA matrices did not beat AdamW, 4-bit optimizer state with Muon gave a worse loss (2.785), and 8-bit saved activations made no difference.

What 0.3 had to correct

Version 0.2 had bugs that changed its results. Packed fine-tuning examples could see each other. LoRA runs reported as Muon runs were trained by 8-bit AdamW, because with a frozen base Muon had nothing to train. The comparison with published models scored them in the wrong text format, which favoured Bantam by about 25 to 37 nats per story; scored in each model’s own format, the gap widened. And an estimate that a 5B model trains 2.6 times faster on one GPU mixed gigabytes and gibibytes: it is about 1.9 times, and that comes from Muon’s published saving, not from a Bantam measurement. Version 0.3.0 fixed them, and its changelog lists each one.

Compressing models, new in 0.4

Version 0.4, out on 29 November, adds commands for models too big for the machine. bantam quantize compresses a Hugging Face model to 2, 3 or 4 bits per weight, one decoder block in memory at a time, and the result runs, is scored and fine-tunes like any model. At 4 bits, SmolLM2-135M’s WikiText-2 perplexity went from 20.49 to 22.04, against 25.43 with the 4-bit format of 0.3. At 2 bits these small models are unusable.

The largest model taken through the whole path has 1.3B parameters. bantam models lists 55 released models, among them DeepSeek and Kimi models, with what one GPU could hold. For those, the parameter counts, the weight-format readers and the loader’s mapping were checked on the real files; where they fit and how fast they would run is arithmetic. No large model has been compressed or run with Bantam.

What comes next

A GPU. The CUDA paths exist (bf16, torch.compile, multi-GPU through torchrun) and have only been tested with CPU stand-ins, so every speed and memory figure on a GPU is still unknown. The docs give the first run to make on a real card: bantam doctor, a short bantam pretrain with a small budget, and a comparison of its peak memory with what bantam memory predicted. When there are GPU numbers, they go on the Bantam page.

pip install 'bantamtrain[data]'
bantam doctor
bantam prepare-text --hf roneneldan/TinyStories --out data/tinystories --vocab 4096
bantam pack-text --data data/tinystories
bantam pretrain --data data/tinystories --budget 6.8e13 --recipe best \
    --name qk_zoom --out runs/tinystories --save runs/tinystories/qk_zoom.pt

FAQ

Can you train a language model on a CPU?

Yes, at small sizes. Bantam trained a 5.8M-parameter GPT on TinyStories on a 4-core CPU and fine-tuned the 135M-parameter SmolLM2 with LoRA. Its best recipe reached a validation loss of 2.589, where the plain baseline reached 2.737 at the same budget. The result is still behind every published TinyStories model, and nothing larger has been trained this way.

Is Bantam faster than Hugging Face for fine-tuning?

On a CPU, in one race on SmolLM2-135M, it matched Hugging Face Trainer with PEFT on held-out loss 1.36 times faster and with 38% less peak memory, mostly because packing computes no padding. It was one run per arm, and GPU tools with fused kernels were not in the race.

Has Bantam been tested on a GPU?

No. The CUDA code paths exist and have only been tested with CPU stand-ins, so its speed and memory on a GPU are unknown. Its figure for a 5B model on one GPU is arithmetic.

How do I try Bantam?

Run pip install bantamtrain, then bantam doctor to check your setup. The Bantam page has quickstarts for pretraining, fine-tuning, a weather model and compression, and bantam --help lists all 15 commands.

The toolkit

Every result, with its conditions and its limits.

Bantam, a toolkit for training small models on limited hardware, made in Jamaica and released under the MIT licence.