Nekochu commited on
Commit
403ef1e
·
verified ·
1 Parent(s): 7f43f1d

Initial commit

Browse files
README.md ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: karpathy/nanochat-d34
4
+ language:
5
+ - en
6
+ tags:
7
+ - nanochat
8
+ - text-generation
9
+ - karpathy
10
+ - single-gpu
11
+ - rtx-5090
12
+ datasets:
13
+ - HuggingFaceFW/finepdfs_edu_50BT-dclm_30BT-fineweb_edu_20BT-shuffled
14
+ - HuggingFaceTB/smol-smoltalk
15
+ - cais/mmlu
16
+ - ai2_arc
17
+ - openai/gsm8k
18
+ pipeline_tag: text-generation
19
+ model-index:
20
+ - name: nanochat-d24
21
+ results:
22
+ - task:
23
+ type: text-generation
24
+ dataset:
25
+ name: GSM8K
26
+ type: openai/gsm8k
27
+ metrics:
28
+ - name: pass@1
29
+ type: accuracy
30
+ value: 0.1645
31
+ verified: false
32
+ ---
33
+
34
+ # nanochat-d24
35
+
36
+ 1.38B param, Pretrain+SFT+RL (GRPO/GSM8K) on a **single RTX 5090** (32GB). Ported from [Karpathy's nanochat](https://github.com/karpathy/nanochat) ([`6ed7d1d`](https://github.com/karpathy/nanochat/commit/6ed7d1d82cee16c2e26f45d559ad3338447a6c1b), Mar 9 2026) into a [single ~2K line Python file](https://gist.github.com/Katehuuh/34c631b9a9ca5e930eba3903937d01e9/8ccb21a677b1da1682fa2a66e6d7ecaaaf30de93).
37
+
38
+ ## Changelog
39
+
40
+ - **2026-03-23**: Initial release
41
+
42
+ ## Evaluation Results
43
+
44
+ <!-- ChatCORE* = without HumanEval (5/6 tasks). val_bpb = base model metric only. -->
45
+
46
+ | Benchmark | Base (step 24K) | SFT (step 1942) | RL (step 300) | d20 SFT (official) | d30 (official) |
47
+ |-----------|:-:|:-:|:-:|:-:|:-:|
48
+ | ARC-Easy | 23.9% | 52.6% | **52.9%** | 38.8% | ~70% |
49
+ | ARC-Challenge | 25.0% | 42.5% | **41.9%** | 28.1% | - |
50
+ | MMLU | 23.6% | 35.3% | **35.6%** | 31.5% | ~40% |
51
+ | GSM8K (pass@1) | 0.0% | 10.2% | **16.5%** | 4.6% | ~20% |
52
+ | SpellingBee | 0.0% | 79.7% | **87.1%** | N/A | - |
53
+ | **ChatCORE**\* | -0.6% | 32.7% | **35.5%** | 8.8% | - |
54
+ | val_bpb | 0.830 | - | - | - | 0.705 |
55
+
56
+ *\*ChatCORE without HumanEval (5/6 tasks). Official d20 SFT from [Discussion #1](https://github.com/karpathy/nanochat/discussions/1). d30 approximate, community reports.*
57
+
58
+ ## Architecture
59
+
60
+ 24 layers, 1536 hidden dim, 12 MHA heads (head_dim=128), 32K BPE vocab, 2048 context. RoPE (theta=100k), QK-norm, unweighted RMSNorm, untied embeddings, ReLU² activation, logit softcap 15.0, value embeddings on alternating layers (~604M params at near-zero FLOPs), per-layer residual scalars, smear mechanism, backout mechanism, cuDNN SDPA full context.
61
+
62
+ ### Differences from official nanochat d24
63
+
64
+ | Feature | Official (8xH100) | This model (1xRTX5090) |
65
+ |---------|-------------------|------------------------|
66
+ | Window pattern | SSSL | L (full context) |
67
+ | VE gate channels | 32 | 12 |
68
+ | Smear/Backout | Not used | Active |
69
+ | Attention | Flash Attention 3 | cuDNN SDPA |
70
+ | FP8 | Optional | Default (pretraining) |
71
+ | Pretraining data | [NVIDIA ClimbMix](https://huggingface.co/datasets/nvidia/Nemotron-ClimbMix) | [finepdfs_edu/dclm/fineweb_edu](https://huggingface.co/datasets/HuggingFaceFW/finepdfs_edu_50BT-dclm_30BT-fineweb_edu_20BT-shuffled) (8/100 shards) |
72
+
73
+ ## Training
74
+
75
+ | Stage | Data | Duration | Steps | Details |
76
+ |-------|------|----------|-------|---------|
77
+ | **Pretrain** | see above | ~3.8 days | 29,232 | FP8, MuonAdamW, grad ckpt, B=4x32 |
78
+ | **SFT** | SmolTalk 460K + MMLUx3 + SimpleSpelling 200K + SpellingBee 80K + GSM8Kx4 | ~7.5h | 1,942 | BF16, bestfit packing, torch.compile |
79
+ | **RL** | GSM8K (16 samples/question) | ~5h | 300 | BF16, cosine LR (T_max=400), KV-cache |
80
+
81
+ ![Training Pipeline](https://i.imgur.com/6Mg7Otx.png)
82
+
83
+ Notes:
84
+ - Single-GPU RL needs cosine LR decay to avoid policy collapse (linear LR diverges after step 400)
85
+ - FP8 on SM120 needs a 1-line Triton inductor patch (`getattr(binary.metadata, 'cluster_dims', (1, 1, 1))`)
86
+ - Entropy bonus (GTPO-style) made collapse worse, gradient noise is the real issue
87
+
88
+ ## Usage
89
+
90
+ ```python
91
+ from safetensors.torch import load_file
92
+ state_dict = load_file("model.safetensors")
93
+ ```
94
+
95
+ Interactive chat ([script](https://gist.github.com/Katehuuh/34c631b9a9ca5e930eba3903937d01e9/8ccb21a677b1da1682fa2a66e6d7ecaaaf30de93)):
96
+ ```bash
97
+ set TRAIN_STAGE=rl
98
+ set NANOCHAT_FP8=0
99
+ python nanochat_gpt-1384M.py --chat
100
+ ```
101
+
102
+ Root = RL (step 300, best pass@4). `pt/` and `sft/` folders have base and SFT checkpoints.
103
+
104
+ ## Chat Format
105
+
106
+ ```
107
+ <|bos|><|user_start|>If a store sells 3 apples at $2 each and 5 oranges at $1 each, what is the total cost?<|user_end|><|assistant_start|>The cost of 3 apples is 3 * $2 = $<|python_start|>3*2<|python_end|><|output_start|>6<|output_end|>6.
108
+ The cost of 5 oranges is 5 * $1 = $<|python_start|>5*1<|python_end|><|output_start|>5<|output_end|>5.
109
+ The total cost is $6 + $5 = $<|python_start|>6+5<|python_end|><|output_start|>11<|output_end|>11.
110
+ #### 11<|assistant_end|>
111
+ ```
112
+
113
+ ## Citation
114
+
115
+ ```bibtex
116
+ @misc{nanochat,
117
+ author = {Andrej Karpathy},
118
+ title = {nanochat: The best ChatGPT that $100 can buy},
119
+ year = {2025},
120
+ publisher = {GitHub},
121
+ url = {https://github.com/karpathy/nanochat}
122
+ }
123
+ ```
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "NanoChatForCausalLM"
4
+ ],
5
+ "model_type": "nanochat",
6
+ "hidden_size": 1536,
7
+ "num_attention_heads": 12,
8
+ "num_key_value_heads": 12,
9
+ "num_hidden_layers": 24,
10
+ "intermediate_size": 6144,
11
+ "hidden_act": "relu2",
12
+ "vocab_size": 32768,
13
+ "max_position_embeddings": 2048,
14
+ "rms_norm_eps": 1e-06,
15
+ "rope_parameters": {
16
+ "rope_theta": 100000.0,
17
+ "rope_type": "default"
18
+ },
19
+ "tie_word_embeddings": false,
20
+ "final_logit_softcapping": 15.0,
21
+ "torch_dtype": "float16",
22
+ "ve_gate_channels": 12
23
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ccc646e6fe7d7b0fd9708b6d82676a5db7c8074cb1dc94bcc125ab683c558261
3
+ size 5536507416
pt/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:510db0d091bd0495834be5f3229dd89d42985568dcb3e47edd4898af2601bc63
3
+ size 4227884224
sft/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6be0fac8fb4ebeec8c89c0d5ed5901ed30414cd97d1e5f49a4566a664ace350d
3
+ size 5536507416
special_tokens_map.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|bos|>",
3
+ "eos_token": "<|assistant_end|>",
4
+ "additional_special_tokens": [
5
+ "<|user_start|>",
6
+ "<|user_end|>",
7
+ "<|assistant_start|>",
8
+ "<|assistant_end|>",
9
+ "<|python_start|>",
10
+ "<|python_end|>",
11
+ "<|output_start|>",
12
+ "<|output_end|>"
13
+ ]
14
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "tokenizer_class": "PreTrainedTokenizerFast",
3
+ "model_max_length": 2048,
4
+ "bos_token": "<|bos|>",
5
+ "eos_token": "<|assistant_end|>",
6
+ "chat_template": "{% for message in messages %}{% if message['role'] == 'user' %}<|user_start|>{{ message['content'] }}<|user_end|>{% elif message['role'] == 'assistant' %}<|assistant_start|>{{ message['content'] }}<|assistant_end|>{% endif %}{% endfor %}<|assistant_start|>"
7
+ }