jbomdev commited on
Commit
603b7a6
·
verified ·
1 Parent(s): 25907b8

Update README.md

Browse files

initial model card commit

Files changed (1) hide show
  1. README.md +236 -0
README.md CHANGED
@@ -1,3 +1,239 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: transformers
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - text-generation
9
+ - causal-lm
10
+ - from-scratch
11
+ - llama
12
+ - grouped-query-attention
13
+ - rope
14
+ - swiglu
15
+ - chatml
16
+ datasets:
17
+ - HuggingFaceFW/fineweb-edu
18
+ - HuggingFaceH4/ultrachat_200k
19
+ model-index:
20
+ - name: AlterEgo-373M
21
+ results:
22
+ - task: {type: text-generation}
23
+ dataset: {name: lambada_openai, type: lambada_openai}
24
+ metrics: [{type: acc, value: 0.3161}]
25
+ - task: {type: text-generation}
26
+ dataset: {name: hellaswag, type: hellaswag}
27
+ metrics: [{type: acc_norm, value: 0.38}]
28
+ - task: {type: text-generation}
29
+ dataset: {name: arc_easy, type: arc_easy}
30
+ metrics: [{type: acc_norm, value: 0.5269}]
31
+ - task: {type: text-generation}
32
+ dataset: {name: arc_challenge, type: arc_challenge}
33
+ metrics: [{type: acc_norm, value: 0.273}]
34
+ - task: {type: text-generation}
35
+ dataset: {name: piqa, type: piqa}
36
+ metrics: [{type: acc_norm, value: 0.6567}]
37
+ - task: {type: text-generation}
38
+ dataset: {name: winogrande, type: winogrande}
39
+ metrics: [{type: acc, value: 0.513}]
40
+ - task: {type: text-generation}
41
+ dataset: {name: openbookqa, type: openbookqa}
42
+ metrics: [{type: acc_norm, value: 0.322}]
43
+ - task: {type: text-generation}
44
+ dataset: {name: sciq, type: sciq}
45
+ metrics: [{type: acc_norm, value: 0.722}]
46
+ - task: {type: text-generation}
47
+ dataset: {name: boolq, type: boolq}
48
+ metrics: [{type: acc, value: 0.6177}]
49
  ---
