gulding commited on
Commit
a69b355
·
verified ·
1 Parent(s): 1a39fa5

Update V4 Model Card

Browse files
Files changed (1) hide show
  1. README.md +52 -31
README.md CHANGED
@@ -12,65 +12,86 @@ tags:
12
 
13
  # EmsyAI (V4)
14
 
15
- EmsyAI is an open-source, from-scratch 196M parameter Large Language Model built strictly as an educational journey. The goal of this project is to demystify LLM creation by handling every single step locally: writing a custom BPE tokenizer, coding a Llama-style Transformer in pure PyTorch, pretraining on 2 Billion tokens, running LoRA instruction tuning, and finally exporting to GGUF for edge deployment via Ollama.
 
16
 
17
- ## 🚀 V4 Architecture
18
 
19
- The V4 iteration is the most advanced version of EmsyAI yet, scaling to almost 200 Million parameters with a massive 4096-token context window.
20
 
21
- - **Parameters:** ~196.7M (Base) + 2.3M (LoRA Adapters)
22
- - **Training Tokens:** 1.96 Billion
23
- - **Context Length:** 4096
24
- - **Dim:** 1024
25
- - **Layers:** 16
26
- - **Heads:** 16 (Q), 4 (KV) (Grouped Query Attention)
27
- - **FFN Dim:** 2816 (SwiGLU)
28
- - **RoPE Theta:** 10,000.0
29
 
30
- ## 📈 Pretraining Results
 
 
 
 
 
 
 
 
 
31
 
32
- The model was pretrained for 15,000 steps using an aggressive learning rate schedule. Despite running on consumer hardware, the training run achieved a flawlessly smooth exponential decay in both cross-entropy loss and validation perplexity, ultimately converging at a final perplexity of **5.86**.
 
 
33
 
34
  ![V4 Training Curve](v4_training_curve.png)
35
 
36
  ## 🧪 Evaluation & Data Contamination
37
 
38
- After pretraining, EmsyAI V4 was fine-tuned for 10,000 steps using LoRA adapters on the ~20k `CodeAlpaca` instruction dataset to teach it the standard `[USER]` / `[MODEL]` chat format.
 
 
39
 
40
- **HumanEval pass@1 Score:** `0.0%`
41
 
42
- *Wait, 0.0%? Is that a failure?*
43
- Actually, this is a massive success! Modern models that ace HumanEval are typically 40x larger (8B+) and trained on 1,500x more data (3T+ tokens). A 196M parameter model scoring 0% is mathematically expected.
44
 
