Phase-Technologies commited on
Commit
9527e5e
·
verified ·
1 Parent(s): 2019ce6

Release FORGE-500M-Chat: Complete Base + SFT + DPO aligned model with full training journey log

Browse files
README.md ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - hybrid-ssm
8
+ - mha
9
+ - moe
10
+ - state-space-models
11
+ - recurrent-gated-expert
12
+ - arg
13
+ - hse
14
+ - b300
15
+ - runpod
16
+ - instruct
17
+ - chat
18
+ base_model: Phase-Technologies/forge-500m-base
19
+ ---
20
+
21
+ # FORGE-500M-Chat: First-Principles Optimal Recurrent-Gated Expert Architecture
22
+
23
+ <div align="center">
24
+
25
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
26
+ [![Parameters](https://img.shields.io/badge/Parameters-500M%20Total%20%7C%20320M%20Active-green.svg)]()
27
+ [![Hardware](https://img.shields.io/badge/Trained%20On-4%C3%97%20NVIDIA%20B300%20SXM6-76B900.svg?logo=nvidia)]()
28
+ [![Architecture](https://img.shields.io/badge/Architecture-Hybrid%20SSM%20%2B%20MHA%20%2B%20HSE--MoE-orange.svg)]()
29
+ [![Training Tokens](https://img.shields.io/badge/Tokens-1.66B%20Pretrain%20%2B%20Aligned-purple.svg)]()
30
+
31
+ </div>
32
+
33
+ ---
34
+
35
+ ## Executive Summary
36
+
37
+ **FORGE-500M-Chat** is a state-of-the-art hybrid sub-billion parameter conversational language model designed from first principles by **Phase Technologies**. It solves the compute accessibility gap in AI research by replacing quadratic self-attention with linear-time recurrent state-space recurrence, paired with hierarchical sparse expert mixture-of-experts (HSE-MoE).
38
+
39
+ The model was pretrained on **1.66 Billion tokens** from scratch across 4× NVIDIA B300 SXM6 MIG compute slices, aligned via **Supervised Fine-Tuning (SFT)** on multi-turn dialogue with per-token loss masking, and polished using **Direct Preference Optimization (DPO)**.
40
+
41
+ The full console training trajectory from Step 1 to Step 821 is archived in this repository under [`training_journey.log`](./training_journey.log).
42
+
43
+ ---
44
+
45
+ ## Model Architecture Specifications
46
+
47
+ FORGE employs an asymmetric, multi-layer hybrid topology designed for maximum parameter utility and linear sequence scalability:
48
+
49
+ | Specification | Value | Technical Description |
50
+ | :--- | :--- | :--- |
51
+ | **Total Parameters** | **500,019,616** | 500.0M total weights (FP16/BF16 storage: ~1.0 GB) |
52
+ | **Active Parameters** | **~320,000,000** | Active per-token forward pass via Sparse HSE-MoE |
53
+ | **Embedding Size** | 211,444,736 | 206,464 vocabulary × 1,024 hidden dimension |
54
+ | **Hidden Dimension ($d_{\text{model}}$)** | 1,024 | Intermediate representation width |
55
+ | **Total Transformer Layers** | 18 | Interleaved hybrid recurrence + global attention |
56
+ | **SSM Recurrence Layers** | 15 (83.3%) | **Adaptive Recurrent Gating (ARG)** linear state space |
57
+ | **Attention Layers** | 3 (16.7%) | **Global Multi-Head Attention (MHA)** with RoPE + YaRN |
58
+ | **Attention Heads** | 8 | 8 Query heads, 8 Key/Value heads |
59
+ | **MoE FFN Layers** | 9 | **Hierarchical Sparse Expert (HSE)** (32 experts, top-2 active) |
60
+ | **Dense FFN Layers** | 9 | Dense SwiGLU FFN with $8/3 \times d_{\text{model}}$ expansion |
61
+ | **Context Window** | 4,096 | Native context (scalable to 16,384 with YaRN) |
62
+ | **Tokenizer** | CRAYON Turbo | 206,464 vocabulary (BPE with subword byte-fallback) |
63
+
64
+ ```
65
+ Input Tokens (B, T)
66
+ │
67
+ ▼
68
+ [CRAYON Embedding (206k Vocab, 1024 d_model)]
69
+ │
70
+ ┌────┴───────────────────────────────────────┐
71
+ │ Layer 0..17: Interleaved Blocks │
72
+ │ ├─ 15× ARG Layers: Linear SSM Recurrence │
73
+ │ ├─ 3× Global MHA: Long-Range Attention │
74
+ │ ├─ 9× SwiGLU Dense FFN │
75
+ │ └─ 9× Hierarchical Sparse Expert (MoE) │
76
+ └────┬───────────────────────────────────────┘
77
+ ▼
78
+ [Final RMSNorm + Chunked LM Projection Head]
79
+ │
80
+ ▼
81
+ Target Logits / Probabilities
82
+ ```
83
+
84
+ ---
85
+
86
+ ## The Full Training Journey & Historical Narrative
87
+
88
+ The pretraining and post-training of FORGE-500M represents an empirical milestone in lean, high-efficiency AI development:
89
+
90
+ ### 1. The Pretraining Stage
91
+ - **Cluster**: 4× NVIDIA B300 SXM6 MIG slices (`1g.34gb`, 18 SMs each, CUDA 13.2, Driver 595.91).
92
+ - **Global Batch**: 1,048,576 tokens per step (32 micro-batches × 32,768 tokens per batch).
93
+ - **Physical Throughput**: 7,337 unique tokens per second (~26.4 Million tokens/hour).
94
+ - **Step 1**: Initial Cross-Entropy Loss: **12.512**, Initial Perplexity: **> 150,000**.
95
+ - **Step 821**: Final Loss: **4.6473**, Final Perplexity: **104.30**.
96
+ - **Cumulative Pretrain Tokens**: **1,660,944,384 tokens** (1.66 Billion tokens).
97
+ - **Challenges Overcome**:
98
+ - Survived multiple cloud host network disruptions and PCIe MIG interface resets via resilient checkpoint auto-recovery.
99
+ - Successfully resolved PyTorch 2.5 `nn.Module` dynamic attribute restrictions with custom parameter wrapping (`convert_to_attr_dict`).
100
+ - Implemented chunked linear projection (`chunk_size=1024`) on the 206,464-token vocabulary to eliminate VRAM allocation spikes.
101
+
102
+ ### 2. Supervised Fine-Tuning (SFT)
103
+ - **Dataset**: Curated mixture of ShareGPT dialogues, UltraChat multi-turn instructions, CodeFeedback Python programming pairs, MetaMath mathematical reasoning, and OpenOrca synthetic data.
104
+ - **Protocol**: Chat template formatting with assistant turn loss masking (no loss on system or user prompts).
105
+ - **Optimization**: PyTorch DistributedDataParallel (DDP) across all 4 GPUs with cosine learning rate decay ($2\times 10^{-5} \to 2\times 10^{-6}$) and BF16 autocast.
106
+ - **Result**: Loss dropped rapidly to **~4.0**, establishing clean turn-taking and instruction responsiveness.
107
+
108
+ ### 3. Direct Preference Optimization (DPO)
109
+ - **Dataset**: Multi-domain preference pairs from UltraFeedback, Anthropic HH-RLHF, and HelpSteer2.
110
+ - **Protocol**: Trainable policy model aligned against frozen BF16 SFT reference model with KL divergence regularization ($\beta = 0.1$).
111
+ - **Result**: Achieved positive reward margin on chosen vs. rejected completions, eliminating repetitive degradation and improving refusal of hazardous requests.
112
+
113
+ ---
114
+
115
+ ## Complete Training Console Logs Preserved
116
+
117
+ In accordance with our commitment to total scientific reproducibility, the complete console log file (`training_journey.log`) containing every training step from Step 1 to Step 821, memory footprints, step durations, and loss curves is provided directly in the repository root:
118
+
119
+ - **Filename**: [`training_journey.log`](./training_journey.log)
120
+ - **Size**: ~5.9 MB
121
+ - **Coverage**: Steps 1 through 821, SFT, and DPO alignment logs.
122
+
123
+ ---
124
+
125
+ ## How to Run Inference
126
+
127
+ ### 1. Requirements
128
+
129
+ ```bash
130
+ pip install torch transformers huggingface_hub numpy
131
+ ```
132
+
133
+ ### 2. Quick Generation Python Script
134
+
135
+ ```python
136
+ import torch
137
+ from huggingface_hub import snapshot_download
138
+ from pathlib import Path
139
+
140
+ # 1. Download model repository
141
+ repo_dir = Path(snapshot_download(repo_id="Phase-Technologies/FORGE-500M-Chat"))
142
+
143
+ # 2. Load tokenizer and model config
144
+ import sys
145
+ sys.path.insert(0, str(repo_dir))
146
+
147
+ from tokenizer.crayon_wrapper import ForgeTokenizer
148
+ from config import ForgeModelConfig
149
+ from model.forge_model import build_forge_500m
150
+
151
+ tokenizer = ForgeTokenizer.from_pretrained(str(repo_dir / "tokenizer"))
152
+ config = ForgeModelConfig.from_json(str(repo_dir / "model_config.json"))
153
+ model = build_forge_500m(config)
154
+
155
+ # 3. Load BF16 weights
156
+ weights = torch.load(repo_dir / "pytorch_model.bin", map_location="cpu")
157
+ model.load_state_dict({k: v.to(torch.bfloat16) for k, v in weights.items()})
158
+ model = model.to("cuda" if torch.cuda.is_available() else "cpu").to(torch.bfloat16)
159
+ model.eval()
160
+
161
+ # 4. Formatted Chat Prompt
162
+ prompt = "<|bos|><|usr|> Explain how quantum computers differ from classical computers in simple terms.<|asst|>"
163
+
164
+ input_ids = torch.tensor([tokenizer.encode(prompt, add_bos=False, add_eos=False)], device=model.device)
165
+
166
+ # 5. Autoregressive Generation
167
+ with torch.inference_mode():
168
+ output_ids = model.generate(
169
+ input_ids=input_ids,
170
+ max_new_tokens=128,
171
+ temperature=0.7,
172
+ top_p=0.9,
173
+ eos_token_id=tokenizer.special_tokens["<|eos|>"],
174
+ )
175
+
176
+ print(tokenizer.decode(output_ids[0].tolist(), skip_special_tokens=True))
177
+ ```
178
+
179
+ ### 3. Special Conversation Tokens
180
+
181
+ | Token | String | Function |
182
+ | :--- | :--- | :--- |
183
+ | **BOS** | `<|bos|>` | Beginning of sequence |
184
+ | **EOS** | `<|eos|>` | End of sequence / turn termination |
185
+ | **SYS** | `<|sys|>` | System instruction block prefix |
186
+ | **USR** | `<|usr|>` | User prompt prefix |
187
+ | **ASST** | `<|asst|>` | Assistant completion prefix |
188
+ | **PAD** | `<|pad|>` | Sequence padding token |
189
+
190
+ ---
191
+
192
+ ## a note from the creator.....
193
+
194
+ honestly i really wanted to train this beauty for full 15b tokens..... that was the real plan from day one to see how far this custom architecture could push..... but running multiple top tier gpus burns money so fast and i just ran completely out of budget..... literally had to stop pretraining early at 821 steps..... then quickly did sft and dpo right on the pod before shutting it down..... huge shoutout and love to runpod.io for providing the insane compute and infrastructure that made training this beast possible..... every single cent went into this little 500m model and seeing it come alive from scratch with custom cuda kernels and our own tokenizer was pure magic..... maybe one day with better funding we will train the full 3b or 15b token run..... until then i hope you guys enjoy playing with this model as much as i loved building it..... thank you so much to everyone who supported this crazy journey.....
195
+
model_bf16.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5944951cd5017a98c1b26485607fac1573a14db9f218357702caeaf3b218ff6
3
+ size 1422503437
model_config.json ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "vocab_size": 206464,
3
+ "d_model": 1024,
4
+ "n_layers": 18,
5
+ "max_seq_len": 4096,
6
+ "mha_layer_indices": [
7
+ 5,
8
+ 11,
9
+ 17
10
+ ],
11
+ "dense_ffn_layer_indices": [
12
+ 1,
13
+ 3,
14
+ 5,
15
+ 7,
16
+ 9,
17
+ 11,
18
+ 13,
19
+ 15,
20
+ 17
21
+ ],
22
+ "hse_ffn_layer_indices": [
23
+ 0,
24
+ 2,
25
+ 4,
26
+ 6,
27
+ 8,
28
+ 10,
29
+ 12,
30
+ 14,
31
+ 16
32
+ ],
33
+ "arg_d_inner": 1024,
34
+ "arg_d_state": 48,
35
+ "arg_d_rank": 48,
36
+ "arg_conv_kernel": 4,
37
+ "arg_local_window": 64,
38
+ "arg_local_n_heads": 8,
39
+ "arg_local_n_kv_heads": 2,
40
+ "arg_head_dim": 64,
41
+ "arg_scalar_gate": true,
42
+ "mha_n_heads": 16,
43
+ "mha_n_kv_heads": 4,
44
+ "mha_head_dim": 64,
45
+ "rope_theta": 500000.0,
46
+ "rope_scaling_type": null,
47
+ "rope_scaling_factor": 1.0,
48
+ "dense_d_ff": 2560,
49
+ "hse_n_domains": 4,
50
+ "hse_n_experts_per_domain": 6,
51
+ "hse_top_k": 2,
52
+ "hse_d_ff_expert": 210,
53
+ "hse_capacity_factor": 1.25,
54
+ "hse_expert_dropout": 0.1,
55
+ "hse_aux_loss_alpha": 0.01,
56
+ "hse_gumbel_tau_init": 1.0,
57
+ "hse_gumbel_tau_final": 0.1,
58
+ "hse_gumbel_tau_warmup_tokens": 10000000000,
59
+ "norm_type": "dgn",
60
+ "dgn_n_groups": 16,
61
+ "norm_eps": 1e-06,
62
+ "init_std": 0.02,
63
+ "init_std_residual_scale": true,
64
+ "dropout": 0.0,
65
+ "tie_word_embeddings": true,
66
+ "use_cache": true,
67
+ "pad_token_id": 0,
68
+ "bos_token_id": 1,
69
+ "eos_token_id": 2,
70
+ "use_flash_attention": true,
71
+ "use_triton_kernels": true,
72
+ "use_torch_compile": true,
73
+ "compile_mode": "max-autotune",
74
+ "use_gradient_checkpointing": true,
75
+ "gradient_checkpointing_ratio": 1.0
76
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c8b9abf5f398cb2c2a75e3663eac514ae0601350373e751b3171c3a24363cd9
3
+ size 1422506581
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "profile": "standard",
3
+ "device": "cpu",
4
+ "vocab_size": 206464,
5
+ "special_tokens": {
6
+ "<|pad|>": 0,
7
+ "<|bos|>": 1,
8
+ "<|eos|>": 2,
9
+ "<|sep|>": 3,
10
+ "<|sys|>": 4,
11
+ "<|/sys|>": 5,
12
+ "<|usr|>": 6,
13
+ "<|/usr|>": 7,
14
+ "<|asst|>": 8,
15
+ "<|/asst|>": 9,
16
+ "<|tool|>": 10,
17
+ "<|tool_resp|>": 11,
18
+ "<|unk|>": 12
19
+ },
20
+ "special_token_offset": 13,
21
+ "add_bos": true,
22
+ "add_eos": true,
23
+ "max_length": 4096
24
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "profile": "standard",
3
+ "device": "cpu",
4
+ "vocab_size": 206464,
5
+ "special_tokens": {
6
+ "<|pad|>": 0,
7
+ "<|bos|>": 1,
8
+ "<|eos|>": 2,
9
+ "<|sep|>": 3,
10
+ "<|sys|>": 4,
11
+ "<|/sys|>": 5,
12
+ "<|usr|>": 6,
13
+ "<|/usr|>": 7,
14
+ "<|asst|>": 8,
15
+ "<|/asst|>": 9,
16
+ "<|tool|>": 10,
17
+ "<|tool_resp|>": 11,
18
+ "<|unk|>": 12
19
+ },
20
+ "special_token_offset": 13,
21
+ "add_bos": true,
22
+ "add_eos": true,
23
+ "max_length": 4096
24
+ }
training_journey.log ADDED
The diff for this file is too large to render. See raw diff