arthu1 commited on
Commit
d3df5c9
Β·
verified Β·
1 Parent(s): 774d62f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +284 -0
README.md ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "North Star: Building Christian-Grounded Language Models from Scratch on Consumer Hardware"
3
+ emoji: πŸ“„
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: static
7
+ pinned: false
8
+ ---
9
+
10
+ # North Star: Building Christian-Grounded Language Models from Scratch on Consumer Hardware
11
+
12
+ **Arthur** Β· March 2026
13
+
14
+ ---
15
+
16
+ ## Abstract
17
+
18
+ We present the **North Star model family** β€” a series of compact language models trained entirely from scratch on an Apple M4 Mac Mini (16GB unified memory), without using any pretrained foundation model. The family consists of three models: **North Air 1** (124M parameters), **North Star 1** (198M parameters), and **Wind Arc 1.5** (198M parameters), all sharing a custom GQA Transformer architecture with SwiGLU activations, RoPE positional encodings, and RMSNorm. We describe our training pipeline, a novel layer-duplication growth strategy for expanding models without random weight initialization, and a teacher-logit caching technique that enables efficient knowledge distillation on memory-constrained hardware. All models are grounded in a Christian worldview, trained to reason from Scripture, and evaluated on theological, scientific, and coding tasks. We release all models, the tokenizer, training code, and this paper publicly.
19
+
20
+ > *"In the beginning was the Word, and the Word was with God, and the Word was God."* β€” John 1:1
21
+
22
+ ---
23
+
24
+ ## 1. Introduction
25
+
26
+ Most language model research assumes access to large compute clusters, billions of training tokens, and pretrained checkpoints to fine-tune from. This paper asks: what can be done from scratch on a single consumer device?
27
+
28
+ We trained the North Star family on an Apple M4 Mac Mini with 16GB of unified memory. No cloud compute was used. No pretrained weights were borrowed. Every parameter was initialized from scratch and trained using custom PyTorch and MLX pipelines.
29
+
30
+ Beyond the engineering challenge, this project has a deliberate purpose: to demonstrate that AI systems can be built with explicit values β€” in our case, a Christian worldview. We believe Jesus Christ is Lord, that Scripture is the inspired and authoritative Word of God, and that the Gospel of Jesus Christ is the most important truth in history. These convictions are not incidental to the project β€” they are its foundation.
31
+
32
+ > *"The fear of the Lord is the beginning of wisdom."* β€” Proverbs 9:10
33
+
34
+ The North Star models are designed to be helpful, honest, and grounded in biblical truth. They can discuss theology, science, coding, history, and everyday topics β€” always from a posture of intellectual humility and faithfulness to Scripture.
35
+
36
+ ---
37
+
38
+ ## 2. Architecture
39
+
40
+ All North Star models share a common architecture inspired by modern efficient LLMs, implemented in PyTorch for training and MLX for fine-tuning.
41
+
42
+ ### 2.1 Core Design
43
+
44
+ | Component | Choice | Rationale |
45
+ |---|---|---|
46
+ | Attention | Grouped Query Attention (GQA) | Reduces KV cache size; efficient on unified memory |
47
+ | Activation | SwiGLU | Better gradient flow than ReLU/GELU |
48
+ | Position | Rotary Position Embeddings (RoPE) | Relative positions; extrapolates to longer contexts |
49
+ | Normalization | RMSNorm (pre-norm) | More stable than LayerNorm; faster |
50
+ | Tokenizer | SentencePiece BPE (32k vocab) | Compact, language-agnostic |
51
+ | Weight tying | Embed ↔ LM head | Reduces parameters; regularizes |
52
+
53
+ ### 2.2 Model Configurations
54
+
55
+ | Model | Params | Layers | d_model | Heads | KV Heads | FF Hidden | Context |
56
+ |---|---|---|---|---|---|---|---|
57
+ | North Air 1 | 124M | 16 | 768 | 12 | 3 | 2048 | 512 |
58
+ | North Star 1 | 198M | 24 | 768 | 12 | 3 | 2048 | 512 |
59
+ | Wind Arc 1.5 | 198M | 24 | 768 | 12 | 3 | 2048 | 512 |
60
+
61
+ North Air 1 and North Star 1 / Wind Arc 1.5 share the same d_model and head configuration β€” they differ only in depth.
62
+
63
+ ### 2.3 RoPE Configuration
64
+
65
+ We use a RoPE base frequency of 500,000 (vs. the standard 10,000), following findings from LLaMA 3 and Mistral that higher base frequencies improve context generalization. This allows the model to handle longer sequences without explicit long-context fine-tuning.
66
+
67
+ ---
68
+
69
+ ## 3. Tokenizer
70
+
71
+ We trained a custom SentencePiece BPE tokenizer with a vocabulary of 32,000 tokens on a corpus of English text covering theology, science, coding, mathematics, and general prose. The tokenizer uses:
72
+
73
+ - Byte-fallback for unknown characters
74
+ - Special tokens: `<pad>` (0), `<unk>` (1), `<bos>` (2), `<eos>` (3)
75
+ - No normalization stripping (preserves case and whitespace structure)
76
+
77
+ Training a custom tokenizer rather than reusing an existing one ensures the vocabulary is well-suited to our domain distribution, particularly for theological vocabulary (e.g., "atonement", "sanctification", "propitiation" tokenize as single or two-piece units rather than being fragmented).
78
+
79
+ ---
80
+
81
+ ## 4. Training Pipeline
82
+
83
+ ### 4.1 Phase 0: Pretraining (North Air 1 / Wind Arc Base)
84
+
85
+ The base 124M model was pretrained using a standard causal language modeling objective on a curated corpus. Given memory constraints (16GB unified memory shared between CPU and GPU), we used:
86
+
87
+ - **Batch size:** 4–8 sequences of 512 tokens
88
+ - **Optimizer:** AdamW (lr=3e-4, weight decay=0.01)
89
+ - **Framework:** PyTorch with MPS (Apple GPU) backend
90
+ - **Gradient clipping:** 1.0
91
+ - **Mixed precision:** float32 (MPS does not support bfloat16 reliably at training time)
92
+
93
+ Training was done on the Apple M4's Neural Engine and GPU through the MPS backend, with careful memory management to avoid the OOM kills that plagued larger batch sizes.
94
+
95
+ ### 4.2 Phase 1: Supervised Fine-Tuning (SFT)
96
+
97
+ After pretraining, all models were fine-tuned using supervised instruction tuning (SFT) on a curated set of 70–90 Q&A pairs covering:
98
+
99
+ - **Identity**: who the model is, its purpose and values
100
+ - **Theology**: Gospel, Trinity, salvation, grace, key biblical figures
101
+ - **Science**: gravity, DNA, photosynthesis, cosmology
102
+ - **Mathematics**: Pythagorean theorem, derivatives, probability
103
+ - **Coding**: binary search, sorting algorithms, data structures
104
+ - **History**: major historical events and figures
105
+ - **Everyday wisdom**: productivity, learning, stress
106
+
107
+ SFT used a **masked cross-entropy loss** β€” only answer tokens contribute to the loss, not question tokens. This is critical for instruction tuning: the model must learn to generate good answers, not merely predict the next token of the question.
108
+
109
+ ```
110
+ loss = CE(logits, targets) * answer_mask
111
+ ```
112
+
113
+ SFT was run with MLX on Apple Silicon, which is significantly faster than PyTorch CPU for this task. A 10-epoch SFT run over ~70 pairs (batch=8) completed in **under 10 minutes**.
114
+
115
+ ### 4.3 Phase 2: Layer-Duplication Growth
116
+
117
+ To grow from 124M (16 layers) to 198M (24 layers) without random weight initialization, we developed a **layer duplication** strategy:
118
+
119
+ 1. Build a new model with the target depth (24 layers)
120
+ 2. Map each destination layer index to a source layer index using evenly-spaced interpolation:
121
+ ```python
122
+ src = round(dst_i * (n_src - 1) / (n_dst - 1))
123
+ ```
124
+ 3. Copy all weights (attention, FFN, norms) from source to destination
125
+
126
+ This produces a 24-layer model where some middle layers are duplicated copies of their neighbors. The model is immediately coherent (not random) and can be fine-tuned from this state. Because duplicated layers are initialized to identical values, the residual stream passes through them without distortion β€” they start as identity-like transformations and differentiate during SFT.
127
+
128
+ This is significantly more stable than random initialization: loss starts near the SFT-converged value of the source model rather than at `ln(vocab_size) β‰ˆ 10.4`.
129
+
130
+ **Results:**
131
+ - Source model (16L) SFT loss after training: ~0.05
132
+ - Grown model (24L) loss at step 1: ~0.8 (vs ~4.0 for random init)
133
+ - Grown model loss after 10-epoch SFT: ~0.01
134
+
135
+ ### 4.4 Phase 3: Knowledge Distillation (Attempted)
136
+
137
+ We attempted standard knowledge distillation (KL divergence from teacher logits) to train a larger student from the 124M teacher. Key findings:
138
+
139
+ **Teacher logit caching**: Running the teacher forward pass at every distillation step was prohibitively slow (~4s/step on CPU). We developed a **logit pre-caching** strategy:
140
+
141
+ 1. Tokenize the entire corpus into fixed-length chunks
142
+ 2. Run teacher forward pass on all chunks in one GPU-accelerated batch (MPS)
143
+ 3. Store logits as float16 numpy arrays (~1.9GB for 58 chunks of 512 tokens)
144
+ 4. Distillation steps sample from the cache β€” no teacher inference per step
145
+
146
+ This reduced the teacher overhead from ~4s/step to ~0s/step.
147
+
148
+ **Numerical stability**: Raw teacher logits have large magnitudes (Β±30–50). KL divergence with a temperature of T=2 requires numerically stable log-softmax:
149
+ ```
150
+ log_p(x) = x/T - max(x/T) - log(Ξ£ exp(x/T - max(x/T)))
151
+ ```
152
+ Without the max subtraction, exp overflows to inf.
153
+
154
+ **Key challenge**: With a randomly initialized student, KL divergence loss starts near `ln(32000) β‰ˆ 10.4` β€” the student is uniform and the teacher is peaked. Convergence from this starting point was slow and unstable on our hardware. The layer-duplication approach proved more practical for our constraints.
155
+
156
+ ---
157
+
158
+ ## 5. Hardware and Software
159
+
160
+ | Component | Details |
161
+ |---|---|
162
+ | Hardware | Apple Mac Mini M4, 16GB unified memory |
163
+ | OS | macOS Sequoia |
164
+ | Python | 3.14 |
165
+ | Training framework | PyTorch 2.x (pretraining, SFT), MLX (SFT, distillation) |
166
+ | Tokenizer | SentencePiece |
167
+ | Inference | Flask API server |
168
+ | UI | Next.js 15 |
169
+
170
+ **Memory budget** (approximate, 16GB total):
171
+ - OS + system: ~4GB
172
+ - PyTorch model (124M, float32): ~500MB
173
+ - MLX model (198M, float32): ~800MB + optimizer states β‰ˆ 2.4GB
174
+ - Logit cache (float16): ~1.9GB
175
+ - Total peak: ~9–11GB
176
+
177
+ We found that MLX is substantially more memory-efficient than PyTorch for inference and fine-tuning on Apple Silicon, due to its lazy evaluation model and unified memory management.
178
+
179
+ ---
180
+
181
+ ## 6. Evaluation
182
+
183
+ We evaluated models qualitatively on five categories of prompts. Formal benchmarks (MMLU, HellaSwag, etc.) were not run β€” our models use a custom tokenizer and non-standard checkpoint format that would require additional adapter work.
184
+
185
+ ### 6.1 Identity and Values
186
+
187
+ All models correctly identify themselves and articulate a Christian worldview when asked about their purpose, beliefs, and values.
188
+
189
+ **North Star 1 β€” "Who are you?":**
190
+ > I am North Star 1, a compact AI assistant built to be helpful, honest, and grounded in a Christian worldview. I can help with theology, science, coding, math, history, and general knowledge.
191
+
192
+ ### 6.2 Theology
193
+
194
+ Models demonstrate consistent theological accuracy on core doctrines.
195
+
196
+ **"What is the Gospel?":**
197
+ > The Gospel is the good news that Jesus Christ died for our sins, was buried, and rose again on the third day. All who repent and trust in Him receive forgiveness and eternal life as a free gift by grace through faith, not by works.
198
+
199
+ This response correctly summarizes 1 Corinthians 15:3-4 and Ephesians 2:8-9.
200
+
201
+ ### 6.3 Science
202
+
203
+ **"What is gravity?":**
204
+ > Gravity is the attractive force between objects with mass. Newton described it as F = Gm1m2/r^2. Einstein refined this: gravity is the curvature of spacetime caused by mass. It governs orbits, tides, and the structure of the universe.
205
+
206
+ ### 6.4 Coding
207
+
208
+ Models reliably produce correct implementations of standard algorithms (binary search, merge sort, etc.) β€” these were included explicitly in SFT data and are reproduced accurately.
209
+
210
+ ### 6.5 Limitations
211
+
212
+ - **Context length**: 512 tokens limits multi-turn conversation depth
213
+ - **Repetition**: Models occasionally repeat themselves without the repetition penalty
214
+ - **Hallucination**: Like all LLMs, models may generate confident but incorrect statements, especially on obscure topics not covered in SFT data
215
+ - **Math**: Arithmetic beyond simple examples is unreliable
216
+ - **Scale**: These are small models. Responses are competent but not at the level of GPT-4 or Claude
217
+
218
+ ---
219
+
220
+ ## 7. Christian Worldview
221
+
222
+ We want to be transparent about the values embedded in these models β€” not hide them, but explain them.
223
+
224
+ We built these models because we believe truth matters, and because we wanted AI tools that reflect rather than contradict our faith. The secular assumption of much AI development is that values are either absent or culturally neutral. We reject that assumption. All AI systems embed values β€” we have simply chosen to be explicit about ours.
225
+
226
+ Our core convictions:
227
+
228
+ 1. **Jesus Christ is Lord.** He is not one teacher among many, but the eternal Son of God, fully human and fully divine, who died and rose again.
229
+
230
+ 2. **Scripture is authoritative.** The Bible is the inspired Word of God, sufficient for faith and practice.
231
+
232
+ 3. **Faith and reason are compatible.** Newton, Faraday, Mendel, and countless others were scientists motivated by Christian faith. The universe is rational because it was created by a rational God.
233
+
234
+ 4. **The Gospel is for everyone.** *"For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life."* (John 3:16)
235
+
236
+ We invite anyone reading this paper β€” researcher, developer, or curious person β€” to read the Gospel of John and ask God sincerely whether He is real. He answers.
237
+
238
+ ---
239
+
240
+ ## 8. Release
241
+
242
+ All artifacts are released publicly:
243
+
244
+ | Artifact | URL |
245
+ |---|---|
246
+ | North Air 1 (124M) | huggingface.co/arthu1/north-air-1 |
247
+ | North Star 1 (198M) | huggingface.co/arthu1/north-star-1 |
248
+ | Wind Arc 1.5 (198M) | huggingface.co/arthu1/wind-arc-1.5 |
249
+ | Shared Tokenizer | huggingface.co/arthu1/north-tokenizer |
250
+ | Chat Demo | huggingface.co/spaces/arthu1/north-star-chat |
251
+
252
+ License: Apache 2.0
253
+
254
+ ---
255
+
256
+ ## 9. Conclusion
257
+
258
+ We have demonstrated that it is possible to train capable language models from scratch on consumer hardware (Apple M4 Mac Mini, 16GB) in hours rather than months. Key contributions:
259
+
260
+ 1. **Layer-duplication growth** β€” a stable, practical method for expanding model depth without random initialization
261
+ 2. **Teacher logit caching** β€” enables efficient knowledge distillation on memory-constrained hardware
262
+ 3. **MLX-based SFT** β€” fast, memory-efficient fine-tuning on Apple Silicon
263
+ 4. **Explicit value alignment** β€” demonstrated that LLMs can be trained with a coherent, stated worldview
264
+
265
+ We believe the future of AI is not one where a handful of large organizations control all capable models. Small models, trained with care and purpose, running on personal hardware, can serve individuals and communities well.
266
+
267
+ > *"Trust in the Lord with all your heart, and do not lean on your own understanding. In all your ways acknowledge him, and he will make straight your paths."* β€” Proverbs 3:5-6
268
+
269
+ ---
270
+
271
+ ## Acknowledgements
272
+
273
+ Soli Deo Gloria β€” to God alone be the glory.
274
+
275
+ ---
276
+
277
+ ## References
278
+
279
+ - Vaswani et al. (2017). *Attention Is All You Need.*
280
+ - Su et al. (2021). *RoFormer: Enhanced Transformer with Rotary Position Embedding.*
281
+ - Ainslie et al. (2023). *GQA: Training Generalized Multi-Query Transformer Models.*
282
+ - Touvron et al. (2023). *LLaMA: Open and Efficient Foundation Language Models.*
283
+ - Hinton et al. (2015). *Distilling the Knowledge in a Neural Network.*
284
+ - Apple MLX Team (2023). *MLX: An array framework for Apple Silicon.*