Text Generation
PyTorch
English
custom-code
math
agmadaasa commited on
Commit
ab1c5b8
·
1 Parent(s): 7f20174

Publish NanoMath v1.1 checkpoint

Browse files
Files changed (4) hide show
  1. README.md +63 -34
  2. model_weights.pth +2 -2
  3. token.model +2 -2
  4. token.vocab +0 -0
README.md CHANGED
@@ -5,62 +5,91 @@ datasets:
5
  - openai/gsm8k
6
  language:
7
  - en
 
 
 
 
 
8
  ---
9
 
10
- # NanoMath: A 136M Parameter Math-Reasoning Language Model
11
 
12
- ## 🚀 Model Overview
13
 
14
- NanoMath is a custom-built, GPT-style Large Language Model explicitly designed to solve mathematical problems using Chain-of-Thought (CoT) reasoning. Built entirely from scratch in PyTorch, the primary goal of this model is to demonstrate an end-to-end language modeling pipeline, helping to understand transformer architectures, training optimizations, and data processing bottlenecks.
15
 
16
- ## 🛠️ Model Details
 
17
 
18
- * **Architecture:** Decoder-only Transformer (GPT-style) built from scratch.
19
- * **Parameters:** 136 Million.
20
- * **Training Compute:** Trained for 12 hours on a single NVIDIA T4 GPU via Kaggle.
21
- * **Tokenizer:** Custom Byte-Pair Encoding (BPE) tokenizer trained using `sentencepiece` to explicitly recognize mathematical operators and digits efficiently.
22
 
23
- ## 📚 Training Data
24
 
25
- The model was trained on approximately 1 Billion tokens. The dataset is a combination of high-quality math datasets and procedural generations:
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- * **Synthetic Basic Math:** Hundreds of thousands of synthetic arithmetic problems generated via a custom Python script.
28
- * **GSM8K:** Gold-standard grade school math word problems.
29
- * **NuminaMath:** Large-scale math reasoning problems.
30
 
31
- To teach the model step-by-step reasoning, the data enforces a strict `<|thinking|>` and `<|answer|>` formatting structure.
32
 
33
- ## 🧠 Performance and Capabilities
34
 
35
- NanoMath was trained to "think before it speaks". It successfully generates intermediate reasoning steps and performs well on basic arithmetic tasks.
36
 
37
- **Successes:**
38
 
39
- * The model successfully executes multi-step algorithmic logic like partial products.
40
- * It correctly utilizes long division from left to right.
 
41
 
42
- ## ⚠️ Limitations
43
 
44
- Given its small scale (136M parameters) and heavily constrained training time (12 hours), the model exhibits standard LLM hallucinations on complex operations.
 
 
 
 
 
 
 
 
45
 
46
- * **Multi-Step Borrowing:** It sometimes struggles to carry values perfectly across complex mathematical borrowing steps.
47
- * **Logic Routing:** It can lose track of logical routing in word problems, leading to hallucinated results.
48
 
49
- ## 💻 How to Use
50
 
51
- Because this is a custom model architecture built from scratch, you cannot use the standard HuggingFace `transformers` library out-of-the-box. Instead, download the weights and run inference using the codebase provided in the linked GitHub repository.
52
 
