xaskasdf commited on
Commit
d0e32f5
·
verified ·
1 Parent(s): c306830

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. README.md +350 -0
  2. config.json +29 -0
  3. model.safetensors +3 -0
  4. tokenizer.model +3 -0
  5. tokenizer.vocab +0 -0
  6. tokenizer_config.json +15 -0
README.md ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: pytorch
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - llama
9
+ - text-generation
10
+ - conversational
11
+ - tiny
12
+ - ultra-small
13
+ - instruction-following
14
+ - knowledge-distillation
15
+ - deep-narrow
16
+ - mobilellm
17
+ - denseformer
18
+ datasets:
19
+ - wikimedia/wikipedia
20
+ - HuggingFaceTB/smollm-corpus
21
+ - nyu-mll/blimp
22
+ - Rowan/hellaswag
23
+ - allenai/ai2_arc
24
+ - ybisk/piqa
25
+ - allenai/winogrande
26
+ - cimec/lambada
27
+ - Salesforce/wikitext
28
+ model-index:
29
+ - name: Brandon-Tiny-10M-Instruct
30
+ results:
31
+ - task:
32
+ type: text-generation
33
+ name: BLiMP (Grammatical Knowledge)
34
+ dataset:
35
+ name: BLiMP
36
+ type: blimp
37
+ metrics:
38
+ - type: accuracy
39
+ value: 73.3
40
+ name: Accuracy
41
+ - task:
42
+ type: text-generation
43
+ name: HellaSwag (Commonsense)
44
+ dataset:
45
+ name: HellaSwag
46
+ type: Rowan/hellaswag
47
+ metrics:
48
+ - type: accuracy
49
+ value: 32.4
50
+ name: 0-shot Accuracy
51
+ - task:
52
+ type: text-generation
53
+ name: ARC-Easy (Science Reasoning)
54
+ dataset:
55
+ name: ARC-Easy
56
+ type: allenai/ai2_arc
57
+ metrics:
58
+ - type: accuracy
59
+ value: 30.6
60
+ name: 0-shot Accuracy
61
+ - task:
62
+ type: text-generation
63
+ name: PIQA (Physical Intuition)
64
+ dataset:
65
+ name: PIQA
66
+ type: ybisk/piqa
67
+ metrics:
68
+ - type: accuracy
69
+ value: 54.7
70
+ name: 0-shot Accuracy
71
+ ---
72
+
73
+ # Brandon-Tiny-10M-Instruct
74
+
75
+ A 10.7M parameter instruction-following language model that punches far above its weight class. Small enough to run on a PlayStation 2's Emotion Engine. Named after a Cloudflare tunnel URL that sounded like a language model.
76
+
77
+ ## Why This Exists
78
+
79
+ We wanted a language model small enough to run natively on a PlayStation 2 -- 32 MB of VRAM on the Emotion Engine, tested on both emulator and real hardware. Inspired by Karpathy's TinyStories, we looked for existing models small enough, and couldn't find anything decent. So we built one.
80
+
81
+ The name "Brandon Tiny" comes from a Cloudflare tunnel: one day we ran `cloudflared tunnel` and the random URL came back as something like `sugar-alaska-brandon-tiny.trycloudflare.com`. We were serving a custom agentic chat through it, and the URL looked so much like a language model name that we couldn't stop joking about it. The name stuck.
82
+
83
+ After 8 model variants, 3 architectural experiments, and one 3-phase training pipeline, Brandon Tiny turned out to be genuinely impressive for its size.
84
+
85
+ ## Highlights
86
+
87
+ - **10.7M parameters** -- runs on a PS2 Emotion Engine (32 MB VRAM)
88
+ - **Beats our own 30M model** on fine-tuning loss (2.40 vs 2.61)
89
+ - **Zero repetition loops** across all generation tests
90
+ - **80% instruction following** on 25 diverse prompts
91
+ - **Trained in ~7 hours** on a single RTX 3090
92
+ - **3-phase pipeline**: Pretrain → Knowledge Distillation → Instruction Finetune
93
+
94
+ ## Model Details
95
+
96
+ ### Architecture
97
+
98
+ Llama 2 style decoder-only transformer with three modern enhancements:
99
+
100
+ | Spec | Value |
101
+ |------|-------|
102
+ | Parameters | 10,706,776 |
103
+ | Dimensions | 256 |
104
+ | Layers | 24 (12 unique with block sharing) |
105
+ | Attention Heads | 8 (2 KV heads, GQA 4:1) |
106
+ | FFN Hidden | 720 (SwiGLU) |
107
+ | Vocabulary | 8,192 (SentencePiece BPE) |
108
+ | Max Sequence | 512 tokens |
109
+ | Positional | RoPE (theta=10000) |
110
+ | Normalization | RMSNorm |
111
+ | Enhancements | DenseFormer + Value Residual + Register Tokens |
112
+
113
+ **Block Sharing (MobileLLM):** Adjacent layer pairs share weights, giving 24 effective layers from only 12 unique parameter blocks.
114
+
115
+ **DenseFormer:** Depth-Weighted Averaging connects all previous layer outputs to each subsequent layer.
116
+
117
+ **Value Residual:** Layer 0's value projection is added to all subsequent layers, preserving early representations.
118
+
119
+ **Register Tokens:** 4 learnable tokens prepended to input, acting as attention sinks.
120
+
121
+ ### Training
122
+
123
+ 3-phase pipeline, each phase addressing different aspects:
124
+
125
+ | Phase | Steps | LR Schedule | Data | Result |
126
+ |-------|-------|-------------|------|--------|
127
+ | 1. Foundation Pretrain | 15K | WSD (8e-4) | 600M tokens (Wiki 40% + SmolLM 30% + Synthetic 30%) | val_loss 4.39 |
128
+ | 2. Knowledge Distillation | 7.5K | WSD (4e-4) | Same pretrain data, 30M teacher | val_loss 4.84 |
129
+ | 3. Instruction Finetune | 12K | Cosine (2e-5) | 75K examples (chat + reasoning + replay) | **val_loss 2.40** |
130
+
131
+ **Anti-repetition training** in Phase 3: label smoothing (0.1) + unlikelihood training (0.5) + entropy regularization (0.01).
132
+
133
+ **Knowledge distillation** uses reverse KL divergence (mode-seeking) with temperature 2.0, following MiniPLM findings that reverse KLD is better for small students.
134
+
135
+ ### Inference
136
+
137
+ | Metric | Value |
138
+ |--------|-------|
139
+ | Speed | 21 tokens/sec (RTX 3090) |
140
+ | VRAM | 51.5 MB allocated |
141
+ | Model size | 42.8 MB (fp32) / 21.4 MB (bf16) |
142
+
143
+ ## Evaluation
144
+
145
+ ### Standard Benchmarks (0-shot)
146
+
147
+ | Benchmark | Brandon-Tiny-10M | Random Baseline | Delta |
148
+ |-----------|:----------------:|:---------------:|:-----:|
149
+ | BLiMP (Grammar) | **73.3%** | 50.0% | +23.3 |
150
+ | HellaSwag (Commonsense) | **32.4%** | 25.0% | +7.4 |
151
+ | ARC-Easy (Science) | **30.6%** | 25.0% | +5.6 |
152
+ | PIQA (Physical Intuition) | **54.7%** | 50.0% | +4.7 |
153
+ | Winogrande (Coreference) | 50.3% | 50.0% | +0.3 |
154
+ | LAMBADA (Last Word) | **8.8%** | 0.0% | +8.8 |
155
+ | Wikitext-2 PPL | **224.2** | -- | -- |
156
+
157
+ ### Custom Evaluation Suite
158
+
159
+ Tested against 7 models from our experimental series:
160
+
161
+ | Model | Params | Wikitext-2 PPL | Gen. Quality | Repetition | Instr. Following |
162
+ |-------|--------|:--------------:|:------------:|:----------:|:----------------:|
163
+ | **Brandon-Tiny-10M** | **10.7M** | **224.2** | **0.947** | **0.000** | **80%** |
164
+ | 10M Enhanced v2 | 10.7M | 329.2 | 0.939 | 0.000 | 80% |
165
+ | 30M v2 Original | 30.0M | 302.8 | 0.957 | 0.000 | 84% |
166
+ | 30M v2 Wiki | 30.0M | 168.6 | 0.918 | 0.000 | 72% |
167
+
168
+ Note: The 10M Optimal achieves comparable performance to 30M models with 3x fewer parameters.
169
+
170
+ ## Usage
171
+
172
+ ### Installation
173
+
174
+ ```bash
175
+ git clone https://github.com/[your-repo]/brandon-tiny
176
+ cd brandon-tiny
177
+ pip install torch sentencepiece pyyaml numpy
178
+ ```
179
+
180
+ ### Inference
181
+
182
+ ```python
183
+ from src.model import TinyLlama
184
+ from src.tokenizer import Tokenizer
185
+
186
+ # Load model
187
+ model = TinyLlama.from_checkpoint('checkpoints/10m_optimal/phase3_finetune/best.pt')
188
+ tokenizer = Tokenizer('data/tokenizer_8k.model')
189
+
190
+ # Chat format
191
+ prompt = "<|im_start|>user\nTell me a story about a cat.<|im_end|>\n<|im_start|>assistant\n"
192
+ tokens = tokenizer.encode(prompt)
193
+ input_ids = torch.tensor(tokens, device='cuda')
194
+
195
+ output = model.generate(
196
+ input_ids,
197
+ max_new_tokens=200,
198
+ temperature=0.7,
199
+ top_p=0.9,
200
+ repetition_penalty=1.2,
201
+ no_repeat_ngram_size=3,
202
+ stop_tokens=tokenizer.get_stop_tokens(),
203
+ )
204
+
205
+ response = tokenizer.decode(output[0, len(tokens):].tolist())
206
+ print(response)
207
+ ```
208
+
209
+ ### Generation Examples
210
+
211
+ **Identity:**
212
+ > User: What is your name?
213
+ > Assistant: I'm Brandon Tiny, a small language model designed to help in limited environments.
214
+
215
+ **Creative:**
216
+ > User: Tell me a short story about a cat.
217
+ > Assistant: Once upon a time, there was an old but young cat named Charlie who lived in the small town of Pagima. Every day, he set out on adventures...
218
+
219
+ **Reasoning:**
220
+ > User: What happens when ice melts?
221
+ > Assistant: When ice causes a strong layer of water, the ice accumulates in the atmosphere due to the temperature and pressure...
222
+
223
+ ## Limitations
224
+
225
+ - **Factual accuracy:** The model hallucinates freely. Do NOT use for factual question answering.
226
+ - **English only:** Trained exclusively on English data.
227
+ - **Short context:** Maximum 512 tokens.
228
+ - **No safety alignment:** No RLHF/DPO training has been applied.
229
+ - **Arithmetic:** Cannot reliably perform mathematical operations.
230
+ - **Vocabulary artifacts:** Occasionally produces garbled or invented words.
231
+ - **Standard benchmarks:** Expected to score near-random on MMLU, GSM8K, and other benchmarks designed for larger models.
232
+
233
+ ## What This Model IS Good For
234
+
235
+ - Running a language model on a PlayStation 2 (or any device with 32+ MB VRAM)
236
+ - Research on ultra-small language models
237
+ - Understanding scaling behavior at extreme parameter budgets
238
+ - Edge/embedded deployment experiments
239
+ - Educational purposes (understanding LLM training pipelines)
240
+ - Prototyping conversational agents with minimal compute
241
+
242
+ ## What This Model Is NOT Good For
243
+
244
+ - Factual question answering
245
+ - Mathematical reasoning
246
+ - Professional or production use
247
+ - Any task requiring reliability or safety guarantees
248
+
249
+ ## Training Details
250
+
251
+ ### Hardware
252
+ - Single NVIDIA RTX 3090 (24 GB VRAM)
253
+ - Total training time: ~7 hours across all 3 phases
254
+ - Operating system: Windows 11
255
+
256
+ ### Data
257
+
258
+ **Pre-training (600M tokens):**
259
+ - [Wikipedia English](https://huggingface.co/datasets/wikimedia/wikipedia) (40%)
260
+ - [SmolLM Corpus](https://huggingface.co/datasets/HuggingFaceTB/smollm-corpus) (30%)
261
+ - Synthetic data generated by GPT-4o-mini (30%)
262
+
263
+ **Instruction fine-tuning (75,502 examples):**
264
+ - 57,000 curated chat instructions
265
+ - 19,944 reasoning/Chain-of-Thought examples
266
+ - ~200 pretrain replay examples (catastrophic forgetting mitigation)
267
+
268
+ **Evaluation datasets:**
269
+ - [BLiMP](https://huggingface.co/datasets/nyu-mll/blimp) - Grammatical knowledge
270
+ - [HellaSwag](https://huggingface.co/datasets/Rowan/hellaswag) - Commonsense reasoning
271
+ - [ARC-Easy](https://huggingface.co/datasets/allenai/ai2_arc) - Science reasoning
272
+ - [PIQA](https://huggingface.co/datasets/ybisk/piqa) - Physical intuition
273
+ - [Winogrande](https://huggingface.co/datasets/allenai/winogrande) - Coreference resolution
274
+ - [LAMBADA](https://huggingface.co/datasets/cimec/lambada) - Last word prediction
275
+ - [Wikitext](https://huggingface.co/datasets/Salesforce/wikitext) - Perplexity evaluation
276
+
277
+ ### Tokenizer
278
+ - SentencePiece BPE, 8,192 vocabulary
279
+ - Special tokens: `<|im_start|>`, `<|im_end|>`, `<|bos|>`, `<|eos|>`, `<|pad|>`
280
+ - Chat format: ChatML
281
+
282
+ ### Training Hyperparameters
283
+
284
+ <details>
285
+ <summary>Phase 1: Foundation Pre-training</summary>
286
+
287
+ - Learning rate: 8e-4 → 8e-5 (WSD schedule)
288
+ - Steps: 15,000
289
+ - Batch size: 32 × 4 gradient accumulation = effective 65K tokens/step
290
+ - Warmup: 500 steps, Stable: 70%, Decay: 20%
291
+ - Weight decay: 0.1
292
+ - Optimizer: AdamW (beta1=0.9, beta2=0.95)
293
+ - Precision: bfloat16
294
+ </details>
295
+
296
+ <details>
297
+ <summary>Phase 2: Knowledge Distillation</summary>
298
+
299
+ - Teacher: Brandon-Tiny 30M v2 pretrained (30M params)
300
+ - Method: Reverse KL Divergence
301
+ - Temperature: 2.0
302
+ - Alpha: 0.5 (soft/hard target balance)
303
+ - Learning rate: 4e-4 → 4e-5 (WSD)
304
+ - Steps: 7,500
305
+ </details>
306
+
307
+ <details>
308
+ <summary>Phase 3: Instruction Fine-tuning</summary>
309
+
310
+ - Learning rate: 2e-5 → 2e-6 (cosine)
311
+ - Steps: 12,000
312
+ - Batch size: 16 × 4 gradient accumulation
313
+ - Weight decay: 0.01
314
+ - Label smoothing: 0.1
315
+ - Unlikelihood alpha: 0.5
316
+ - Entropy regularization beta: 0.01
317
+ - Loss masking: assistant tokens only
318
+ </details>
319
+
320
+ ## Experimental Context
321
+
322
+ This model is the result of systematic exploration across 8 architectural variants. Key insight: **training methodology matters more than parameter count at this scale.** The 3-phase pipeline (Pretrain → Distill → Finetune) enabled a 10M model to outperform 30M models trained with a standard 2-phase approach.
323
+
324
+ For the full experimental report, see our [technical report](docs/technical_report.md).
325
+
326
+ ## Links
327
+
328
+ - **Website:** [naranjositos.tech](https://naranjositos.tech/)
329
+ - **Code:** [github.com/naranjositos/brandon-tiny](https://github.com/naranjositos/brandon-tiny)
330
+ - **Technical Report:** [docs/technical_report.md](docs/technical_report.md)
331
+
332
+ ## Citation
333
+
334
+ ```bibtex
335
+ @misc{brandon-tiny-2026,
336
+ title={Brandon-Tiny 10M: A 3-Phase Training Pipeline for Ultra-Small Instruction-Following Language Models},
337
+ author={Samuel Cortes},
338
+ year={2026},
339
+ url={https://naranjositos.tech/}
340
+ }
341
+ ```
342
+
343
+ ## Acknowledgments
344
+
345
+ Architecture and techniques inspired by:
346
+ - MobileLLM (Meta, 2024) - Block sharing, deep-narrow design
347
+ - SmolLM2 (HuggingFace, 2025) - Data-centric small model training
348
+ - MiniCPM (2024) - WSD learning rate schedule
349
+ - DenseFormer (Pagliardini et al., 2024) - Depth-Weighted Averaging
350
+ - MiniPLM (ICLR 2025) - Reverse KLD for small model distillation
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "TinyLlama"
4
+ ],
5
+ "model_type": "brandon-tiny",
6
+ "dim": 256,
7
+ "n_layers": 24,
8
+ "n_heads": 8,
9
+ "n_kv_heads": 2,
10
+ "vocab_size": 8192,
11
+ "hidden_dim": 720,
12
+ "max_seq_len": 512,
13
+ "dropout": 0.05,
14
+ "weight_tying": true,
15
+ "norm_eps": 1e-05,
16
+ "rope_theta": 10000.0,
17
+ "block_sharing": true,
18
+ "n_predict": 1,
19
+ "dense_former": true,
20
+ "value_residual": true,
21
+ "n_registers": 4,
22
+ "n_loops": 1,
23
+ "ternary": false,
24
+ "activation": "swiglu",
25
+ "normalization": "rmsnorm",
26
+ "position_encoding": "rope",
27
+ "chat_format": "chatml",
28
+ "total_parameters": 10706776
29
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ff727cc8921d21e5e7b153babd288efc5524b166e9417e1b439ac8c11fe44cf
3
+ size 60072760
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6808ff86d9b1422aa1ef5d0adb3cde5d993e870a4387fcd2a16a119083caae0
3
+ size 369538
tokenizer.vocab ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "sentencepiece",
3
+ "vocab_size": 8192,
4
+ "bos_token": "<|bos|>",
5
+ "eos_token": "<|eos|>",
6
+ "pad_token": "<|pad|>",
7
+ "chat_template": "{% for message in messages %}<|im_start|>{{ message.role }}\n{{ message.content }}<|im_end|>\n{% endfor %}<|im_start|>assistant\n",
8
+ "special_tokens": {
9
+ "im_start": "<|im_start|>",
10
+ "im_end": "<|im_end|>",
11
+ "bos": "<|bos|>",
12
+ "eos": "<|eos|>",
13
+ "pad": "<|pad|>"
14
+ }
15
+ }