bantamtrain 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.4
2
+ Name: bantamtrain
3
+ Version: 0.1.0
4
+ Summary: Bantam: train small language models and weather models faster and cheaper on limited compute - Zoom Training, Muon, 8-bit/bf16 low-memory training, int8/int4 weights, compressed token and weather-grid stores
5
+ Author: Nathan
6
+ License-Expression: MIT
7
+ Project-URL: Source, https://github.com/Wisk-inc/AboxRebuildcode
8
+ Keywords: llm,training,efficiency,muon,optimizer,quantization,weather,era5,pytorch
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: torch>=2.2
19
+ Requires-Dist: numpy>=1.24
20
+ Requires-Dist: zstandard>=0.21
21
+ Provides-Extra: data
22
+ Requires-Dist: tokenizers; extra == "data"
23
+ Requires-Dist: pyarrow; extra == "data"
24
+ Requires-Dist: huggingface_hub; extra == "data"
25
+ Provides-Extra: weather
26
+ Requires-Dist: xarray; extra == "weather"
27
+ Requires-Dist: zarr; extra == "weather"
28
+ Requires-Dist: fsspec; extra == "weather"
29
+ Requires-Dist: aiohttp; extra == "weather"
30
+ Provides-Extra: test
31
+ Requires-Dist: pytest; extra == "test"
32
+ Dynamic: license-file
33
+
34
+ # Bantam (`bantamtrain`)
35
+
36
+ **Train small language models and weather models faster and cheaper on limited
37
+ compute, without throwing away data.** Made by Nathan, Jamaica.
38
+
39
+ Bantam is the library behind a set of measured results on real data (TinyStories
40
+ from HuggingFace, ERA5 from WeatherBench2), all obtained in a 4-core CPU sandbox;
41
+ the same code runs on a GPU with mixed precision and `torch.compile`.
42
+
43
+ ```bash
44
+ pip install bantamtrain
45
+ ```
46
+
47
+ ## What is inside
48
+
49
+ | module | what it does | measured (5.8M-param LM on TinyStories unless noted) |
50
+ |---|---|---|
51
+ | `bantamtrain.zoom` | **Zoom Training**: merge neighbouring tokens / grid patches into one position early in training, anneal back to full resolution | k=2 for the first half with batch x2: loss 2.685 +- 0.004 vs 2.737 +- 0.011 at equal FLOPs (3 seeds) |
52
+ | `bantamtrain.optim` | **Muon** optimizer (Jordan 2024; quintic or Polar Express orthogonalizer), AdamW for the rest, 8-bit state | 2.74 vs 3.33 (AdamW) at equal FLOPs |
53
+ | `bantamtrain.lowmem` | 8-bit blockwise optimizer state; bf16 weights with stochastic rounding (no fp32 master copy) | weights + state 3x smaller, loss 2.728 vs 2.737 |
54
+ | `bantamtrain.qweights` | int8 / int4 weight-only `Linear` and `Embedding` kept compressed in RAM | int8: 3.9x smaller, +0.0002 loss; int4: 7.5x smaller, +0.026 |
55
+ | `bantamtrain.weightpack` | compressed checkpoints: fp32 / lossless bf16 / int8 / int4 | lossless bf16 file 2.9x smaller than fp32 |
56
+ | `bantamtrain.data.tokpack` | TokPack v2: random-access compressed token store (rank remap + LEB128 + zstd dictionary) | 2.68x smaller than uint16 ids (5.97 bits/token), exact |
57
+ | `bantamtrain.data.dedup` | exact + MinHash-LSH near-duplicate removal on token streams, vectorised | 4 % exact duplicates found in TinyStories |
58
+ | `bantamtrain.data.gridpack` | GridPack: error-bounded int16 + temporal delta + zstd for gridded fields | ERA5 5.2x smaller than float32, error <= 5 % of a 6 h change |
59
+ | `bantamtrain.device` | runtime: flush-to-zero on CPU, AMP, TF32, compile, batch finder, duty-cycle limiter | the FTZ fix made affected CPU matmuls up to 23x faster |
60
+ | `bantamtrain.memory` | memory / time scoreboard for single-GPU training | `python -m bantamtrain.memory` |
61
+ | `bantamtrain.models` | `ZoomGPT` (decoder LM) and `ZoomViT` (weather grid forecaster) with every option above | |
62
+
63
+ ## Quick start
64
+
65
+ ```python
66
+ import torch
67
+ from bantamtrain.models import ZoomGPT
68
+ from bantamtrain.optim import build_optimizer
69
+ from bantamtrain.zoom import ZoomSchedule, lr_at
70
+
71
+ model = ZoomGPT(vocab=4096, d=256, n_layer=6, n_head=4, zoom_ks=[2])
72
+ opt = build_optimizer(model, "muon", lr=1.6e-2, weight_decay=0.1, state_bits=8)
73
+ sched = ZoomSchedule.parse("2:0.5,1:0.5") # k=2 for the first half of the budget
74
+
75
+ x = torch.randint(0, 4096, (16, 258))
76
+ for frac in (0.1, 0.6): # fraction of the compute budget spent
77
+ k = sched.k_at(frac)
78
+ for g in opt.param_groups:
79
+ g["lr"] = lr_at(frac, 1.6e-2, sched="wsd")
80
+ loss = model(x[:, :256], x[:, k:256 + k], k=k)
81
+ opt.zero_grad(); loss.backward(); opt.step()
82
+ ```
83
+
84
+ Store a trained model small:
85
+
86
+ ```python
87
+ from bantamtrain import qweights, weightpack
88
+ weightpack.save("model.zwpk", model.state_dict(), bits=8) # int8 checkpoint file
89
+ qweights.quantize_model(model, bits=4) # int4 weights in RAM, float compute
90
+ ```
91
+
92
+ Size a run on one GPU:
93
+
94
+ ```bash
95
+ python -m bantamtrain.memory --params 5e9 --gpu_gb 96 --tokens 1e11
96
+ ```
97
+
98
+ ## Honest notes
99
+
100
+ - Muon, 8-bit optimizer state, stochastic-rounding bf16 and blockwise weight
101
+ quantization are published techniques re-implemented here; Zoom Training and
102
+ the storage formats are this project's own.
103
+ - All quality numbers above were measured on a 5.8M-parameter model; gains at
104
+ larger scale are expected to be smaller for the optimizer and are untested for
105
+ Zoom. Nothing has been run on a GPU yet.
106
+ - Source, experiments, tests and the full write-up:
107
+ https://github.com/Wisk-inc/AboxRebuildcode
@@ -0,0 +1,20 @@
1
+ bantamtrain/__init__.py,sha256=XuqGCbTt9r-Y5AphGXmtv4oXGsE-pSvbioPxVRfFJyE,504
2
+ bantamtrain/device.py,sha256=oKMXrWKXKyjClYhESt-S1e2ZVcHi1bD4CgQgfcAVh6U,6158
3
+ bantamtrain/lowmem.py,sha256=u3zARMQ4mqrY0jBJ5-2-H7a3xqt_TMbXyia6QicZGj4,4767
4
+ bantamtrain/memory.py,sha256=M0lX4z9G9ViFX52GA9jUoPq0Z_WGgIhgAXeoTvnHXGI,9322
5
+ bantamtrain/optim.py,sha256=Lk_XmodUZCHtlt2wgdmjQQektOdmfvH6Y0GyuwJK_Ek,9195
6
+ bantamtrain/qweights.py,sha256=vhHLDvGeo3DxsjyUYnzsOxAVsVWB8mS5Yjw6LDWmoys,5272
7
+ bantamtrain/weightpack.py,sha256=JMal_LCwZNb3UfHlZJXPvOIeom1sYL6p1oR5-p4HNKU,6514
8
+ bantamtrain/zoom.py,sha256=qXdY9ZWrQEtUWB-IhVTau4O8FlvQtE7Yv4ffGrufaMI,5500
9
+ bantamtrain/data/__init__.py,sha256=Kn-fhFPbn_1lkT9ys_5I6GsR5MQTtZP0F4_rrP4cKtQ,53
10
+ bantamtrain/data/dedup.py,sha256=czb8Zs6oKCRVEkhm9-lyX0AVt_DA2QaItaF_qf5wxAo,5888
11
+ bantamtrain/data/gridpack.py,sha256=53RNKYa3V2XvQkJsecw1NubbrHecgdLRJFjnPQYD5yg,5485
12
+ bantamtrain/data/tokpack.py,sha256=BgwKxMECiTy_nJDRG-S5zWpwZTp-SbUxli6OfN4Ryeo,9287
13
+ bantamtrain/models/__init__.py,sha256=-WjZbcCe58fsKhO_QRhTDyqjQjSFzSQk8HGkPwz3ws0,86
14
+ bantamtrain/models/gpt.py,sha256=klRn84VNfeIxFzD-auIXzgqFgLD-G4LBVq3xHh5bA3s,7444
15
+ bantamtrain/models/vit_weather.py,sha256=j45qEkB4Y_gMypU5x4_lSPqVJmcQewBmmyGKIjfHWWk,5097
16
+ bantamtrain-0.1.0.dist-info/licenses/LICENSE,sha256=B-dKvC0yRVgxLbFdW57s7fwR82Dj6YoMuqfvpq5NddI,1063
17
+ bantamtrain-0.1.0.dist-info/METADATA,sha256=c4iiTSnLiBtM5zZkRsf1aslQqmOpx4gvDv345DdkUvI,5355
18
+ bantamtrain-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
+ bantamtrain-0.1.0.dist-info/top_level.txt,sha256=-2gY3XzK7WTRed7qIX94MHD1xymdMHyQHIIjvPPdYq0,12
20
+ bantamtrain-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nathan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ bantamtrain