File size: 9,423 Bytes
8988982
 
4cadc9e
 
8988982
4cadc9e
 
 
 
 
 
 
 
 
 
 
 
 
 
8988982
 
4cadc9e
8988982
9648c63
 
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
 
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
8988982
4cadc9e
8988982
4cadc9e
 
 
 
 
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
8988982
4cadc9e
 
 
 
 
 
 
8988982
4cadc9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8988982
4cadc9e
 
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
 
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
8988982
4cadc9e
8988982
4cadc9e
 
 
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
 
 
8988982
9648c63
0024fb9
fc0a437
0024fb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc0a437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0024fb9
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
8988982
4cadc9e
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
 
 
 
 
8988982
4cadc9e
8988982
4cadc9e
 
 
 
 
8988982
4cadc9e
8988982
4cadc9e
8988982
4cadc9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
---
library_name: transformers
license: apache-2.0
base_model: openai-community/gpt2-xl
tags:
- chatbot
- gpt2
- lora
- instruction-tuned
- distilled
- microllm2
pipeline_tag: text-generation
language:
- en
widget:
- text: "<|im_start|>user\nWho are you?<|im_end|>\n<|im_start|>assistant\n"
  example_title: Identity check
- text: "<|im_start|>user\nExplain quantum computing in simple terms<|im_end|>\n<|im_start|>assistant\n"
  example_title: Simple explanation
---

# MicroLLM2

![image](https://cdn-uploads.huggingface.co/production/uploads/6a5434fc4ee93d17dce646af/s0WBdHFtvgnD1Sz3xVwIs.png)

MicroLLM2 is a chatbot built from GPT2 XL 1.5B by Maximalist Labs. It takes the classic openai-community/gpt2-xl and elevates it with instruction tuning and distillation so it can actually chat, follow prompts, and keep a consistent identity.

If you ask who made it, it will tell you: MicroLLM2 created by Maximalist Labs. That is baked in during training, not just a system prompt.

**Repo:** `MLVXN/MicroLLM2`  
**Base:** `openai-community/gpt2-xl` (48 layers, 1600 hidden, 1024 context, 1.5B params)  
**Method:** LoRA SFT on distilled chat data, merged to a single safetensors for easy use  
**Context:** 1024 tokens  
**License:** Apache 2.0

## What makes this different from plain GPT2 XL

Plain GPT2 XL is a strong completer but not a chat model. MicroLLM2 adds:

* ChatML format with `<|im_start|>` and `<|im_end|>` so conversations have clear user and assistant turns
* Distilled instruction data from high quality teachers (GPT-4, GPT-3.5, Mixtral) plus identity reinforcement
* Clean merge: no adapter needed at inference, just load like any GPT2 model

No fancy claims here. It is still a 1.5B model with 1024 context. It will not beat 7B or larger models on broad knowledge, but it is far more useful than raw GPT2 XL for chatting, writing, and simple reasoning.

## Training in a nutshell
* **Tuning:** LoRA r=64 alpha=128 on all attention and MLP projections (c_attn, c_proj, c_fc). About 78M trainable params. BF16 with TF32, Flash SDPA, packing, gradient checkpointing, 8-bit Adam, torch.compile.
* **Throughput:** around 16.5k tokens per second on H100, roughly 3 hours for the main run plus overhead to land in the 4 to 5 hour window.
* **Data mix:** 200k samples total, 3 epochs. Roughly 29k from UltraChat 200k (GPT-3.5), 100k from OpenHermes 2.5 (GPT-4), 60k from WizardLM Evol Instruct V2 (GPT-4), 5k from Cosmopedia v2 (Mixtral), plus 10k identity examples upsampled. Raw about 510M tokens, effective about 200M after packing and truncation. All packed to 1024 with ChatML.
* **Identity:** 200 hand written identity prompts expanded to 10k during training so the model learns to answer consistently as MicroLLM2 by Maximalist Labs.
* **Chat template:** `<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n{response}<|im_end|>`

## How to use

### Transformers

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "MLVXN/MicroLLM2"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
    device_map="auto"
)

def chat(prompt, max_new=160):
    formatted = f"<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
    inputs = tok(formatted, return_tensors="pt").to(model.device)
    out = model.generate(
        **inputs,
        max_new_tokens=max_new,
        do_sample=True,
        temperature=0.7,
        top_p=0.9,
        repetition_penalty=1.1,
        pad_token_id=tok.eos_token_id,
        eos_token_id=tok.convert_tokens_to_ids("<|im_end|>")
    )
    text = tok.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=False)
    return text.split("<|im_end|>")[0].strip()