50
+
51
+ <div align="center">
52
+
53
+ # 🧠 AlterEgo-373M
54
+
55
+ **A 373-million-parameter language model designed, trained, and served entirely from scratch.**
56
+
57
+ [![Code](https://img.shields.io/badge/GitHub-AlterEgo%20(training)-181717?logo=github)](https://github.com/J-bom/AlterEgo)
58
+ [![Platform](https://img.shields.io/badge/GitHub-LLME%20(platform)-181717?logo=github)](https://github.com/J-bom/LLME)
59
+ [![Architecture](https://img.shields.io/badge/arch-Llama--style-blue)]()
60
+ [![Params](https://img.shields.io/badge/params-373M-green)]()
61
+
62
+ </div>
63
+
64
+ ---
65
+
66
+ ## Introduction
67
+
68
+ **AlterEgo** is a small, decoder-only language model built from the ground up - not a fine-tune of an existing model. Every part was written from zero: the transformer architecture, the training loop, the tokenizer wiring, and the KV-cached inference engine. It was pre-trained on ~10B tokens of high-quality educational web text and then instruction-tuned for chat.
69
+
70
+ It is the model at the heart of **[LLME](https://github.com/J-bom/LLME)**, a self-hosted, end-to-end-encrypted LLM platform (think LM Studio / Open WebUI / Ollama, also built from scratch). LLME can serve AlterEgo alongside `llama.cpp` GGUF models and the Gemini API; AlterEgo is the "house" model it was designed around.
71
+
72
+ This repository contains the **model**. The training and architecture code lives in the [AlterEgo repo](https://github.com/J-bom/AlterEgo); the serving platform lives in the [LLME repo](https://github.com/J-bom/LLME).
73
+
74
+ > **Two formats are published.** This repo is the Hugging Face `LlamaForCausalLM` conversion, for drop-in use with `transformers`, vLLM, and GGUF tooling. The **original checkpoint** - in AlterEgo's own from-scratch architecture, exactly as trained - is published separately as [`J-bom/alterego_raw`](https://huggingface.co/J-bom/AlterEgo_raw). This version is a **numerically-lossless conversion** of it (verified: max logit difference ~1e-6).
75
+
76
+ > **What it is and isn't.** AlterEgo is a *research / learning artifact* - a demonstration of the full modern LLM pipeline (architecture → pretraining → SFT → serving) at a scale one person can train on a single GPU. It is **not** a production assistant and won't compete with billion-parameter models. See [Limitations](#limitations).
77
+
78
+ ## Architecture
79
+
80
+ A modern Llama-style decoder (and, thanks to that, it loads as a standard `LlamaForCausalLM`).
81
+
82
+ | Component | Choice |
83
+ |---|---|
84
+ | Type | Decoder-only transformer (autoregressive) |
85
+ | Parameters | ~373M (input/output embeddings tied) |
86
+ | Layers | 24 |
87
+ | Model dimension | 1024 |
88
+ | Attention | **Grouped-Query Attention** - 16 query heads / 4 KV heads (head dim 64) |
89
+ | Positional encoding | **Rotary embeddings (RoPE)**, θ = 10,000 |
90
+ | Normalization | **RMSNorm** (pre-norm) |
91
+ | Feed-forward | **SwiGLU**, hidden dim 2816 |
92
+ | Context length | 2048 |
93
+ | Vocabulary | 100,352 |
94
+ | Tokenizer | `cl100k_base` (tiktoken) extended with ChatML special tokens |
95
+
96
+ ## Training
97
+
98
+ AlterEgo was trained in two stages on a single NVIDIA RTX 4090.
99
+
100
+ ### Stage 1 - Pretraining
101
+
102
+ Pre-trained on **[FineWeb-Edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu)** (HuggingFaceFW), a quality-filtered educational subset of CommonCrawl.
103
+
104
+ ![Pretraining loss](assets/pretraining_loss.png)
105
+
106
+ ![Training dynamics](assets/training_dynamics.png)
107
+
108
+ The grad-norm settling to ~0.26 and the smooth cosine-shaped loss indicate stable training with no divergence.
109
+
110
+ ### Stage 2 - Supervised fine-tuning
111
+
112
+ Instruction-tuned on **[UltraChat-200K](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k)** (HuggingFaceH4), formatted as multi-turn **ChatML**.
113
+
114
+ ![SFT loss](assets/sft_loss.png)
115
+
116
+ ### Hyperparameters
117
+
118
+ | | Pretraining | SFT |
119
+ |---|---|---|
120
+ | Dataset | FineWeb-Edu | UltraChat-200K |
121
+ | Tokens / steps | ~10B / 19,073 | ~64M / 244 |
122
+ | Global batch | 524,288 tokens (micro 2 × 2048 × 128 grad-accum) | same scheme |
123
+ | Optimizer | AdamW (β = 0.9, 0.95; ε = 1e-8; fused) | same |
124
+ | Weight decay | 0.1 (decoupled; excluded from norms/biases) | same |
125
+ | LR schedule | linear warmup (1,900 steps) → cosine decay | cosine |
126
+ | Peak / min LR | 3e-4 → 3e-5 | low (fine-tune range) |
127
+ | Grad clipping | global-norm 1.0 | 1.0 |
128
+ | Precision | bfloat16 autocast | bfloat16 |
129
+ | Throughput / wall-clock | ~32k tok/s · ~86 GPU-h (3.6 days) | ~39k tok/s · ~28 min |
130
+ | Other | `torch.compile`, gradient checkpointing, FlashAttention (SDPA) | same |
131
+ | Final loss (train / val) | 2.94 / **2.89** | 1.83 / **1.81** |
132
+
133
+ ## Evaluation
134
+
135
+ Benchmarked with [EleutherAI's lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) (0-shot).
136
+
137
+ | Benchmark | Metric | AlterEgo-373M | Random |
138
+ |---|---|---|---|
139
+ | lambada_openai | acc | 31.6% | ~0% |
140
+ | hellaswag | acc_norm | 38.0% | 25% |
141
+ | arc_easy | acc_norm | 52.7% | 25% |
142
+ | arc_challenge | acc_norm | 27.3% | 25% |
143
+ | piqa | acc_norm | 65.7% | 50% |
144
+ | winogrande | acc | 51.3% | 50% |
145
+ | openbookqa | acc_norm | 32.2% | 25% |
146
+ | sciq | acc_norm | 72.2% | 25% |
147
+ | boolq | acc | 61.8% | 50% |
148
+
149
+ For a 373M model trained on ~10B tokens these are solid: clearly above chance on science and commonsense (SciQ, PIQA, BoolQ, ARC-easy, HellaSwag) and on next-word prediction (LAMBADA — perplexity 62.3), with the expected near-chance results on the hardest reasoning sets (ARC-challenge, WinoGrande).
150
+
151
+ ## Usage
152
+
153
+ ```python
154
+ from transformers import AutoModelForCausalLM, AutoTokenizer
155
+ import torch
156
+
157
+ tok = AutoTokenizer.from_pretrained("J-bom/AlterEgo")
158
+ model = AutoModelForCausalLM.from_pretrained("J-bom/AlterEgo", torch_dtype=torch.bfloat16)
159
+
160
+ messages = [
161
+ {"role": "system", "content":
162
+ "You are Alter Ego, a small AI built from scratch. You're casual and direct. "
163
+ "You're not great with facts, math, or current events - when you don't know "
164
+ "something, just say so. You're better at chatting than at answering questions."},
165
+ {"role": "user", "content": "Tell me something interesting about the ocean."},
166
+ ]
167
+ ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
168
+
169
+ out = model.generate(
170
+ ids,
171
+ max_new_tokens=200,
172
+ do_sample=True,
173
+ temperature=0.7,
174
+ top_k=50,
175
+ top_p=1.0,
176
+ repetition_penalty=1.1,
177
+ )
178
+ print(tok.decode(out[0][ids.shape[1]:], skip_special_tokens=True))
179
+ ```
180
+
181
+ ### Recommended generation settings
182
+
183
+ These are the defaults AlterEgo was tuned and served with in LLME:
184
+
185
+ | Parameter | Value |
186
+ |---|---|
187
+ | `temperature` | 0.7 |
188
+ | `top_k` | 50 |
189
+ | `top_p` | 1.0 |
190
+ | `repetition_penalty` | 1.1 |
191
+ | `max_new_tokens` | 200 |
192
+
193
+ Lower the temperature toward 0.3–0.5 for steadier, more focused replies; it stops on `<|im_end|>` or `<|endoftext|>`.
194
+
195
+ ### Chat format
196
+
197
+ AlterEgo uses **ChatML**:
198
+
199
+ ```
200
+ <|im_start|>system
201
+ {system prompt}<|im_end|>
202
+ <|im_start|>user
203
+ {message}<|im_end|>
204
+ <|im_start|>assistant
205
+ ```
206
+
207
+ ### Run it locally (GGUF)
208
+
209
+ Because it's standard Llama format, you can convert to GGUF for Ollama / LM Studio / llama.cpp:
210
+
211
+ ```bash
212
+ python llama.cpp/convert_hf_to_gguf.py ./AlterEgo --outfile alterego-f16.gguf --outtype f16
213
+ ```
214
+
215
+ ## Limitations
216
+
217
+ AlterEgo is a 373M-parameter model trained on a modest token budget, and it behaves like one:
218
+
219
+ - **Capability** - it can be factually wrong, repeat itself, and lose coherence on long or complex prompts. By its own (default) system prompt, it is "better at chatting than at answering questions."
220
+ - **Language** - English only.
221
+ - **Safety** - it is **not** safety- or preference-tuned (no RLHF/DPO). It can produce incorrect, biased, or undesirable content and must not be deployed in user-facing settings without additional safeguards.
222
+ - **Bias** - it inherits biases from FineWeb-Edu (web text) and UltraChat.
223
+
224
+ ## License
225
+
226
+ Released under the Apache 2.0 license. Training data is governed by the respective licenses of FineWeb-Edu and UltraChat-200K.
227
+
228
+ ## Citation
229
+
230
+ ```bibtex
231
+ @misc{alterego2026,
232
+ title = {AlterEgo: A 373M language model trained from scratch},
233
+ author = {J-bom},
234
+ year = {2026},
235
+ url = {https://github.com/J-bom/AlterEgo}
236
+ }
237
+ ```
238
+
239
+ **Credits** - datasets: FineWeb-Edu (HuggingFaceFW), UltraChat-200K (HuggingFaceH4). Architecture follows the modern Llama-style design (RoPE, GQA, SwiGLU, RMSNorm); implementation, training, and serving by the author.