53
- 1. Download the `model_weights.pth` and `token.model` files from this repository.
54
- 2. Clone the [NanoMath GitHub repository](https://github.com/agmada-asa/NanoMath) and install the dependencies:
55
- ```bash
56
- pip install -r requirements.txt
 
 
 
 
57
 
58
- ```
59
 
 
 
 
60
 
61
- 3. Place the downloaded `.pth` and `.model` files into the `build/` directory of the cloned repository.
62
- 4. Run the interactive chat CLI:
63
  ```bash
64
- python chat.py
 
 
 
 
65
 
66
- ```
 
5
  - openai/gsm8k
6
  language:
7
  - en
8
+ pipeline_tag: text-generation
9
+ library_name: pytorch
10
+ tags:
11
+ - custom-code
12
+ - math
13
  ---
14
 
15
+ # NanoMath v1.1
16
 
17
+ NanoMath is a compact 113.27M-parameter decoder-only language model for maths reasoning. Its architecture and inference code are implemented from scratch in PyTorch rather than through Transformers. Despite its size, v1.1 produces readable multi-step solutions and solved four of six mixed prompts in the current spot check.
18
 
19
+ This repository contains two files that must be used together:
20
 
21
+ - `model_weights.pth` is the v1.1 inference checkpoint.
22
+ - `token.model` is its 16,384-piece SentencePiece tokenizer.
23
 
24
+ The [NanoMath source repository](https://github.com/agmada-asa/NanoMath) contains the matching model code, training pipeline, and local chat CLI.
 
 
 
25
 
26
+ ## Architecture
27
 
28
+ | Setting | Value |
29
+ |---|---:|
30
+ | Parameters | 113.27M |
31
+ | Decoder layers | 16 |
32
+ | Model width | 768 |
33
+ | Query heads | 12 |
34
+ | Key-value heads | 4 |
35
+ | Context length | 1,024 |
36
+ | Vocabulary | 16,384 |
37
+ | Position encoding | RoPE |
38
+ | Normalization | RMSNorm |
39
+ | MLP | SwiGLU |
40
 
41
+ The model uses grouped-query attention, tied token and output embeddings, and bias-free projections. The checkpoint stores the full model configuration and completed optimizer step.
 
 
42
 
43
+ ## Training record
44
 
45
+ The v1.1 checkpoint completed optimizer step 5,999 on two NVIDIA T4 GPUs. Its packed training build contains 641,276,817 train tokens and 13,076,780 validation tokens from GSM8K, NuminaMath, and generated maths problems.
46
 
47
+ Training weights prompt tokens at 0, reasoning tokens at 1, and final-answer tokens at 3. This changes the loss calculation only. It does not add a calculator or symbolic solver at inference time.
48
 
49
+ Checkpoint SHA-256:
50
 
51
+ ```text
52
+ f13f762b64ec710221575b6f5d4dae05f6105d8234b8a53a35ea7b40680f6dca
53
+ ```
54
 
55
+ ## Run it
56
 
57
+ ```bash
58
+ git clone https://github.com/agmada-asa/NanoMath.git
59
+ cd NanoMath
60
+ python3 -m venv .venv
61
+ source .venv/bin/activate
62
+ pip install -r requirements.txt
63
+ hf download agmadaasa/NanoMath model_weights.pth token.model --local-dir build
64
+ python chat.py "What is 84 / 7?"
65
+ ```
66
 
67
+ The model requires the custom classes in the source repository. `AutoModel` and the standard Transformers text-generation pipeline cannot load this checkpoint.
 
68
 
69
+ ## Observed outputs
70
 
71
+ The following results came from greedy decoding with a 200-token limit. The model answered four of the six prompts correctly. This is a small, reproducible behavior sample, not an accuracy score.
72
 
73
+ | Prompt | Output answer | Expected | Result |
74
+ |---|---|---:|---|
75
+ | `What is 84 / 7?` | `12` | 12 | Correct |
76
+ | `Calculate 57 + 68.` | `89` | 125 | Incorrect |
77
+ | `What is 17 * 24?` | `408` | 408 | Correct |
78
+ | `A box has 15 pencils. Six are removed and four are added. How many pencils are in the box?` | `13` | 13 | Correct |
79
+ | `Solve 3x + 5 = 20.` | `5` | 5 | Correct |
80
+ | `Which is larger, 5/8 or 2/3?` | Did not finish a valid comparison | 2/3 | Incorrect |
81
 
82
+ Producing coherent solution structure across division, multiplication, algebra, and a word problem is a solid result for a model of this size. NanoMath can still produce plausible reasoning with a wrong answer, so its arithmetic should be checked before use.
83
 
84
+ ## Versions
85
+
86
+ `main` and the `v1.1` tag contain the current model. The original 136.18M checkpoint and its 32,768-piece tokenizer remain available under the `v1.0` tag.
87
 
 
 
88
  ```bash
89
+ hf download agmadaasa/NanoMath \
90
+ model_weights.pth token.model \
91
+ --revision v1.0 \
92
+ --local-dir build
93
+ ```
94
 
95
+ Do not mix a checkpoint from one version with the tokenizer from another.
model_weights.pth CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c79f03dfa6e78b4d8597a8e6142c72ca7e5d98c2d621dcefc4cddff2fe783dda
3
- size 544772107
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f13f762b64ec710221575b6f5d4dae05f6105d8234b8a53a35ea7b40680f6dca
3
+ size 503449776
token.model CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:05be0ac2a347b489489be9babd47335dc01471494ca0b1992f01bc33176cb264
3
- size 782378
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c729c9cd6b7fafe1073e0ad71c2d064d52c59b8b13b91952aff34edef8e8bdb5
3
+ size 504281
token.vocab CHANGED
The diff for this file is too large to render. See raw diff