print(chat("Who are you?"))
print(chat("Write a short poem about the H100"))
```

### Ollama Modelfile

A `Modelfile` is included for Ollama. It sets the ChatML template, system prompt, and sane defaults.

```bash
ollama create microllm2 -f Modelfile
ollama run microllm2
# then chat normally, the identity is already set
```

### GGUF for llama.cpp

GGUF weights are in this repo:

* `microllm2-f16.gguf` full precision, best quality, about 3.0 GB
* `microllm2-q8_0.gguf` 8-bit, near full quality, about 1.6 GB
* `microllm2-q4_k_m.gguf` 4-bit, smallest, about 0.9 GB, good for CPU and edge

Use with llama.cpp, LM Studio, or any GGUF runner:

```bash
# llama.cpp example
./llama-cli -m microllm2-q4_k_m.gguf -p "<|im_start|>user\nHello<|im_end|>\n<|im_start|>assistant\n" -n 128
```

The model is GPT2 architecture in GGUF, so make sure your runner supports GPT2 GGUF.

## Benchmark: MMLU

We include `mmlu_bench.py` so anyone can reproduce numbers. It runs 5 shot MMLU either with lm-evaluation-harness if you have it, or a lightweight direct logprob scorer that works without extra deps.

```bash
python mmlu_bench.py --shots 5
python mmlu_bench.py --shots 5 --limit 20  # quick smoke test
python mmlu_bench.py --subset philosophy,abstract_algebra
```

Measured result on 2026-08-09 with `mmlu_bench.py` on H100, 5 shot, 20 samples per subject, lightweight logprob scorer. Full 57 subjects, 1140 questions

**Overall: 318/1140 = 27.89 percent**

| Subject | Accuracy | Correct |
|---|---|---|
| abstract_algebra | 30.0% | 6/20 |
| anatomy | 25.0% | 5/20 |
| astronomy | 35.0% | 7/20 |
| business_ethics | 30.0% | 6/20 |
| clinical_knowledge | 45.0% | 9/20 |
| college_biology | 45.0% | 9/20 |
| college_chemistry | 15.0% | 3/20 |
| college_computer_science | 45.0% | 9/20 |
| college_mathematics | 35.0% | 7/20 |
| college_medicine | 30.0% | 6/20 |
| college_physics | 15.0% | 3/20 |
| computer_security | 30.0% | 6/20 |
| conceptual_physics | 5.0% | 1/20 |
| econometrics | 30.0% | 6/20 |
| electrical_engineering | 20.0% | 4/20 |
| elementary_mathematics | 30.0% | 6/20 |
| formal_logic | 10.0% | 2/20 |
| global_facts | 35.0% | 7/20 |
| high_school_biology | 45.0% | 9/20 |
| high_school_chemistry | 35.0% | 7/20 |
| high_school_computer_science | 35.0% | 7/20 |
| high_school_european_history | 20.0% | 4/20 |
| high_school_geography | 25.0% | 5/20 |
| high_school_government_and_politics | 20.0% | 4/20 |
| high_school_macroeconomics | 0.0% | 0/20 |
| high_school_mathematics | 20.0% | 4/20 |
| high_school_microeconomics | 35.0% | 7/20 |
| high_school_physics | 20.0% | 4/20 |
| high_school_psychology | 25.0% | 5/20 |
| high_school_statistics | 40.0% | 8/20 |
| high_school_us_history | 20.0% | 4/20 |
| high_school_world_history | 35.0% | 7/20 |
| human_aging | 40.0% | 8/20 |
| human_sexuality | 15.0% | 3/20 |
| international_law | 35.0% | 7/20 |
| jurisprudence | 40.0% | 8/20 |
| logical_fallacies | 35.0% | 7/20 |
| machine_learning | 50.0% | 10/20 |
| management | 20.0% | 4/20 |
| marketing | 35.0% | 7/20 |
| medical_genetics | 40.0% | 8/20 |
| miscellaneous | 30.0% | 6/20 |
| moral_disputes | 20.0% | 4/20 |
| moral_scenarios | 15.0% | 3/20 |
| nutrition | 20.0% | 4/20 |
| philosophy | 15.0% | 3/20 |
| prehistory | 25.0% | 5/20 |
| professional_accounting | 30.0% | 6/20 |
| professional_law | 35.0% | 7/20 |
| professional_medicine | 5.0% | 1/20 |
| professional_psychology | 45.0% | 9/20 |
| public_relations | 45.0% | 9/20 |
| security_studies | 25.0% | 5/20 |
| sociology | 20.0% | 4/20 |
| us_foreign_policy | 25.0% | 5/20 |
| virology | 25.0% | 5/20 |
| world_religions | 15.0% | 3/20 |

GPT2 XL base is around 24 to 26 percent on MMLU (random is 25 percent), so MicroLLM2 at 27.89 percent shows no regression and a small gain from distillation. Re run `python mmlu_bench.py --limit 20` to reproduce (set `HF_TOKEN` env to avoid Hub 429 rate limits for the full 57). Full results are also saved as `mmlu_results.json` in this repo.

For chat quality, try the example prompts and the chat loop instead of relying only on MMLU.

## Identity

The model is trained to answer like this:

* User: Who are you?
* Assistant: I am MicroLLM2, a chatbot created by Maximalist Labs.

* User: Who trained you?
* Assistant: I was trained by Maximalist Labs.

It will still admit it is based on GPT2 XL if you ask about its architecture, but it keeps the MicroLLM2 identity for who built and tuned it.

## Limitations

* 1024 context. Long conversations will need trimming. The chat loop keeps the last 12 turns for this reason.
* 1.5B size. It can be inconsistent on complex reasoning, math, or very recent facts.
* Can still hallucinate. Do not use for medical, legal, or high stakes advice without verification.
* English centric. Other languages will be weaker.
* Identity can be nudged with strong jailbreaks. If you find a failure, the `identity.py` pattern is in the repo to strengthen it.

## Files in this repo

* `model.safetensors` merged model, no adapter needed
* `config.json`, `tokenizer.json`, `vocab.json`, `merges.txt`, `tokenizer_config.json`
* `mmlu_bench.py` MMLU benchmark
* `Modelfile` for Ollama
* `microllm2-f16.gguf`, `microllm2-q8_0.gguf`, `microllm2-q4_k_m.gguf` GGUF weights

## Credits

Built by Maximalist Labs (MLVXN) on top of openai-community/gpt2-xl. Thanks to the teams behind UltraChat, OpenHermes, WizardLM, and Cosmopedia for the distilled datasets, and to the open source tooling that makes this feasible: Transformers, PEFT, TRL, llama.cpp, and Ollama.

If you use MicroLLM2, a mention of Maximalist Labs is appreciated but not required under Apache 2.0.