Update README.md
Browse files
README.md
CHANGED
|
@@ -1,13 +1,17 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
-
NanoGPT-X
|
| 5 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
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 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|