File size: 6,717 Bytes
084b790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79032f8
 
084b790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79032f8
084b790
 
 
79032f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
084b790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79032f8
 
 
 
 
 
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
---
license: apache-2.0
language:
- en
library_name: pytorch
pipeline_tag: text-generation
tags:
- mathematics
- recurrent-transformer
- custom-code
- sentencepiece
datasets:
- openai/gsm8k
- AI-MO/NuminaMath-1.5
- EleutherAI/asdiv
---

# NanoMath-R

NanoMath-R is a math model with 103.83 million parameters, written from scratch
in PyTorch. It has 16 stored Transformer decoder blocks and applies the same stack
twice, giving 32 block applications per token without storing a second stack of
weights.

The release is intended for research on small models and direct integer arithmetic. It
is not a general assistant and it is not a dependable solver for word problems,
fractions, algebra, proofs, or calculations where an error could cause harm.

## Model details

| Setting | Value |
|---|---:|
| Stored parameters | 103,834,368 |
| Physical decoder blocks | 16 |
| Recurrent passes | 2 |
| Unrolled depth | 32 |
| Width | 768 |
| Query heads | 12 |
| Key and value heads | 4 |
| Context length | 1,024 tokens |
| Vocabulary | 4,096 SentencePiece tokens |
| Position encoding | RoPE |
| Normalization | RMSNorm |
| MLP | SwiGLU |

The model uses grouped query attention and tied input and output embeddings.
Its projections have no bias, and its residual projections were initialized to
zero at the start of training.

## Files

- `model_weights.pth` contains the weights, model configuration, and training
  metadata.
- `token.model` is the matching SentencePiece tokenizer.
- `model_config.json` and `training_summary.json` expose the main checkpoint
  metadata without loading PyTorch.
- `benchmark_results.json` records the release checks.
- `draft_heads/depth16_mlp.pt` is an optional draft head for faster greedy
  decoding (see below). It does not change the model's answers.
- `checksums.sha256` covers every published model file.
- `LICENSE` contains the Apache License 2.0 terms.

This checkpoint is incompatible with the NanoMath v1.0, v1.1, V2, and V3
tokenizers.

## Run it

The checkpoint uses the custom classes in the
[NanoMath-R source repository](https://github.com/agmada-asa/NanoMath-R). It
does not load through `AutoModelForCausalLM` or the standard Transformers text
generation pipeline.

```bash
git clone https://github.com/agmada-asa/NanoMath-R.git
cd NanoMath-R
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
hf download agmadaasa/NanoMath-R model_weights.pth token.model draft_heads/depth16_mlp.pt --local-dir build
python3 scripts/chat.py "What is 84 / 7?"
```

## Faster decoding with the draft head

`draft_heads/depth16_mlp.pt` is a 2.4M-parameter head trained against this
frozen checkpoint. In self-speculative decoding, the model's first recurrent
pass drafts several tokens and the second pass checks them all at once. The
head turns the first pass's hidden state into better drafts, so more of them
are kept. Every kept token is still the full model's greedy choice, so the
head changes speed, not answers.

The head agrees with the full model on 96.6% of generated tokens for 300
synthetic evaluation questions and 92.5% for 300 SVAMP questions, against
93.3% and 85.9% for the plain first pass. On an M3 Pro MacBook Pro with
PyTorch on MPS, it gave 1.43× on the benchmark prompts, 1.33× on the synthetic
sample and 1.23× on SVAMP over ordinary decoding. With the source repository's
MLX backend, the same setup reaches about 300 tokens per second.

`chat.py` uses the head automatically when it is at
`build/draft_heads/depth16_mlp.pt`. The training method and measurements are
in `INFERENCE.md` in the source repository. The head fits only this
checkpoint; its metadata records the checkpoint's SHA-256.

The prompt format is:

```text
<|user|> What is 84 / 7? <|end|>
<|assistant|>
```

Greedy decoding is the default. The model normally emits a reasoning span,
then `<|answer|>`, a numeric answer, and `<|end|>`.

## Evaluation

Fresh release checks used greedy decoding, two recurrent passes, a KV cache,
FP16 on Apple MPS, and at most 384 new tokens.

| Evaluation | Examples | Macro exact match | Micro exact match | Malformed |
|---|---:|---:|---:|---:|
| Synthetic math reserved for evaluation | 50 | 63.27% | 66.00% | 2.00% |
| SVAMP | 40 | 22.50% | 22.50% | 0.00% |
| NanoMath v1.1 continuity prompts | 6 | 50.00% | 50.00% | 0.00% |

The clearest strength is direct integer arithmetic. On the synthetic sample it
scored 8/8 addition, 8/8 subtraction, 7/7 multiplication, and 7/7 exact
division. The same sample scored 2/7 linear equations, 1/7 word problems, and
0/6 fraction questions. These samples are small. They describe observed
behavior, not a guarantee.

## Training

The packed training stream contains 233,896,960 token positions and 1,066,609
accepted documents after length filtering. Its source counts are:

| Source | Documents |
|---|---:|
| Verified structural arithmetic | 750,000 |
| NuminaMath | 190,209 |
| Generated language curriculum | 117,487 |
| GSM8K | 7,404 |
| ASDiv | 1,509 |

The run completed 6,000 optimizer steps and processed 393,216,000 token
positions, about 1.68 passes through the packed corpus. It used two NVIDIA T4
GPUs, FP16, sequences of 1,024 tokens, attention isolated between documents,
loss weights based on message role, and activation checkpointing. Training
took 41,623.7 wall seconds, or 23.12 hours of accelerator use. The checkpoint
records validation loss 0.129966.

Prompt tokens had weight 0, reasoning tokens weight 1, and answer tokens weight
3. Every packed document reset its positions and could not attend to another
document in the same block.

## Limits and intended use

Good uses include studying recurrent depth, reproducing the reported
experiments on small models, and testing direct arithmetic prompts with independent
verification.

NanoMath-R is not reliable for financial, medical, engineering, or other
calculations where an error could cause harm. It can produce fluent reasoning
with the wrong final number. Training primarily used English, the context
window is 1,024 tokens, and the release represents one training seed. The model
has not received a broad safety or bias evaluation. It is also outside its
intended scope for coding, factual retrieval, unrestricted chat,
formal proof, and advanced mathematics.

The source datasets retain their own licenses and terms. Users should review
those terms before redistributing derived artifacts.

## Integrity

Checkpoint SHA-256:

```text
6d251ab0c7595023006f7975b05436676311c18f17c8df608dc44a3e24f937b2
```

Tokenizer SHA-256:

```text
195e6efabd0a9dc238f04c83807d4e2cb79bd0270866773ad0b71a44c3794ba1
```

Draft head SHA-256:

```text
a9f7869487ed8f5de8b1314b0be80c8fcb788ac8e7b465c7a34edd66f56d7f1e
```