45
- More importantly, **we audited the CodeAlpaca instruction dataset for contamination** before fine-tuning. Using an aggressive 13-gram exact match technique, we discovered exactly **1,644 sequences** in the open-source CodeAlpaca dataset that perfectly leaked HumanEval test logic (such as Heron's formula and prime number checks).
46
 
47
- Despite this verifiable data leakage, EmsyAI scored 0.0%, proving that the model did not blindly overfit or memorize the test set during the LoRA phase. It remains an honest, baseline 196M model!
48
 
49
- ## 💻 How to Run (Ollama)
 
 
 
 
 
50
 
51
- EmsyAI V4 has been fused and exported to the highly optimized GGUF format for CPU/GPU inference.
 
 
 
 
 
 
 
52
 
53
- If you have [Ollama](https://ollama.com/) installed, you can run EmsyAI directly:
 
 
54
 
55
  ```bash
56
  # Clone the repository
57
  git clone https://github.com/gulding/EmsyAI.git
58
  cd EmsyAI
59
 
60
- # Create the Ollama model using the provided Modelfile
61
- ollama create emsyai-v4 -f Modelfile
62
 
63
- # Start chatting!
 
64
  ollama run emsyai-v4
65
  ```
66
 
67
- ## 🧠 What's Next (V5 Blueprint)
68
 
69
- While V4 was a massive success, we are already blueprinting **V5**, which will adopt bleeding-edge insights inspired by the Qwen 3 architecture:
70
- 1. **QK-Norm:** Injecting RMSNorm on the Query and Key states to completely eliminate attention logit exploding (a major instability during V4 scaling).
71
- 2. **Document-Aware Packing:** Upgrading our tokenization pipeline to respect document boundaries instead of blindly concatenating texts, preventing cross-document attention poisoning.
72
- 3. **Tokenizer Rebuild:** Fixing a critical collision where bytes 0-3 currently overlap with special tokens, and expanding the vocabulary to 32K or 64K.
73
- 4. **RoPE Scaling:** Lowering `head_dim` back to 64 and adjusting `rope_theta` to 500,000.0 to better balance high-frequency and low-frequency positional perception at context=4096.
74
 
75
  ---
76
  *Built with ❤️ in pure PyTorch.*
 
12
 
13
  # EmsyAI (V4)
14
 
15
+ [![Hugging Face Model](https://img.shields.io/badge/🤗%20Hugging%20Face-EmsyAI--V4-yellow)](https://huggingface.co/gulding/EmsyAI)
16
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
17
 
18
+ EmsyAI is a 196M parameter language model I built from scratch to learn how LLMs actually work under the hood.
19
 
20
+ 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.
21
 
22
+ ## 📐 Architecture Evolution
 
 
 
 
 
 
 
23
 
24
+ | Specification | EmsyAI V3 (Titan) | EmsyAI V4 (Current) |
25
+ |---|---|---|
26
+ | **Active Parameters** | 153.8M | **196.7M** (+2.3M LoRA) |
27
+ | **Training Tokens** | ~150M | **1.96 Billion** |
28
+ | **Context Window** | 4,096 tokens | 4,096 tokens |
29
+ | **Hidden Dimension** | 896 | **1,024** |
30
+ | **Layers** | 16 | 16 |
31
+ | **Attention Mechanism** | GQA (14 Q / 2 KV) | **GQA (16 Q / 4 KV)** |
32
+ | **FFN Dimension** | 2,560 (SwiGLU) | **2,816 (SwiGLU)** |
33
+ | **Validation Perplexity** | ~14.2 | **5.86** |
34
 
35
+ ## 📉 Pretraining Hardware & Results
36
+
37
+ 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.
38
 
39
  ![V4 Training Curve](v4_training_curve.png)
40
 
41
  ## 🧪 Evaluation & Data Contamination
42
 
43
+ After pretraining, I fine-tuned the model using LoRA on the ~20k `CodeAlpaca` instruction dataset to teach it the standard `[USER]` / `[MODEL]` prompt format.
44
+
45
+ **HumanEval pass@1 Score:** `0.0%` *(Expected Baseline)*
46
 
47
+ *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.
48
 
49
+ 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.
 
50
 
51
+ ## 💬 Sample Output
52
 
53
+ 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.
54
 
55
+ **Prompt:**
56
+ ```text
57
+ [USER]
58
+ Write a python function to check if a number is even.
59
+ [MODEL]
60
+ ```
61
 
62
+ **Completion (EmsyAI V4):**
63
+ ```python
64
+ def is_even(num):
65
+ if num % 2 == 0:
66
+ return True
67
+ else:
68
+ return False
69
+ ```
70
 
71
+ ## 💻 How to Run locally
72
+
73
+ 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.
74
 
75
  ```bash
76
  # Clone the repository
77
  git clone https://github.com/gulding/EmsyAI.git
78
  cd EmsyAI
79
 
80
+ # Download the V4 GGUF weights from Hugging Face
81
+ huggingface-cli download gulding/EmsyAI emsyai-v4-instruct-f32.gguf --local-dir .
82
 
83
+ # Create and run the Ollama model
84
+ ollama create emsyai-v4 -f Modelfile
85
  ollama run emsyai-v4
86
  ```
87
 
88
+ ## 🛠️ Lessons Learned (Blueprint for V5)
89
 
90
+ Building this taught me a lot about transformer stability. Here is what I'm fixing for V5:
91
+ 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.
92
+ 2. **Document-Aware Packing:** Currently, the tokenizer blindly concatenates text. V5 will respect document boundaries to prevent cross-document attention poisoning.
93
+ 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.
94
+ 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.
95
 
96
  ---
97
  *Built with ❤️ in pure PyTorch.*