alikup-ai commited on
Commit
5e7ef04
·
verified ·
1 Parent(s): 788f8b2

varC_long_s0 and combo_s0: weights, configs, tokenizers, ESP32-S3 packs, model card

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ combo_s0/model.pack filter=lfs diff=lfs merge=lfs -text
37
+ varC_long_s0/model.pack filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ datasets:
6
+ - roneneldan/TinyStories
7
+ tags:
8
+ - tinyml
9
+ - microcontroller
10
+ - esp32
11
+ - esp32-s3
12
+ - edge-ai
13
+ - quantization
14
+ - int4
15
+ - tinystories
16
+ pipeline_tag: text-generation
17
+ ---
18
+
19
+ # bytes-per-token: small LMs that run at ~90 tokens/s on an $8 ESP32-S3
20
+
21
+ Weights for [github.com/alikup-ai/bytes-per-token](https://github.com/alikup-ai/bytes-per-token).
22
+ The models were designed for one number: how many bytes of weights the microcontroller reads from PSRAM
23
+ per generated token. They are trained with 4-bit quantization-aware training and run on the board in int4.
24
+
25
+ | model | stored params | weights read per token (int4) | bits/byte, TinyStories valid | speed on ESP32-S3-N16R8 |
26
+ |---|---:|---:|---:|---:|
27
+ | `varC_long_s0` | 8.6M | 1.16 MB | **0.6253** | ~90 tok/s at the start of the context, ~81 mean over 256 tokens |
28
+ | `combo_s0` | 3.4M | 0.90 MB | 0.7322 | ~113 tok/s at the start, ~88 mean |
29
+
30
+ For reference, [slvDev/esp32-ai](https://github.com/slvDev/esp32-ai) (28.9M params) scores 0.863 bits/byte on
31
+ the same text with the same procedure.
32
+
33
+ Bits per byte: first 5,000 stories of `TinyStoriesV2-GPT4-valid.txt` (skipping the first, partial one), joined by
34
+ `<|endoftext|>`, scored on non-overlapping 256-token windows, summed loss in bits divided by UTF-8 bytes.
35
+ Reproduce with `python bench_pc.py` from the GitHub repo.
36
+
37
+ ## Architecture
38
+
39
+ Llama-style decoder, 6 layers, 4 heads, context 256, RoPE, RMSNorm.
40
+
41
+ - **ReLU FFN** instead of SwiGLU: ~79% of FFN neurons are zero per token, and the engine skips their rows.
42
+ - **Per-layer embeddings (PLE)**, the idea from Gemma 3n: a per-layer token table kept in flash, read only for the current token.
43
+ - **4-bit weights** (group-wise QAT); embeddings and output layer tied.
44
+
45
+ | model | d | ffn | vocab | PLE dim |
46
+ |---|---:|---:|---:|---:|
47
+ | `varC_long_s0` | 128 | 256 | 8192 | 128 |
48
+ | `combo_s0` | 128 | 320 | 4096 | 64 |
49
+
50
+ ## Files (per model folder)
51
+
52
+ - `model.safetensors`: PyTorch weights for `train/model.py` in the GitHub repo (`LM(Config(**config["cfg"]))`).
53
+ - `config.json`: shape, training run, measured validation bits/byte.
54
+ - `tokenizer.json`: byte-level BPE (Hugging Face `tokenizers`), `<|endoftext|>` between stories.
55
+ - `model.pack`: the int4 pack the ESP32-S3 engine reads, flashed at 0x90000 with the demo firmware.
56
+ Ready-made full images are in the [GitHub release](https://github.com/alikup-ai/bytes-per-token/releases).
57
+
58
+ ## Training
59
+
60
+ Data: the first 300 MiB of `TinyStoriesV2-GPT4-train.txt` from
61
+ [roneneldan/TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories).
62
+ `varC_long_s0`: 70M tokens (~0.9 epoch), `combo_s0`: 20M tokens. AdamW, lr 3e-3, batch 32 x 256, one seed,
63
+ laptop CPU (~2.6 h for `varC_long_s0`).
64
+
65
+ ## Limitations
66
+
67
+ - Trained only on synthetic children's stories: it continues simple English stories and does not follow instructions or answer general questions.
68
+ - Context is 256 tokens.
69
+ - One training seed per model; small differences between models are within seed noise (~0.003 bits/byte).
70
+
71
+ License: MIT.
combo_s0/config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "combo_s0",
3
+ "cfg": {
4
+ "vocab": 4096,
5
+ "d": 128,
6
+ "layers": 6,
7
+ "heads": 4,
8
+ "ffn": 320,
9
+ "ple": 64,
10
+ "experts": 1,
11
+ "seq_len": 256,
12
+ "rope_theta": 10000.0,
13
+ "act": "relu",
14
+ "qbits": 4
15
+ },
16
+ "stored_params": 3375104,
17
+ "read_params": 1802752,
18
+ "bytes_per_token_4bit": 901376.0,
19
+ "steps": 2441,
20
+ "tokens": 19996672,
21
+ "lr": 0.003,
22
+ "seed": 0,
23
+ "batch": 32,
24
+ "final_val_loss": 2.0081979647332195,
25
+ "elapsed_s": 2419.3
26
+ }
combo_s0/model.pack ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97030f02d89f7ca2ddefa444a6d94e2b90627f3790008c4dfff9e4a4ab6017f6
3
+ size 2436288
combo_s0/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ea3d5098e43fa75260d17b0f821dc48f0984357df6c1ca7053f3c2027e211b7
3
+ size 13517352
combo_s0/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
varC_long_s0/config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "varC_long_s0",
3
+ "cfg": {
4
+ "vocab": 8192,
5
+ "d": 128,
6
+ "layers": 6,
7
+ "heads": 4,
8
+ "ffn": 256,
9
+ "ple": 128,
10
+ "experts": 1,
11
+ "seq_len": 256,
12
+ "rope_theta": 10000.0,
13
+ "act": "relu",
14
+ "qbits": 4
15
+ },
16
+ "stored_params": 8617984,
17
+ "read_params": 2327424,
18
+ "bytes_per_token_4bit": 1163712.0,
19
+ "steps": 8544,
20
+ "tokens": 69992448,
21
+ "lr": 0.003,
22
+ "seed": 0,
23
+ "batch": 32,
24
+ "final_val_loss": 1.7688706053627863,
25
+ "elapsed_s": 9423.2,
26
+ "val_bpb": 0.6261052017431212
27
+ }
varC_long_s0/model.pack ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1955d394b47cbb135116ef23560482518da76fd008312915aa2f50e80972fc95
3
+ size 5714624
varC_long_s0/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3dab0cfdba413b158e81479f863ce82e2b4200fdb5f21a3a5db72c945a5832cf
3
+ size 34489144
varC_long_s0/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff