dharun2049 commited on
Commit
212e2fd
·
verified ·
1 Parent(s): 32a6f10

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +112 -83
README.md CHANGED
@@ -1,13 +1,17 @@
1
  ---
2
  license: apache-2.0
3
  ---
4
- NanoGPT-X
5
- What This Is
 
 
6
  NanoGPT-X is a 15.6M parameter decoder-only transformer trained on WikiText-2.
7
  It integrates architectural innovations from DeepSeek, Meta, Google, Microsoft,
8
  Mistral, and Stanford into a single file that trains on a T4 GPU in under 5 hours.
9
- Architecture
10
- plain
 
 
11
  Input -> [Embed] -> [Block x 4] -> [RMSNorm] -> [LM Head] -> Output
12
  |
13
  v
@@ -17,89 +21,114 @@ Input -> [Embed] -> [Block x 4] -> [RMSNorm] -> [LM Head] -> Output
17
  Attn = MLA (default) | DiffAttn (optional)
18
  MLP = SwiGLU
19
  alpha = DeepNorm scaling = sqrt(2N) = 2.83
20
- Components
21
- Table
22
- Component Source What It Does
23
- MLA DeepSeek-V3 KV cache compression to 32-dim latent (8x smaller)
24
- MTP DeepSeek-V3 Predicts t+2, t+3 alongside t+1 for better efficiency
25
- DiffAttn Microsoft 2024 Signal-minus-noise attention filtering
26
- SWA Mistral Local attention window of 128 tokens
27
- RoPE+NTK Meta / CodeLLaMA Relative position with length extrapolation
28
- DeepNorm Microsoft Residual scaling for deep network stability
29
- RMSNorm LLaMA / PaLM Fast normalization without mean-centering
30
- QK-Norm Gemma 2 Pre-attention query/key normalization
31
- SwiGLU PaLM / LLaMA Gated FFN activation (8/3 ratio)
32
- Z-loss PaLM / Chinchilla Logit regularization preventing softmax drift
33
- Lion Google Brain 2023 Sign-momentum optimizer
34
- WSD DeepSeek / MiniMax Warmup-Stable-Decay LR schedule
35
- Flash Attention 2 Stanford O(1) memory fused attention kernel
36
- torch.compile PyTorch 2.0+ Graph compilation with operator fusion
37
- Specs
38
- Table
39
- Parameter Value
40
- Layers 4
41
- Embed dim 256
42
- Heads 4
43
- MLA latent 32
44
- FFN hidden 682
45
- Context 256
46
- Sliding window 128
47
- Vocab 50,257 (GPT-2 BPE)
48
- Params 15,586,816
49
- Checkpoint ~31 MB (FP16)
50
- Files
51
- plain
 
 
 
 
 
 
 
52
  train_goat_gpt_nano.py Training script (auto-downloads dataset)
53
  app.py HF Spaces deployment (Gradio UI)
54
  requirements.txt Dependencies
55
  goat_gpt_nano.ht Trained model output (generated)
56
- Build / Run
57
- Train
58
- bash
 
 
 
 
59
  pip install -r requirements.txt
60
  python train_goat_gpt_nano.py
 
 
61
  Outputs:
62
- goat_gpt_nano.ht -- deployable model
63
- goat_gpt_nano_gen.pt -- generation checkpoint
64
- best.pt -- best validation checkpoint
65
- ckpt_*.pt -- intermediate checkpoints
66
- Deploy (Hugging Face Spaces)
67
- Create Space -> Gradio SDK
68
- Upload:
69
- goat_gpt_nano.ht
70
- app.py
71
- requirements.txt
72
- Training Config
73
- Table
74
- Parameter Value
75
- Batch size 16
76
- Grad accum 2 (effective = 32)
77
- Max steps 5000
78
- Warmup 250
79
- Stable 3000
80
- Decay 1750
81
- LR 8e-4 -> 8e-5
82
- Optimizer Lion
83
- Precision FP16
84
- Compile default (T4-safe)
85
- Dataset
86
- Source: WikiText-2 (auto-downloaded from HuggingFace)
87
- Fallback chain: wikitext -> wikitext-2-raw-v1 -> Salesforce/wikitext -> local file
88
- Train tokens: ~2.4M
89
- Val tokens: ~250K
90
- GPU
91
- Recommended: T4 (Google Colab)
92
- Cost: ~5-10 compute units per run
93
- Time: ~3-5 hours
94
- VRAM: <2 GB
95
- Expected Results
96
- Table
97
- Metric Value
98
- Val loss ~3.5-4.7
99
- Val PPL ~33-110
100
- Throughput ~50-80K tok/s
101
- Notes
102
- TORCHINDUCTOR_MAX_AUTOTUNE_GEMM=0 set before torch import (T4 compatibility)
103
- torch.amp.GradScaler('cuda') and torch.amp.autocast('cuda') used (PyTorch 2.6+)
104
- trust_remote_code removed (datasets library deprecated)
105
- Warning suppression active for clean logs
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+ # NanoGPT-X
5
+
6
+ ## What This Is
7
+
8
  NanoGPT-X is a 15.6M parameter decoder-only transformer trained on WikiText-2.
9
  It integrates architectural innovations from DeepSeek, Meta, Google, Microsoft,
10
  Mistral, and Stanford into a single file that trains on a T4 GPU in under 5 hours.
11
+
12
+ ## Architecture
13
+
14
+ ```
15
  Input -> [Embed] -> [Block x 4] -> [RMSNorm] -> [LM Head] -> Output
16
  |
17
  v
 
21
  Attn = MLA (default) | DiffAttn (optional)
22
  MLP = SwiGLU
23
  alpha = DeepNorm scaling = sqrt(2N) = 2.83
24
+ ```
25
+
26
+ ## Components
27
+
28
+ | Component | Source | What It Does |
29
+ |-----------|--------|--------------|
30
+ | MLA | DeepSeek-V3 | KV cache compression to 32-dim latent (8x smaller) |
31
+ | MTP | DeepSeek-V3 | Predicts t+2, t+3 alongside t+1 for better efficiency |
32
+ | DiffAttn | Microsoft 2024 | Signal-minus-noise attention filtering |
33
+ | SWA | Mistral | Local attention window of 128 tokens |
34
+ | RoPE+NTK | Meta / CodeLLaMA | Relative position with length extrapolation |
35
+ | DeepNorm | Microsoft | Residual scaling for deep network stability |
36
+ | RMSNorm | LLaMA / PaLM | Fast normalization without mean-centering |
37
+ | QK-Norm | Gemma 2 | Pre-attention query/key normalization |
38
+ | SwiGLU | PaLM / LLaMA | Gated FFN activation (8/3 ratio) |
39
+ | Z-loss | PaLM / Chinchilla | Logit regularization preventing softmax drift |
40
+ | Lion | Google Brain 2023 | Sign-momentum optimizer |
41
+ | WSD | DeepSeek / MiniMax | Warmup-Stable-Decay LR schedule |
42
+ | Flash Attention 2 | Stanford | O(1) memory fused attention kernel |
43
+ | torch.compile | PyTorch 2.0+ | Graph compilation with operator fusion |
44
+
45
+ ## Specs
46
+
47
+ | Parameter | Value |
48
+ |-----------|-------|
49
+ | Layers | 4 |
50
+ | Embed dim | 256 |
51
+ | Heads | 4 |
52
+ | MLA latent | 32 |
53
+ | FFN hidden | 682 |
54
+ | Context | 256 |
55
+ | Sliding window | 128 |
56
+ | Vocab | 50,257 (GPT-2 BPE) |
57
+ | Params | 15,586,816 |
58
+ | Checkpoint | ~31 MB (FP16) |
59
+
60
+ ## Files
61
+
62
+ ```
63
  train_goat_gpt_nano.py Training script (auto-downloads dataset)
64
  app.py HF Spaces deployment (Gradio UI)
65
  requirements.txt Dependencies
66
  goat_gpt_nano.ht Trained model output (generated)
67
+ ```
68
+
69
+ ## Build / Run
70
+
71
+ ### Train
72
+
73
+ ```bash
74
  pip install -r requirements.txt
75
  python train_goat_gpt_nano.py
76
+ ```
77
+
78
  Outputs:
79
+ - `goat_gpt_nano.ht` -- deployable model
80
+ - `goat_gpt_nano_gen.pt` -- generation checkpoint
81
+ - `best.pt` -- best validation checkpoint
82
+ - `ckpt_*.pt` -- intermediate checkpoints
83
+
84
+ ### Deploy (Hugging Face Spaces)
85
+
86
+ 1. Create Space -> Gradio SDK
87
+ 2. Upload:
88
+ - `goat_gpt_nano.ht`
89
+ - `app.py`
90
+ - `requirements.txt`
91
+
92
+ ## Training Config
93
+
94
+ | Parameter | Value |
95
+ |-----------|-------|
96
+ | Batch size | 16 |
97
+ | Grad accum | 2 (effective = 32) |
98
+ | Max steps | 5000 |
99
+ | Warmup | 250 |
100
+ | Stable | 3000 |
101
+ | Decay | 1750 |
102
+ | LR | 8e-4 -> 8e-5 |
103
+ | Optimizer | Lion |
104
+ | Precision | FP16 |
105
+ | Compile | default (T4-safe) |
106
+
107
+ ## Dataset
108
+
109
+ - Source: WikiText-2 (auto-downloaded from HuggingFace)
110
+ - Fallback chain: wikitext -> wikitext-2-raw-v1 -> Salesforce/wikitext -> local file
111
+ - Train tokens: ~2.4M
112
+ - Val tokens: ~250K
113
+
114
+ ## GPU
115
+
116
+ - Recommended: T4 (Google Colab)
117
+ - Cost: ~5-10 compute units per run
118
+ - Time: ~3-5 hours
119
+ - VRAM: <2 GB
120
+
121
+ ## Expected Results
122
+
123
+ | Metric | Value |
124
+ |--------|-------|
125
+ | Val loss | ~3.5-4.7 |
126
+ | Val PPL | ~33-110 |
127
+ | Throughput | ~50-80K tok/s |
128
+
129
+ ## Notes
130
+
131
+ - `TORCHINDUCTOR_MAX_AUTOTUNE_GEMM=0` set before torch import (T4 compatibility)
132
+ - `torch.amp.GradScaler('cuda')` and `torch.amp.autocast('cuda')` used (PyTorch 2.6+)
133
+ - `trust_remote_code` removed (datasets library deprecated)
134
+ - Warning suppression active for clean logs