REZIRETSA commited on
Commit
0874d20
·
verified ·
1 Parent(s): b6dbdde

Add workspace README (SFT/LoRA recipes)

Browse files
Files changed (1) hide show
  1. README.md +30 -303
README.md CHANGED
@@ -1,311 +1,38 @@
1
- # LUNA - 100M Parameter LLM from Scratch
2
-
3
- Custom ~100M parameter GPT model (Pythia-like architecture) pretrained on 4.5B tokens of clean English text.
4
-
5
- ## Quick Start (RunPod / Cloud GPU)
6
-
7
- ### 1. Clone & Install (one command)
8
-
9
- ```bash
10
- git clone https://huggingface.co/spaces/ASTERIZER/LUNA /workspace/LUNA && \
11
- cd /workspace/LUNA && \
12
- pip install -q -r requirements.txt
13
- ```
14
-
15
- ### 2. Get Dataset + Train (one command)
16
-
17
- The dataset (~4.5B tokens) is hosted as a zip at [ASTERIZER/Luna_Dataset](https://huggingface.co/datasets/ASTERIZER/Luna_Dataset). The script downloads, extracts, and starts training automatically.
18
-
19
- **From HuggingFace (recommended):**
20
- ```bash
21
- bash setup_and_train.sh huggingface ASTERIZER/Luna_Dataset
22
- ```
23
-
24
- **From Google Drive:**
25
- ```bash
26
- bash setup_and_train.sh gdrive YOUR_GDRIVE_FOLDER_ID
27
- ```
28
-
29
- **Smoke test (10M tokens only):**
30
- ```bash
31
- bash setup_and_train.sh huggingface ASTERIZER/Luna_Dataset 10000000
32
- ```
33
-
34
- That's it. The script auto-detects your GPU, VRAM, RAM, CPU cores and configures everything for maximum utilization.
35
-
36
- ---
37
-
38
- ## How It Works
39
-
40
- ### Auto vs Manual Config
41
-
42
- All hyperparameters live in `train_config.yaml`:
43
-
44
- ```yaml
45
- auto_config: true # auto-detect everything from hardware
46
- auto_config: false # use exact values below, no overrides
47
- ```
48
-
49
- When `auto_config: true` (default), the trainer:
50
- - **Probes VRAM** via binary search to find max micro_batch_size (82% safety)
51
- - **Sets grad_accum** to hit the target global_batch_size
52
- - **Picks precision** (bf16 on Ampere+, fp16 otherwise)
53
- - **Scales workers** to half your CPU cores, capped by RAM
54
- - **Enables torch.compile** if Triton is available (Linux)
55
-
56
- When `auto_config: false`, every value in the YAML is used exactly as-is.
57
-
58
- ### CLI Overrides
59
-
60
- Any config value can be overridden from the command line:
61
-
62
- ```bash
63
- python train.py --config train_config.yaml --data_path /data/litdata --max_tokens 100000000
64
- ```
65
-
66
- Priority: CLI args > train_config.yaml > auto-detection
67
-
68
  ---
69
-
70
- ## Dataset
71
-
72
- - **4,515,286,950 tokens** (4.5B) in 270 binary chunks
73
- - Sources: Wikipedia, FineWeb-Edu, OpenWebText (deduplicated, cleaned)
74
- - Format: LitData binary (int32, block_size=1025, TokensLoader)
75
- - Tokenizer: EleutherAI/pythia-160m (50,254 vocab)
76
-
77
- ## Model Architecture
78
-
79
- | Parameter | Value |
80
- |-----------|-------|
81
- | Layers | 10 |
82
- | Hidden dim | 768 |
83
- | Attention heads | 12 |
84
- | Vocab size | 50,304 (padded) |
85
- | Context length | 1,024 |
86
- | Total params | ~109M (70M unique, tied embeddings) |
87
- | Rotary % | 25% |
88
-
89
- ## File Structure
90
-
91
- ```
92
- LUNA/
93
- train.py # Main training script (config-driven, auto-detects hardware)
94
- train_config.yaml # All hyperparameters (auto_config: true/false)
95
- fetch_data.py # Downloads dataset from HuggingFace / GDrive
96
- setup_and_train.sh # One-command cloud entrypoint
97
- benchmark_runpod.py # Local benchmark + RunPod cost calculator
98
- requirements.txt # Python dependencies
99
- Base/
100
- checkpoints/EleutherAI/pythia-160m/ # Tokenizer files
101
- configs/ # Legacy litgpt YAML configs (reference only)
102
- scripts/ # Data preprocessing scripts
103
- ```
104
-
105
- ## Estimated Training Times (RunPod)
106
-
107
- | GPU | $/hr | tok/s | Hours | Cost USD | Cost INR |
108
- |-----|------|-------|-------|----------|----------|
109
- | RTX A5000 | $0.16 | ~6,400 | ~196h | ~$31 | ~2,700 |
110
- | RTX 3090 | $0.22 | ~7,600 | ~165h | ~$36 | ~3,100 |
111
- | RTX 4090 | $0.34 | ~10,000 | ~125h | ~$42 | ~3,600 |
112
- | RTX 5090 | $0.69 | ~16,000 | ~78h | ~$54 | ~4,600 |
113
- | H100 NVL | $2.59 | ~43,000 | ~29h | ~$75 | ~6,400 |
114
-
115
- ## Resume Training
116
-
117
- Training auto-saves `latest.pt` every save_interval steps. If interrupted, just re-run the same command -- it picks up where it left off.
118
-
119
- ---
120
-
121
- ## Verified Configs (What Worked)
122
-
123
- These are the exact configurations that produced the current LUNA 100M model.
124
- Do NOT change them unless you know what you're doing — they are proven and validated.
125
-
126
  ---
127
 
128
- ### 1. Pretraining 4.5 Billion Tokens
129
 
130
- The pretraining ran in two phases on an RTX 4060 Ti 16GB.
131
 
132
- **Phase 1: Bulk pretraining on 3B general web tokens**
133
 
134
- | Parameter | Value |
135
- |-----------|-------|
136
- | Dataset | `litdata_3b` deduplicated, quality-filtered (score 0.96) general web |
137
- | Total tokens | 3,000,000,000 (3B) |
138
- | Precision | bf16-mixed |
139
- | Global batch size | 120 (micro_batch=12 × grad_accum=10) |
140
- | Sequence length | 1024 |
141
- | Optimizer | AdamW (lr=6e-4, min_lr=6e-5, weight_decay=0.1, betas=[0.9, 0.95]) |
142
- | LR schedule | Cosine decay with 500-step warmup |
143
- | Gradient clip | max_norm=1.0 |
144
- | Checkpoints | Every 1000 steps |
145
- | Seed | 1337 |
146
- | Tokenizer | EleutherAI/pythia-160m (vocab 50,254) |
147
-
148
- **Phase 2: Continued pretraining on clean English (Wikipedia + FineWeb-Edu)**
149
-
150
- | Parameter | Value |
151
- |-----------|-------|
152
- | Dataset | `litdata_english` — ultra-clean Wikipedia + FineWeb-Edu |
153
- | Total tokens | 150,000,000 (150M) — ~3 epochs over ~50M unique tokens |
154
- | Init weights | Phase 1 checkpoint (`custom-100m-3b-full/final_raw`) |
155
- | Precision | bf16-mixed |
156
- | Global batch size | 120 (micro_batch=12 × grad_accum=10) |
157
- | Sequence length | 1024 |
158
- | Optimizer | AdamW (lr=1e-4, min_lr=1e-5, weight_decay=0.1, betas=[0.9, 0.95]) |
159
- | LR schedule | Cosine decay with 200-step warmup |
160
- | Gradient clip | max_norm=1.0 |
161
- | Checkpoints | Every 500 steps |
162
-
163
- **Final combined dataset used for the production run:**
164
-
165
- | Parameter | Value |
166
- |-----------|-------|
167
- | Dataset | `litdata_pretrain_final` — all sources merged |
168
- | Total tokens | 4,515,286,950 (~4.5B) in 270 chunks |
169
- | Sources | Wikipedia, FineWeb-Edu, OpenWebText (deduplicated, cleaned pure English) |
170
- | Format | LitData binary (int32, block_size=1025, EOS=0) |
171
- | Config file | `train_config.yaml` |
172
- | Precision | bf16 |
173
- | Global batch size | 120 (micro_batch=12 × grad_accum=10) |
174
- | Sequence length | 1024 |
175
- | Optimizer | AdamW (lr=6e-4, min_lr=6e-5, weight_decay=0.1, betas=[0.9, 0.95]) |
176
- | LR schedule | Cosine with 500-step warmup (5% of total steps when auto) |
177
- | Gradient clip | max_norm=1.0 |
178
- | torch.compile | true (Linux/cloud with Triton) |
179
- | auto_config | true (probes VRAM, CPU, RAM at runtime) |
180
-
181
- ---
182
-
183
- ### 2. SFT Fine-Tuning — ~145 Million Tokens
184
-
185
- Supervised fine-tuning on the pretrained LUNA 100M checkpoint.
186
-
187
- | Parameter | Value |
188
- |-----------|-------|
189
- | Dataset | `Base/Datasets/sft_clean/` — 574,996 train + 5,808 val samples |
190
- | Format | Alpaca JSON (instruction / input / output) |
191
- | Estimated tokens | ~145M total (574,996 samples × ~250 tokens avg × 2 epochs) |
192
- | Epochs | 2 |
193
- | Config file | `sft_config.yaml` |
194
-
195
- **Model (frozen architecture — matches pretrain exactly):**
196
-
197
- | Parameter | Value |
198
- |-----------|-------|
199
- | vocab_size | 50,304 (padded to 128 multiple) |
200
- | seq_len | 1024 |
201
- | n_layer | 10 |
202
- | n_embd | 768 |
203
- | n_head | 12 |
204
- | Rotary % | 25% |
205
- | Total params | 109,513,728 |
206
-
207
- **Training hyperparameters:**
208
-
209
- | Parameter | Value |
210
- |-----------|-------|
211
- | Optimizer | AdamW (lr=1.5e-5, min_lr=1e-6, weight_decay=0.01, betas=[0.9, 0.95]) |
212
- | Precision | bf16 |
213
- | Global batch size | 64 (micro_batch=8 × grad_accum=8) |
214
- | LR warmup | 200 steps |
215
- | Gradient clip | max_norm=1.0 |
216
- | Save interval | Every 500 steps |
217
- | Eval interval | Every 500 steps (runs val loss + eval prompts) |
218
- | DataLoader | 4 workers, pin_memory=true |
219
- | torch.compile | false |
220
-
221
- **Prompt format (used during training — must be matched at inference):**
222
-
223
- ```
224
- ### Instruction:
225
- {instruction}
226
-
227
- ### Response:
228
- ```
229
-
230
- With optional input field:
231
-
232
- ```
233
- ### Instruction:
234
- {instruction}
235
-
236
- ### Input:
237
- {input}
238
-
239
- ### Response:
240
- ```
241
-
242
- **Loss masking:** Only the response tokens (after `### Response:\n`) contribute to the loss.
243
- The prompt tokens are masked out (loss_mask=0). EOS token (id=0) is appended to every response.
244
-
245
- ---
246
-
247
- ### 3. SFT Inference / Chat — Loaded Configs
248
-
249
- These are the exact generation parameters loaded when running `chat.py` or `validate_sft.py`.
250
- They match the training eval config from `sft_train.py`.
251
-
252
- ```bash
253
- python chat.py --ckpt "Base\out\sft\model.pth"
254
- ```
255
-
256
- **Model loading:**
257
-
258
- | Parameter | Value |
259
- |-----------|-------|
260
- | Checkpoint | `Base/out/sft/model.pth` (419 MB, raw state_dict, 154 keys) |
261
- | Checkpoint format | Raw `state_dict` — NOT wrapped in `{"model": ...}` dict |
262
- | Tokenizer | `Base/checkpoints/EleutherAI/pythia-160m` (vocab 50,254) |
263
- | EOS token ID | 0 (pythia tokenizer — NOT 50276) |
264
- | Device | auto (CUDA if available, else CPU) |
265
- | Precision | float32 at inference (weights loaded as-is from bf16-trained ckpt) |
266
-
267
- **Generation parameters:**
268
-
269
- | Parameter | Value | Why |
270
- |-----------|-------|-----|
271
- | temperature | 0.7 | Balanced creativity vs coherence |
272
- | top_k | 40 | Matches training eval (NOT 50) |
273
- | top_p | 0.9 | Nucleus sampling cutoff |
274
- | repetition_penalty | 1.0 | No penalty — matches training (NOT 1.1) |
275
- | max_new_tokens | 150 | Matches training eval (NOT 256) |
276
-
277
- **Prompt template (must match training exactly):**
278
-
279
- ```python
280
- def format_prompt(instruction, context=""):
281
- if instruction and context:
282
- return f"### Instruction:\n{instruction}\n\n### Input:\n{context}\n\n### Response:\n"
283
- else:
284
- return f"### Instruction:\n{instruction}\n\n### Response:\n"
285
- ```
286
-
287
- **Critical notes:**
288
- - There is NO Alpaca preamble text (e.g., "Below is an instruction...") — the model was never trained with one
289
- - EOS token is id=0 (pythia), not 50276 (GPT-NeoX) — using the wrong EOS causes the model to never stop
290
- - Generation stops when EOS is produced OR max_new_tokens is reached
291
- - For longer responses in chat, you can override: `--max_new 512`
292
- - For less repetition in production, add: `--rep_pen 1.05`
293
-
294
- **Validation results with these configs (100 complex examples):**
295
-
296
- | Metric | Value |
297
- |--------|-------|
298
- | Overall Grade | A |
299
- | Avg Loss (CE) | 1.9167 |
300
- | Avg Perplexity | 7.45 |
301
- | Token Accuracy | 58.6% |
302
- | BLEU-1 | 0.589 |
303
- | BLEU-2 | 0.219 |
304
- | Empty responses | 0/100 |
305
- | Repetitive responses | 5/100 |
306
-
307
- ---
308
 
309
- ## License
310
 
311
- Private / ASTERIZER 2026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: other
3
+ language:
4
+ - en
5
+ tags:
6
+ - luna
7
+ - sft
8
+ - lora
9
+ - rag
10
+ - mcp
11
+ - training
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
+ # LUNA-TrainingSFT & LoRA Recipes for LUNA-100M
15
 
16
+ This repository is the **supervised fine-tuning workspace** for the [LUNA-100M](https://huggingface.co/ASTERIZER/LUNA-100M) model. It contains the SFT/LoRA training code, configuration files, and the RAG + MCP dataset build pipeline used to produce the trained `sft_v1` / `luna_100m_sft` checkpoints.
17
 
18
+ ## Contents
19
 
20
+ | Path | Description |
21
+ |---|---|
22
+ | `train.py` | Base pretraining trainer (shared with the [LUNA workspace](https://huggingface.co/spaces/ASTERIZER/LUNA)) |
23
+ | `sft_train.py` | Full supervised fine-tuning trainer |
24
+ | `lora_sft_train.py` | LoRA SFT trainer (RAG+MCP adapter runs) |
25
+ | `lora_chat.py` / `chat.py` / `chat_full_sft.py` / `generate.py` | Inference / chat entry points |
26
+ | `validate_sft.py` / `validate_and_quantize.py` | Eval + quantization (incl. GGUF export) |
27
+ | `rag_mcp_lora_config.yaml` / `rag_mcp_full_sft_config.yaml` | RAG + MCP SFT recipes |
28
+ | `sft_config.yaml` / `train_config.yaml` | Base SFT / pretrain configs |
29
+ | `push_*_to_hf.py` | Upload helpers (code / dataset / model / LoRA) |
30
+ | `Base/Datasets/rag_mcp_sft/` | RAG + MCP SFT dataset builder + reports |
31
+ | `Base/checkpoints/EleutherAI/pythia-160m/` | LUNA tokenizer (vocab 50,254) |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ ## Related
34
 
35
+ - **Model:** [ASTERIZER/LUNA-100M](https://huggingface.co/ASTERIZER/LUNA-100M)
36
+ - **SFT dataset:** [ASTERIZER/LUNA-RAG-MCP-SFT-10M](https://huggingface.co/datasets/ASTERIZER/LUNA-RAG-MCP-SFT-10M)
37
+ - **Pretrain corpus:** [ASTERIZER/LUNA_PreTrain](https://huggingface.co/datasets/ASTERIZER/LUNA_PreTrain)
38
+ - **Program collection:** [LUNA-100M Program](https://huggingface.co/collections/ASTERIZER/luna-100m-program-6a9115383c18e52460bf67c9)