Bantam
Train and fine-tune small language models and small weather models on limited
compute, in plain PyTorch, and since version 0.4 compress larger models to 2, 3 or 4 bits per
weight. One command, bantam, covers the whole path, from preparing the data to
talking to the trained model.
Package: bantamtrain 0.4.0 · Python ≥ 3.10 · PyTorch ≥ 2.4 · Developer: Nathan · Origin: Jamaica
Bantam is a training toolkit built by CorX Labs in
Jamaica and published as the bantamtrain package. Its core needs only PyTorch,
NumPy and zstandard. With one command you can pretrain a small GPT on a Hugging Face text
dataset at a fixed compute budget, fine-tune a Hugging Face language model with LoRA, QLoRA or
DoRA and export a standard PEFT adapter, train a small 6-hour weather forecaster on ERA5, or
estimate the memory a run needs before you rent a GPU. Version 0.4 adds experimental
compression: a Hugging Face model goes to 2, 3 or 4 bits per weight, one block in memory at a
time, and the result runs, is scored and fine-tunes like any model.
It is meant for learning how training works, for testing training ideas at small scale, and for a CPU or one GPU. It does not replace Unsloth, Axolotl, TRL with PEFT or LLaMA-Factory on GPUs: Bantam has no fused GPU kernels, no multi-node training and no RL or DPO.
Every number on this page comes from one CPU: a sandbox with 4 cores and 16 GB of RAM, running PyTorch 2.15 for CPU. Nothing has been run on a GPU yet. The models are small (5.8M parameters for pretraining, 135M for fine-tuning, 1.26M for weather, and 135M to 1.3B for compression) and each result has 1 to 3 seeds. The limits are below.
- Package
bantamtrain0.4.0- Command
bantam, 15 subcommands- Core needs
- PyTorch, NumPy, zstandard
- Fine-tuning
- LoRA, QLoRA, DoRA
- Compression
- 2, 3 or 4 bits, experimental
- Adapter format
- PEFT
- Measured on
- 4-core CPU
- GPU runs
- None yet
- Licence
- MIT
1. What it does
Fifteen commands, one for each step. python -m bantamtrain works the same way as
bantam.
- Prepare and pack text.
prepare-textreads a Hugging Face dataset or local parquet files, trains a BPE tokenizer or reuses one, and writes token files.pack-textremoves duplicate documents and stores the tokens 2.68 times smaller than 16-bit ids, with nothing lost. - Pretrain.
pretraintrains a small GPT at a fixed compute budget, and--recipe bestsets the best settings measured so far.generatesamples from the result. - Fine-tune.
finetunetrains LoRA, QLoRA (a 4-bit NF4 base in pure PyTorch, no bitsandbytes) or DoRA on a Hugging Face causal language model, with examples packed into windows that keep them apart.chattalks to the result. - Forecast weather.
prepare-era5downloads ERA5 from WeatherBench 2,pack-era5stores it 5.2 times smaller with a bounded error, andweathertrains a 6-hour forecaster and rolls it forward. - Compress (new in 0.4, experimental).
quantizecompresses a Hugging Face causal language model to 2, 3 or 4 bits per weight against calibration text, one decoder block in memory at a time, andevalscores its perplexity before and after.modelslists 55 released models with what a given GPU can do with each, andfitplans one from its checkpoint’s file headers. - Plan.
memoryestimates memory and time for one GPU, anddoctorprints versions, devices, threads, RAM and which extras import.
All three trainers write resumable checkpoints. On a CPU a resumed run matches an uninterrupted one bit for bit, and the tests check it.
2. What has been measured
On one 4-core CPU, at small sizes. n is the number of seeds and ± is the sample standard deviation over seeds.
Pretraining a small language model
A 5.8M-parameter GPT on TinyStories (a 4,096-token BPE, about 117M training tokens), every run at the same budget of 6.8e13 model FLOPs. Lower validation loss is better. “Baseline compute to match” is how much more compute the plain Muon baseline needs to reach the same loss.
| Recipe | Validation loss | Baseline compute to match | n |
|---|---|---|---|
| AdamW baseline, tuned learning rate | 3.332 | n/a | 1 |
| Muon baseline | 2.737 ± 0.012 | 1.00× | 3 |
| Zoom, k=2 for the first half, batch ×2 | 2.685 ± 0.004 | 1.12× | 3 |
| QK-norm, a known trick | 2.639 ± 0.003 | 1.24× | 2 |
QK-norm and Zoom: --recipe best | 2.589 ± 0.006 | 1.41× | 2 |
QK-norm and Zoom together need about 29% less compute than the plain Muon baseline for the same loss. That evidence is 2 seeds at this one small size, on a CPU.
- Muon is the biggest single win at this size: 2.737 against 3.332 for AdamW. The comparison changes two things at once: in Muon runs the parameters left on AdamW get 16 times the tuned AdamW learning rate, and the AdamW baseline is one seed.
- Zoom’s gain is small, and it repeats across seeds. Patch-level training, the published method it varies, reports about half the training cost at 370M to 2.7B parameters. Bantam measures 1.12 to 1.14 times at 5.8M.
- A known trick beat it. QK-norm alone did better than Zoom alone, and the two stack.
- What did not help (one seed each, against 2.737): a WSD schedule (2.773), ReLU² (2.829), the Polar Express orthogonalizer (2.755) and Zoom schedules with k=4. The first Zoom schedule, k=4 then 2 then 1, lost on all 3 seeds: 2.874.
Against published TinyStories models
1,000 TinyStories validation stories that none of these models trained on, scored in bits per byte so different tokenizers compare fairly; lower is better. The Bantam row is one CPU run of the plain Muon baseline, without QK-norm or Zoom.
| Model | Bits per byte | Parameters | Training FLOPs |
|---|---|---|---|
| Bantam, plain Muon baseline | 1.029 | 5.8M | 6.4e13 |
| llama2.c stories260K | 1.097 | 0.26M | 1.0e16 |
| TinyStories-1M | 0.822 | 3.75M | about 2.1e17 |
| TinyStories-3M | 0.677 | 8.3M | about 4.7e17 |
| llama2.c stories15M | 0.577 | 15.2M | 3.6e18 |
| TinyStories-33M | 0.542 | 68.5M | about 3.9e18 |
Bantam is behind every TinyStories model. It is 0.207 bits per byte behind TinyStories-1M, which used about 3,350 times more compute. It beats llama2.c stories260K with at least 157 times less compute, in one run, and with 22 times more parameters than that model.
The fine-tuning race
Hugging Face Trainer with PEFT against bantam finetune, on SmolLM2-135M in fp32 on
the same 4-core CPU: one epoch over 800 Dolly examples, the same LoRA modules, learning rate and
schedule in every arm, and held-out loss on 200 examples judged the same way.
| Arm | Held-out loss | Minutes | Peak RAM | Tokens/s |
|---|---|---|---|---|
| Hugging Face Trainer + PEFT, AdamW | 2.260 | 13.2 | 4.17 GB | 151 |
| Bantam, the same AdamW | 2.259 | 9.7 | 2.57 GB | 206 |
| Bantam, QLoRA with an NF4 base | 2.368 | 9.4 | 2.12 GB | 212 |
Bantam reached the same held-out loss 1.36 times faster with 38% less peak RAM, mainly because packing computes no padding tokens. Packing also means fewer, larger optimizer steps: at 2 × 2 packed windows per step Bantam took 58 steps instead of 200 and lost 0.056. QLoRA used the least memory and ended 0.109 higher in loss. Muon on the LoRA matrices did not beat AdamW. It was one run per arm, and GPU tools with fused kernels, such as Unsloth, were not in the race.
A small weather model
ERA5 at 5.625° (a 64 × 32 grid, 6 channels), a 1.26M-parameter vision transformer, 5.5e13 FLOPs per run, trained on 2010 to 2017. The score is the normalized error of the 6-hour forecast on 2018, and the error in z500 after 24 hours of rollout; lower is better.
| Recipe | Normalized MSE | z500 RMSE at 24 h (m²/s²) | n |
|---|---|---|---|
| AdamW baseline | 0.229 | 346 | 1 |
| Muon baseline | 0.124 ± 0.001 | 217 | 2 |
| Muon and Zoom | 0.159 ± 0.001, worse | 253 to 258 | 2 |
| Muon and a low-resolution warm-up | 0.112 | 194 | 1 |
| Persistence: the forecast is the current state | n/a | 569 | n/a |
Muon is again the biggest win. Zoom made the forecast worse under Muon. Training on a coarser grid first, a known method called progressive resizing, lowered the error by about 10% in one run. The learning rates were chosen on 2018, the year the runs are scored on, and these are not WeatherBench scorecards: at 5.625° the model is a demo.
Memory and storage
- 8-bit optimizer state and bf16 weights with stochastic rounding: loss 2.728 in one run against 2.737 over 3 seeds, with the weights and optimizer state 2.7 times smaller (50.4 MB to 18.5 MB). It ran 1.6 times slower on this CPU, so it saves memory and costs time.
- Quantized bases, on SmolLM2-135M before any training: int8 costs 0.003 in loss, and NF4 with int8 embeddings 0.18. On a model this small, 4-bit costs real quality. These were measured with the 0.2 code.
- Data stores. TokPack keeps tokens 2.68 times smaller than 16-bit ids, with nothing lost. GridPack keeps ERA5 5.2 times smaller than float32, each value within 5% of its channel’s 6-hour-change standard deviation.
- A 5B model on one 96 GB GPU fits by arithmetic: about 6 bytes per
parameter of model state with bf16 weights and 8-bit state, against 16 to 18 for standard
mixed-precision AdamW. This comes from
bantam memoryand has not been measured. It is not new either: ZeRO-Offload trained models over 13B on one 32 GB GPU in 2021, and torchao ships 8-bit AdamW with bf16 stochastic rounding.
Compressing models (new in 0.4, experimental)
WikiText-2 perplexity after compression, on two small models on the CPU, one seed each; lower
is better. --recover was measured on the smaller model only.
| Format | SmolLM2-135M | Qwen2.5-0.5B | Bits per weight |
|---|---|---|---|
| Float | 20.49 | 16.52 | 16 |
| NF4, round to nearest (Bantam 0.3) | 25.43 | 18.63 | 4.25 |
bantam quantize --bits 4 | 22.04 | 17.45 | 4.16 / 4.13 |
… with --recover 60 | 21.60 | n/a | 4.16 |
bantam quantize --bits 3 | 28.08 | 21.40 | 3.16 / 3.13 |
… with --recover 60 | 26.86 | n/a | 3.16 |
bantam quantize --bits 2 | 117.4 | 99.57 | 2.16 / 2.13 |
At 4 bits the calibrated weights lose less than 0.3’s NF4: 22.04 against 25.43 on SmolLM2-135M, where the float model scores 20.49. At 2 bits these small models are unusable. The largest model taken through the whole path is a 1.3B-parameter mixture-of-experts model, Granite 3.1: 2.67 GB as released, 717 MB at 4 bits, and with half of each layer’s experts in memory, 70% of the experts a token needed were already there. The outputs of a paged model are bit-identical to an unpaged one.
No large model has been compressed or run with Bantam. For the 55 released
models it lists (DeepSeek, Kimi, Qwen, GLM, gpt-oss, Llama, Mistral and others), the parameter
counts, the weight-format readers and the loader’s mapping were checked on the real files,
and 51 of the 55 match their architecture tensor by tensor. Where a model fits and how fast paging
would run are arithmetic. bantam quantize --device cuda has never been run, and Kimi
K3 can only be planned: its architecture exists only as its repository’s own code.
Training techniques added in 0.4
All off by default, on the same 5.8M-parameter TinyStories protocol, 2 seeds unless noted. Each number is how much more compute the plain Muon baseline needs to match.
| Technique | Alone | With --recipe best | Flag |
|---|---|---|---|
| Progressive depth growth | 1.18× | 1.55× | --grow 3:0.25,6:0.75 |
| Sequence-length warm-up | 1.07× | 1.47× | --seq_warmup 64:0.3 |
| Random token dropping | 1.17× | no gain, 1 seed | --tokdrop 0.0625:0.7 |
Depth growth on top of the recipe reached a loss of 2.551, against 2.589 for the recipe alone.
Adding the sequence-length warm-up as well gave 2.546, inside the seed spread, so the three do not
add up. The optimizer step inside backward (--fused_step 1) cut peak memory by 31% on
a 102M-parameter model at batch 1 with gradient checkpointing, and a mini-sequence MLP
(--mlp_chunk) halves the activations kept per token. Two did not pay: 8-bit saved
activations were neutral, and 4-bit optimizer state with Muon gave a worse loss (2.785 against
2.737). For storage, TokPack v3 uses 15.6% fewer bits per token, checkpoints can be stored
losslessly with floatzip, and GridPack v2 keeps ERA5 8.0 times smaller than float32 (5.2 before),
with slower decoding for both new formats.
3. Where it falls short
Nothing has been run on a GPU. Speed and memory against Unsloth, Liger, torchtune, Axolotl or plain Hugging Face on a GPU are unknown, and the 5B figure is arithmetic. The CUDA code paths exist and have only been tested with CPU stand-ins.
- Small scale. One model size per task: 5.8M parameters for pretraining, 135M for fine-tuning and 1.26M for weather. Nothing shows the gains hold at larger scale, and patch-level training, the closest prior work, found its own advantage shrinking with model size.
- Few seeds. Headline rows have 2 or 3 seeds; most ablations have 1.
- Baselines may be under-tuned. The learning rate was tuned on the baseline and reused for Zoom, and weak baselines can inflate a claimed speed-up by up to 2 times (Wen et al., 2025).
- Matched in FLOPs, not in time. Muon’s own optimizer FLOPs, about 20% of the model FLOPs at this size, are not charged to the budget.
- Weather. The runs had no separate validation year, and their learning rates were chosen on the test year.
- Fine-tuning. The race is one run per arm on one 135M model, and packing changes the number of optimizer steps.
- Compression. Measured on models of 135M to 1.3B parameters on a CPU; none of the large models in its catalog has been compressed or run. At 2 bits the method is a baseline, behind vector and trellis quantizers such as AQLM, QuIP# and QTIP, and a quantized layer is dequantized on every call, with no fused kernel. Expert paging and reading one expert at a time need transformers 5.
- Not built: FSDP or ZeRO, RL and preference training (DPO, GRPO), fused GPU kernels and FP8 training.
Corrected in 0.3
Version 0.2 had bugs that changed results, and 0.3.0 fixed them. Packed examples attended to each other, LoRA runs reported as Muon runs were trained by 8-bit AdamW, the chunked loss skipped some models’ logit transforms, and gradient accumulation weighted micro-batches wrongly. The comparison with published models now scores each model family in its own text format, which widened Bantam’s gap to the TinyStories models. And 0.2’s estimate that a 5B model trains 2.6 times faster on one GPU mixed GB and GiB: it is about 1.9 times, and that comes from Muon’s published saving, not from a Bantam measurement.
4. Whose ideas these are
Most of Bantam is other people’s ideas, re-implemented in plain PyTorch: the Muon optimizer (Keller Jordan and others), QK-norm, 8-bit optimizer state (Dettmers and others), bf16 weights with stochastic rounding, LoRA, QLoRA and NF4, DoRA, LoRA+, rsLoRA, the PEFT adapter format and progressive resizing. The compression in 0.4 builds on GPTQ (Frantar and others), QERA’s low-rank correction (Zhang and others) and block-wise reconstruction (BRECQ and EfficientQAT), and depth growth on stacking (Du and others). Zoom is a learned-gate variant of patch-level training (Shao and others, ICLR 2025).
Bantam’s own part is that Zoom design, the TokPack and GridPack file formats, and the tooling that ties it all together. The data comes from TinyStories (Eldan and Li), the llama2.c models (Karpathy) and WeatherBench 2 (Rasp and others).
5. Using it
Install from PyPI. The extras add what each workflow needs:
pip install bantamtrain # core: torch, numpy, zstandard
pip install 'bantamtrain[data]' # prepare-text, generate
pip install 'bantamtrain[finetune]' # finetune, chat, quantize, fit, models, eval
pip install 'bantamtrain[weather]' # prepare-era5
Pretrain a small language model
bantam prepare-text --hf roneneldan/TinyStories --out data/tinystories --vocab 4096
bantam pack-text --data data/tinystories # dedup + compressed token store
bantam pretrain --data data/tinystories --budget 6.8e13 --recipe best \
--name qk_zoom --out runs/tinystories --save runs/tinystories/qk_zoom.pt
bantam generate --model runs/tinystories/qk_zoom_pretrained --prompt "Once upon a time"
Fine-tune a Hugging Face model
# LoRA r=16 on every linear layer, 8-bit AdamW (the defaults)
bantam finetune --model HuggingFaceTB/SmolLM2-135M \
--dataset databricks/databricks-dolly-15k --max_examples 2000 --out runs/dolly
# QLoRA (NF4 base) or DoRA: add --quant nf4 --low_ram 1 --grad_ckpt 1, or --dora 1
bantam chat --model HuggingFaceTB/SmolLM2-135M --adapter runs/dolly \
--prompt "Give me three tips for staying healthy."
The output is a standard PEFT adapter (adapter_config.json and
adapter_model.safetensors) that loads in PEFT.
Train a small weather model
bantam prepare-era5 --out data/era5 # WeatherBench2 ERA5, 5.625 deg, 2010-2018
# Muon and a low-resolution warm-up: the best measured weather run (1 seed)
bantam weather --data data/era5 --val_year 2017 --budget 5.5e13 --recipe best \
--name lowres --out runs/era5 --save runs/era5/lowres.pt
bantam weather --forecast --load runs/era5/lowres.pt --init 2018-03-01T00 --steps 12
Compress a model (experimental)
bantam models --vram_gb 96 --ram_gb 128 # 55 released models: what your GPU can do with each
bantam fit --model deepseek-v3 --check 1 # the plan for one model, from its file headers
bantam quantize --model Qwen/Qwen2.5-0.5B --out q3 --bits 3 # calibrated 2-, 3- or 4-bit weights
bantam eval --model Qwen/Qwen2.5-0.5B q3 # perplexity before and after
bantam chat --model q3 --prompt "Hello" # the result is an ordinary model
bantam finetune --model q3 --dataset databricks/databricks-dolly-15k --out runs/q3
Check first. bantam doctor reports versions, devices and which
extras import, and bantam memory --params 1e9 --gpu_gb 24 estimates whether a run
fits a card before you rent one.
Licence. MIT.
6. Questions
What is Bantam?
Bantam is a small toolkit for training and fine-tuning small language models and small weather models on limited compute, in plain PyTorch. Nathan made it at CorX Labs in Jamaica, and it is published on PyPI as bantamtrain under the MIT licence. One command, bantam, pretrains a small GPT, fine-tunes a Hugging Face model with LoRA, QLoRA or DoRA, trains a 6-hour ERA5 weather forecaster, and estimates memory before you rent a GPU. Since version 0.4 it also compresses Hugging Face models to 2, 3 or 4 bits per weight, an experimental feature measured on models of up to 1.3B parameters.
Can Bantam compress a large model like DeepSeek-V3?
It can plan one, but no large model has been compressed or run with Bantam yet. bantam models and bantam fit read the parameter counts from a checkpoint’s file headers and work out what one GPU can hold; the placement and paged speeds are arithmetic. The quality numbers come from SmolLM2-135M and Qwen2.5-0.5B on a CPU, and the largest model taken through the whole path is a 1.3B-parameter mixture-of-experts model. bantam quantize --device cuda has never been run.
Has Bantam been run on a GPU?
No. Every result was measured in one CPU-only sandbox: 4 cores, 16 GB of RAM, PyTorch 2.15 for CPU. The CUDA code paths exist (bf16 autocast, TF32, torch.compile and multi-GPU DDP through torchrun) but have only been tested with CPU stand-ins. There is no FSDP, no FP8 and no fused GPU kernel.
How much compute does Bantam save in pretraining?
On a 5.8M-parameter GPT trained on TinyStories at a fixed budget, the best measured recipe (Muon, QK-norm and Zoom) reached validation loss 2.589, where the plain Muon baseline reached 2.737. The baseline needs 1.41 times the compute to match it, so the recipe needs about 29% less compute for that loss. That is 2 seeds at one small size on a CPU, and it has not been tested on larger models or a GPU.
Is Bantam faster than Hugging Face for fine-tuning?
In one race on a 4-core CPU, fine-tuning SmolLM2-135M with LoRA on 800 Dolly examples, Bantam matched Hugging Face Trainer with PEFT on held-out loss (2.259 against 2.260) 1.36 times faster and with 38% less peak RAM, mostly because packing computes no padding. With fewer, larger optimizer steps (58 instead of 200) it lost 0.056. It was one run per arm, and GPU tools with fused kernels, such as Unsloth, were not in the race.
How does Bantam compare with published small models?
It is behind every TinyStories model. One CPU run of its plain Muon baseline scores 1.029 bits per byte on 1,000 TinyStories validation stories; TinyStories-1M scores 0.822 with about 3,350 times more compute. It beats llama2.c stories260K (1.097) with at least 157 times less compute, and that model has 22 times fewer parameters.
What is Zoom?
Zoom merges each pair of neighbouring tokens into one position for the first part of training, then trains at full resolution. It is a learned-gate variant of patch-level training (Shao et al., ICLR 2025), which reports about half the training cost at 370M to 2.7B parameters. In Bantam, at 5.8M parameters, Zoom alone saved less: the baseline needs 1.12 times the compute to match it (3 seeds). On the weather model under Muon it made the forecast worse.
Should I use Bantam or Unsloth or Axolotl?
On a GPU, use the established tools: Unsloth for the fastest LoRA and QLoRA on NVIDIA GPUs, and Axolotl, TRL with PEFT or LLaMA-Factory for multi-GPU training and DPO or GRPO. Bantam is for learning how training works, testing training ideas at small scale, and training on a CPU or one GPU, with every experiment small enough to rerun on a laptop.
How do I install Bantam?
Run pip install bantamtrain. The core needs only PyTorch, NumPy and zstandard; add [data] to prepare text, [finetune] to fine-tune, chat and compress, and [weather] for ERA5. It needs Python 3.10 or newer and PyTorch 2.4 or newer. bantam --help lists its 15 commands, and bantam doctor checks your setup.
Try it yourself
Small enough to run on a laptop.
Every quickstart above runs on a CPU, at the sizes measured on this page.
bantam doctor checks your setup first, and bantam memory says what
a bigger run would need.