gulding commited on
Commit
27825fd
·
verified ·
1 Parent(s): 6b68b7a

Update V4 Model Card

Browse files
Files changed (1) hide show
  1. README.md +97 -97
README.md CHANGED
@@ -1,97 +1,97 @@
1
- ---
2
- license: mit
3
- pipeline_tag: text-generation
4
- language:
5
- - en
6
- tags:
7
- - gguf
8
- - llama.cpp
9
- - ollama
10
- - from-scratch
11
- - educational
12
- - pytorch
13
- - lora
14
- ---
15
-
16
- # EmsyAI (V4)
17
-
18
- [![Hugging Face Model](https://img.shields.io/badge/🤗%20Hugging%20Face-EmsyAI--V4-yellow)](https://huggingface.co/gulding/EmsyAI)
19
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
20
-
21
- EmsyAI is a 196M parameter language model I built from scratch to learn how LLMs actually work under the hood.
22
-
23
- Instead of just fine-tuning an existing model, I wanted to handle the entire pipeline locally: writing a custom BPE tokenizer, building a Llama-style transformer in PyTorch, pretraining it on 2 billion tokens, applying LoRA instruction tuning, and exporting it to GGUF so it runs natively in Ollama.
24
-
25
- ## 📐 Architecture Evolution
26
-
27
- | Specification | EmsyAI V3 (Titan) | EmsyAI V4 (Current) |
28
- |---|---|---|
29
- | **Active Parameters** | 153.8M | **196.7M** (+2.3M LoRA) |
30
- | **Training Tokens** | ~150M | **1.96 Billion** |
31
- | **Context Window** | 4,096 tokens | 4,096 tokens |
32
- | **Hidden Dimension** | 896 | **1,024** |
33
- | **Layers** | 16 | 16 |
34
- | **Attention Mechanism** | GQA (14 Q / 2 KV) | **GQA (16 Q / 4 KV)** |
35
- | **FFN Dimension** | 2,560 (SwiGLU) | **2,816 (SwiGLU)** |
36
- | **Validation Perplexity** | ~14.2 | **5.86** |
37
-
38
- ## 📉 Pretraining Hardware & Results
39
-
40
- Pretrained on 1x NVIDIA RTX GPU (24GB VRAM) using mixed-precision FP16 and AdamW with cosine decay. The model was trained for 15,000 steps. The loss curve behaved surprisingly well, decaying smoothly down to a final validation perplexity of 5.86.
41
-
42
- ![V4 Training Curve](v4_training_curve.png)
43
-
44
- ## 🧪 Evaluation & Data Contamination
45
-
46
- After pretraining, I fine-tuned the model using LoRA on the ~20k `CodeAlpaca` instruction dataset to teach it the standard `[USER]` / `[MODEL]` prompt format.
47
-
48
- **HumanEval pass@1 Score:** `0.0%` *(Expected Baseline)*
49
-
50
- *Analysis:* Models that pass HumanEval are typically 40x-350x larger (8B-70B+) and trained on trillions of tokens. For a 196M parameter model, a 0.0% score is mathematically expected and serves as a strict baseline.
51
-
52
- More interestingly, before fine-tuning, I audited the open-source CodeAlpaca dataset for contamination. Using a 13-gram exact match technique, I found 1,644 sequences in CodeAlpaca that perfectly leaked HumanEval test logic (like Heron's formula and prime number checks). Despite this verifiable data leakage in the training set, the model still scored 0.0%—meaning it didn't just blindly overfit or memorize the test set during instruction tuning. It remains an honest, baseline 196M model.
53
-
54
- ## 💬 Sample Output
55
-
56
- Here is an example of how the 196M model responds post-instruction tuning. While it lacks the deep reasoning of a 7B model, it successfully internalizes Python syntax and basic structures.
57
-
58
- **Prompt:**
59
- ```text
60
- [USER]
61
- Write a python function to check if a number is even.
62
- [MODEL]
63
- ```
64
-
65
- **Completion (EmsyAI V4):**
66
- ```python
67
- def is_even(num):
68
- if num % 2 == 0:
69
- return True
70
- else:
71
- return False
72
- ```
73
-
74
- ## 💻 How to Run locally
75
-
76
- The model is exported to GGUF and can be run instantly via Ollama. Because the `.gguf` file is too large for GitHub (and `.gitignore`d), you'll pull the weights directly from Hugging Face first.
77
-
78
- ```bash
79
- # Clone the repository
80
- git clone https://github.com/gulding/EmsyAI.git
81
- cd EmsyAI
82
-
83
- # Download the V4 GGUF weights from Hugging Face
84
- huggingface-cli download gulding/EmsyAI emsyai-v4-instruct-f32.gguf --local-dir .
85
-
86
- # Create and run the Ollama model
87
- ollama create emsyai-v4 -f Modelfile
88
- ollama run emsyai-v4
89
- ```
90
-
91
- ## 🛠️ Lessons Learned (Blueprint for V5)
92
-
93
- Building this taught me a lot about transformer stability. Here is what I'm fixing for V5:
94
- 1. **QK-Norm:** I ran into severe attention logit explosions during scaling. V5 will inject RMSNorm on the Query and Key states to stabilize training.
95
- 2. **Document-Aware Packing:** Currently, the tokenizer blindly concatenates text. V5 will respect document boundaries to prevent cross-document attention poisoning.
96
- 3. **Tokenizer Byte Collisions:** I realized late in training that bytes 0-3 currently overlap with special tokens. I'll be rebuilding the tokenizer from scratch and expanding the vocab to 32K.
97
- 4. **RoPE Scaling:** Lowering `head_dim` to 64 and adjusting `rope_theta` to 500,000 to better balance high/low frequency positional data at 4096 context.
 
1
+ ---
2
+ license: mit
3
+ pipeline_tag: text-generation
4
+ language:
5
+ - en
6
+ tags:
7
+ - gguf
8
+ - llama.cpp
9
+ - ollama
10
+ - from-scratch
11
+ - educational
12
+ - pytorch
13
+ - lora
14
+ ---
15
+
16
+ # EmsyAI (V4)
17
+
18
+ [![Hugging Face Model](https://img.shields.io/badge/🤗%20Hugging%20Face-EmsyAI--V4-yellow)](https://huggingface.co/gulding/EmsyAI)
19
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
20
+
21
+ EmsyAI is a 196M parameter language model I built from scratch to learn how LLMs actually work under the hood.
22
+
23
+ Instead of just fine-tuning an existing model, I wanted to handle the entire pipeline locally: writing a custom BPE tokenizer, building a Llama-style transformer in PyTorch, pretraining it on 2 billion tokens, applying LoRA instruction tuning, and exporting it to GGUF so it runs natively in Ollama.
24
+
25
+ ## 📐 Architecture Evolution
26
+
27
+ | Specification | EmsyAI V3 (Titan) | EmsyAI V4 (Current) |
28
+ |---|---|---|
29
+ | **Active Parameters** | 153.8M | **196.7M** (+2.3M LoRA) |
30
+ | **Training Tokens** | ~150M | **1.96 Billion** |
31
+ | **Context Window** | 4,096 tokens | 4,096 tokens |
32
+ | **Hidden Dimension** | 896 | **1,024** |
33
+ | **Layers** | 16 | 16 |
34
+ | **Attention Mechanism** | GQA (14 Q / 2 KV) | **GQA (16 Q / 4 KV)** |
35
+ | **FFN Dimension** | 2,560 (SwiGLU) | **2,816 (SwiGLU)** |
36
+ | **Validation Perplexity** | ~14.2 | **5.86** |
37
+
38
+ ## 📉 Pretraining Hardware & Results
39
+
40
+ Pretrained on 1x NVIDIA RTX GPU (24GB VRAM) using mixed-precision FP16 and AdamW with cosine decay. The model was trained for 15,000 steps. The loss curve behaved surprisingly well, decaying smoothly down to a final validation perplexity of 5.86.
41
+
42
+ ![V4 Training Curve](v4_training_curve.png)
43
+
44
+ ## 🧪 Evaluation & Data Contamination
45
+
46
+ After pretraining, I fine-tuned the model using LoRA on the ~20k `CodeAlpaca` instruction dataset to teach it the standard `[USER]` / `[MODEL]` prompt format.
47
+
48
+ **HumanEval pass@1 Score:** `0.0%` *(Expected Baseline)*
49
+
50
+ *Analysis:* Models that pass HumanEval are typically 40x-350x larger (8B-70B+) and trained on trillions of tokens. For a 196M parameter model, a 0.0% score is mathematically expected and serves as a strict baseline.
51
+
52
+ More interestingly, before fine-tuning, I audited the open-source CodeAlpaca dataset for contamination. Using a 13-gram exact match technique, I found 1,644 sequences in CodeAlpaca that perfectly leaked HumanEval test logic (like Heron's formula and prime number checks). Despite this verifiable data leakage in the training set, the model still scored 0.0%—meaning it didn't just blindly overfit or memorize the test set during instruction tuning. It remains an honest, baseline 196M model.
53
+
54
+ ## 💬 Sample Output
55
+
56
+ Here is an example of how the 196M model responds post-instruction tuning. While it lacks the deep reasoning of a 7B model, it successfully internalizes Python syntax and basic structures.
57
+
58
+ **Prompt:**
59
+ ```text
60
+ [USER]
61
+ Write a python function to check if a number is even.
62
+ [MODEL]
63
+ ```
64
+
65
+ **Completion (EmsyAI V4):**
66
+ ```python
67
+ def is_even(num):
68
+ if num % 2 == 0:
69
+ return True
70
+ else:
71
+ return False
72
+ ```
73
+
74
+ ## 💻 How to Run locally
75
+
76
+ The model is exported to GGUF and can be run instantly via Ollama. Because the `.gguf` file is too large for GitHub (and `.gitignore`d), you'll pull the weights directly from Hugging Face first.
77
+
78
+ ```bash
79
+ # Clone the repository
80
+ git clone https://github.com/gulding/EmsyAI.git
81
+ cd EmsyAI
82
+
83
+ # Download the V4 GGUF weights from Hugging Face
84
+ huggingface-cli download gulding/EmsyAI emsyai-v4-instruct-f32.gguf --local-dir .
85
+
86
+ # Create and run the Ollama model
87
+ ollama create emsyai-v4 -f Modelfile
88
+ ollama run emsyai-v4
89
+ ```
90
+
91
+ ## 🛠️ Lessons Learned (Blueprint for V5)
92
+
93
+ Building this taught me a lot about transformer stability. Here is what I'm fixing for V5:
94
+ 1. **QK-Norm:** I ran into severe attention logit explosions during scaling. V5 will inject RMSNorm on the Query and Key states to stabilize training.
95
+ 2. **Document-Aware Packing:** Currently, the tokenizer blindly concatenates text. V5 will respect document boundaries to prevent cross-document attention poisoning.
96
+ 3. **Tokenizer Byte Collisions:** I realized late in training that bytes 0-3 currently overlap with special tokens. I'll be rebuilding the tokenizer from scratch and expanding the vocab to 32K.
97
+ 4. **RoPE Scaling:** Lowering `head_dim` to 64 and adjusting `rope_theta` to 500,000 to better balance high/low frequency positional data at 4096 context.