jbomdev commited on
Commit
04b6e89
·
verified ·
1 Parent(s): 603b7a6

Upload 10 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/sft_loss.png filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
AlterEgo_HF_model_card.md ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.
assets/pretraining_loss.png ADDED
assets/sft_loss.png ADDED

Git LFS Details

  • SHA256: e92fced2d75e4b81e8bed14128ae473ffd36c9d51316931a2274e66f9f547e46
  • Pointer size: 131 Bytes
  • Size of remote file: 120 kB
assets/training_dynamics.png ADDED
chat_template.jinja ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {% for m in messages %}{{ '<|im_start|>' + m['role'] + '
2
+ ' + m['content'] + '<|im_end|>' + '
3
+ ' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
4
+ ' }}{% endif %}
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "dtype": "float32",
9
+ "eos_token_id": 2,
10
+ "head_dim": 64,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 1024,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 2816,
15
+ "max_position_embeddings": 2048,
16
+ "mlp_bias": false,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 16,
19
+ "num_hidden_layers": 24,
20
+ "num_key_value_heads": 4,
21
+ "pad_token_id": null,
22
+ "pretraining_tp": 1,
23
+ "rms_norm_eps": 1e-06,
24
+ "rope_parameters": {
25
+ "rope_theta": 10000.0,
26
+ "rope_type": "default"
27
+ },
28
+ "tie_word_embeddings": true,
29
+ "transformers_version": "5.3.0",
30
+ "use_cache": true,
31
+ "vocab_size": 100352
32
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_sample": true,
3
+ "eos_token_id": [
4
+ 100278,
5
+ 100257
6
+ ],
7
+ "max_new_tokens": 256,
8
+ "pad_token_id": 100257,
9
+ "repetition_penalty": 1.1,
10
+ "temperature": 0.7,
11
+ "top_k": 50,
12
+ "transformers_version": "5.3.0"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13f78762e91585b9c940c3b83955da6142e1721e5f5772086fdb486ac0714817
3
+ size 1493397720
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e65ad83c582f4ecc2425830ba8ec1ae33c7e548394c0c80b18c1d0f346ce5370
3
+ size 13865537
tokenizer_config.json ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "eos_token": "<|im_end|>",
4
+ "extra_special_tokens": [
5
+ "<|reserved_100256|>",
6
+ "<|endoftext|>",
7
+ "<|fim_prefix|>",
8
+ "<|fim_middle|>",
9
+ "<|fim_suffix|>",
10
+ "<|reserved_100261|>",
11
+ "<|reserved_100262|>",
12
+ "<|reserved_100263|>",
13
+ "<|reserved_100264|>",
14
+ "<|reserved_100265|>",
15
+ "<|reserved_100266|>",
16
+ "<|reserved_100267|>",
17
+ "<|reserved_100268|>",
18
+ "<|reserved_100269|>",
19
+ "<|reserved_100270|>",
20
+ "<|reserved_100271|>",
21
+ "<|reserved_100272|>",
22
+ "<|reserved_100273|>",
23
+ "<|reserved_100274|>",
24
+ "<|reserved_100275|>",
25
+ "<|endofprompt|>",
26
+ "<|im_start|>",
27
+ "<|im_end|>",
28
+ "<|reserved_100279|>",
29
+ "<|reserved_100280|>",
30
+ "<|reserved_100281|>",
31
+ "<|reserved_100282|>",
32
+ "<|reserved_100283|>",
33
+ "<|reserved_100284|>",
34
+ "<|reserved_100285|>",
35
+ "<|reserved_100286|>",
36
+ "<|reserved_100287|>",
37
+ "<|reserved_100288|>",
38
+ "<|reserved_100289|>",
39
+ "<|reserved_100290|>",
40
+ "<|reserved_100291|>",
41
+ "<|reserved_100292|>",
42
+ "<|reserved_100293|>",
43
+ "<|reserved_100294|>",
44
+ "<|reserved_100295|>",
45
+ "<|reserved_100296|>",
46
+ "<|reserved_100297|>",
47
+ "<|reserved_100298|>",
48
+ "<|reserved_100299|>",
49
+ "<|reserved_100300|>",
50
+ "<|reserved_100301|>",
51
+ "<|reserved_100302|>",
52
+ "<|reserved_100303|>",
53
+ "<|reserved_100304|>",
54
+ "<|reserved_100305|>",
55
+ "<|reserved_100306|>",
56
+ "<|reserved_100307|>",
57
+ "<|reserved_100308|>",
58
+ "<|reserved_100309|>",
59
+ "<|reserved_100310|>",
60
+ "<|reserved_100311|>",
61
+ "<|reserved_100312|>",
62
+ "<|reserved_100313|>",
63
+ "<|reserved_100314|>",
64
+ "<|reserved_100315|>",
65
+ "<|reserved_100316|>",
66
+ "<|reserved_100317|>",
67
+ "<|reserved_100318|>",
68
+ "<|reserved_100319|>",
69
+ "<|reserved_100320|>",
70
+ "<|reserved_100321|>",
71
+ "<|reserved_100322|>",
72
+ "<|reserved_100323|>",
73
+ "<|reserved_100324|>",
74
+ "<|reserved_100325|>",
75
+ "<|reserved_100326|>",
76
+ "<|reserved_100327|>",
77
+ "<|reserved_100328|>",
78
+ "<|reserved_100329|>",
79
+ "<|reserved_100330|>",
80
+ "<|reserved_100331|>",
81
+ "<|reserved_100332|>",
82
+ "<|reserved_100333|>",
83
+ "<|reserved_100334|>",
84
+ "<|reserved_100335|>",
85
+ "<|reserved_100336|>",
86
+ "<|reserved_100337|>",
87
+ "<|reserved_100338|>",
88
+ "<|reserved_100339|>",
89
+ "<|reserved_100340|>",
90
+ "<|reserved_100341|>",
91
+ "<|reserved_100342|>",
92
+ "<|reserved_100343|>",
93
+ "<|reserved_100344|>",
94
+ "<|reserved_100345|>",
95
+ "<|reserved_100346|>",
96
+ "<|reserved_100347|>",
97
+ "<|reserved_100348|>",
98
+ "<|reserved_100349|>",
99
+ "<|reserved_100350|>",
100
+ "<|reserved_100351|>"
101
+ ],
102
+ "model_max_length": 1000000000000000019884624838656,
103
+ "tokenizer_class": "TokenizersBackend"
104
+ }