Text Generation
English
gpt
micro-gpt
Akshat-Dwivedi commited on
Commit
c92b111
·
verified ·
1 Parent(s): 4c29028

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +133 -0
README.md ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - roneneldan/TinyStories
5
+ - facebook/recycling_the_web
6
+ language:
7
+ - en
8
+ base_model:
9
+ - Akshat-Dwivedi/micro-gpt
10
+ pipeline_tag: text-generation
11
+ tags:
12
+ - gpt
13
+ - micro-gpt
14
+ ---
15
+
16
+ # Micro-GPT
17
+
18
+ **Micro-GPT** is a compact **50M parameter (50,039,520 exact)** dense, decoder-only GPT model pre-trained on **~1.028 Billion (1,027,551,376)** tokens with a token density of **~20.5 tokens per parameter**.
19
+
20
+ I pre-trained this model from scratch on a single **NVIDIA RTX 3050 6GB GPU**, keeping memory usage strictly under **~4.5 GB VRAM** while maintaining high throughput (~13,500 tokens/sec).
21
+
22
+ ---
23
+
24
+ ## 📐 Model Architecture Specs
25
+
26
+ Micro-GPT uses a modern decoder-only Transformer architecture with tied embeddings and VRAM-efficient design choices:
27
+
28
+ | Feature / Setting | Specification |
29
+ | :--- | :--- |
30
+ | **Model Type** | Dense Decoder-only GPT Transformer |
31
+ | **Total Parameters** | **50,039,520 (~50.0M)** |
32
+ | **Vocabulary Size** | 32,000 tokens (Byte-Level BPE with NFC normalization) |
33
+ | **Embeddings** | Shared token and output head weight matrix |
34
+ | **Context Length (`block_size`)** | 512 tokens |
35
+ | **Transformer Layers (`n_layers`)** | 12 blocks |
36
+ | **Embedding Dimension (`d_model`)** | 480 |
37
+ | **Attention Heads (`n_heads`)** | 8 heads (60 dimensions per head) |
38
+ | **Attention Type** | PyTorch Causal Scaled Dot-Product Attention |
39
+ | **Feed-Forward / MLP** | SwiGLU activation with a hidden dimension of 1,352 |
40
+ | **Normalization** | RMSNorm (pre-layer normalization) |
41
+ | **Positional Embeddings** | Learned absolute position embeddings |
42
+ | **Dropout** | 0.0 |
43
+
44
+ ---
45
+
46
+ ## ⚡ Training & GPU Setup (RTX 3050 6GB)
47
+
48
+ The training process was optimized to squeeze maximum speed and efficiency out of an RTX 3050 6GB:
49
+
50
+ - **Hardware**: Single NVIDIA RTX 3050 6GB GPU (peak VRAM usage ~4.5 GB).
51
+ - **Mixed Precision**: FP16 autocast paired with TF32 matrix multiplication for fast training on RTX Series cards.
52
+ - **VRAM Optimizations**:
53
+ - **Gradient Checkpointing**: Reduces memory footprint during backpropagation.
54
+ - **Chunked Loss Calculation**: Calculates cross-entropy loss in smaller steps of 256 tokens to prevent allocating large prediction arrays in VRAM.
55
+ - **Optimizer**: Fused AdamW with a weight decay of 0.1 on weight matrices (0.0 on biases and norm weights).
56
+ - **Learning Rate Schedule**: Cosine decay with a 2% linear warmup (1,220 warmup steps). Peak learning rate of 0.0003, gradually decaying to a minimum of 0.00003.
57
+ - **Batching & Throughput**:
58
+ - Micro-batch size: 4
59
+ - Gradient accumulation steps: 8
60
+ - Effective batch size: 32 samples (**16,384 tokens per optimizer step**)
61
+ - Training speed: **~13,000 to 13,600 tokens/second**
62
+ - **Total Training Steps**: 61,000 steps (~1.028 Billion tokens streamed).
63
+
64
+ ---
65
+
66
+ ## 📊 Dataset Summary
67
+
68
+ The training data was cleaned using a multi-core parallel cleaner and converted into a binary token stream.
69
+
70
+ ```bash
71
+ ================================================================================
72
+ DATASET SUMMARY & METRICS
73
+ ================================================================================
74
+ Total File Size : 4.66 GB
75
+ Total Output Dataset Rows : 3,077,324
76
+ Final Total Tokens : 1.0276 Billion (1,027,551,376)
77
+ Max Tokens per Sample : 1,024
78
+ --------------------------------------------------------------------------------
79
+ DATASET BREAKDOWN BY SOURCE:
80
+
81
+ 1. TinyStories:
82
+ • Output Dataset Row Share : 68.87%
83
+ • Token Count : 0.4496 Billion (449,583,331)
84
+ • Output Dataset Token Share : 43.75%
85
+
86
+ 2. Recycling The Web:
87
+ • Output Dataset Row Share : 31.13%
88
+ • Token Count : 0.5780 Billion (577,968,045)
89
+ • Output Dataset Token Share : 56.25%
90
+ ================================================================================
91
+ ```
92
+
93
+ ---
94
+
95
+ ## 📈 Pre-training Progress & Results
96
+
97
+ - **Final Loss**: `3.2339`
98
+ - **Final Perplexity**: `25.38`
99
+ - **Final Learning Rate**: `0.00003`
100
+
101
+ ```bash
102
+ [step 100/61,000] loss=9.5585 ppl=14164.71 lr=2.484e-05 grad=2.223 speed=13,251 tok/s eta=00d:20h:54m:57s
103
+ [step 1,000/61,000] loss=5.5282 ppl=251.69 lr=2.461e-04 grad=1.342 speed=12,949 tok/s eta=00d:20h:44m:22s
104
+ [step 10,000/61,000] loss=3.8061 ppl=44.97 lr=2.859e-04 grad=0.896 speed=13,574 tok/s eta=00d:17h:44m:11s
105
+ [step 20,000/61,000] loss=3.5895 ppl=36.22 lr=2.394e-04 grad=0.994 speed=13,300 tok/s eta=00d:14h:18m:23s
106
+ [step 30,000/61,000] loss=3.4506 ppl=31.52 lr=1.729e-04 grad=1.210 speed=13,061 tok/s eta=00d:10h:35m:47s
107
+ [step 40,000/61,000] loss=3.3449 ppl=28.36 lr=1.042e-04 grad=1.343 speed=13,531 tok/s eta=00d:07h:16m:23s
108
+ [step 50,000/61,000] loss=3.2720 ppl=26.36 lr=5.194e-05 grad=1.443 speed=13,064 tok/s eta=00d:03h:48m:17s
109
+ [step 60,000/61,000] loss=3.2304 ppl=25.29 lr=3.019e-05 grad=1.563 speed=13,572 tok/s eta=00d:00h:20m:27s
110
+ [step 61,000/61,000] loss=3.2339 ppl=25.38 lr=3.000e-05 grad=1.585 speed=13,556 tok/s eta=00d:00h:00m:00s
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 📁 Codebase Structure & Usage
116
+
117
+ - [`config.py`](file:///data/projects/sashvat-ai/micro-kimi-k3/micro-gpt/config.py): Single source of truth for model and training configurations.
118
+ - [`model.py`](file:///data/projects/sashvat-ai/micro-kimi-k3/micro-gpt/model.py): PyTorch implementation of the `GPT` model architecture.
119
+ - [`train.py`](file:///data/projects/sashvat-ai/micro-kimi-k3/micro-gpt/train.py): Main training loop with checkpointing and mixed-precision support.
120
+ - [`dataset.py`](file:///data/projects/sashvat-ai/micro-kimi-k3/micro-gpt/dataset.py): Local dataset cleaning, 32k BPE tokenizer training, and binary token streaming pipeline.
121
+
122
+ ### Running the Code
123
+
124
+ ```bash
125
+ # 1. Clean dataset, train 32k BPE tokenizer, and generate token stream
126
+ uv run micro-gpt/dataset.py
127
+
128
+ # 2. Start pre-training run
129
+ uv run micro-gpt/train.py
130
+
131
+ # 3. Resume training from checkpoint
132
+ uv run micro-gpt/train.py --resume
133
+ ```