gulding commited on
Commit
06ba4fd
Β·
verified Β·
1 Parent(s): c1009d7

Update Model Card for Hugging Face audience

Browse files
Files changed (1) hide show
  1. README.md +110 -121
README.md CHANGED
@@ -1,121 +1,110 @@
1
- ---
2
- base_model: gulding/EmsyAI
3
- library_name: emsyai
4
- license: mit
5
- tags:
6
- - emsyai
7
- - pytorch
8
- - custom-architecture
9
- ---
10
- # EmsyAI 🧠
11
-
12
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
13
- [![Python: 3.12](https://img.shields.io/badge/Python-3.12-blue.svg)](https://www.python.org/)
14
- [![PyTorch: 2.5.1+cu121](https://img.shields.io/badge/PyTorch-CUDA%2012.1-red.svg)](https://pytorch.org/)
15
- [![Hugging Face: EmsyAI](https://img.shields.io/badge/HuggingFace-gulding%2FEmsyAI-orange.svg)](https://huggingface.co/gulding/EmsyAI)
16
-
17
- EmsyAI is a complete, educational, decoder-only Transformer Language Model built entirely from mathematical first principles in pure PyTorch. The goal of this project is to demystify how modern LLMs (like Llama 3, Qwen 2.5, and DeepSeek) operate under the hood.
18
-
19
- This is **not** a wrapper around the `transformers` library. **Every single component was built from scratch:**
20
-
21
- - βœ‚οΈ **Hand-rolled Byte-Pair Encoding (BPE)** Tokenizer with native special token isolation (`<|eos|>`, `<|bos|>`, `<|pad|>`)
22
- - πŸ”„ **Rotary Positional Embeddings (RoPE)** via complex polar tensor rotations
23
- - ⚑ **Grouped Query Attention (GQA)** with fused FlashAttention-2 (PyTorch SDPA)
24
- - πŸšͺ **SwiGLU Feed-Forward Networks** (3-matrix gated layout: $W_1, W_2, W_3$)
25
- - βš–οΈ **RMSNorm Pre-Normalization** with numerical float32 upcasting
26
- - πŸ’Ύ **Step-by-Step KV Caching** for high-throughput autoregressive inference
27
- - 🎯 **Multi-Layer Low-Rank Adaptation (LoRA)** fine-tuning across all 7 linear projections
28
-
29
- ---
30
-
31
- ## πŸ—οΈ Architecture Specifications
32
-
33
- | Specification | EmsyAI-v2 (Current) | EmsyAI-v3 Titan (Active) |
34
- |---|---|---|
35
- | **Parameters** | 88.1 Million (Tied) | 178.5 Million (Tied) |
36
- | **Layers ($L$)** | 12 | 16 |
37
- | **Hidden Dimension ($d_{\text{model}}$)** | 768 | 896 |
38
- | **Attention Heads ($H_q / H_{kv}$)** | 12 Query / 4 KV (GQA 3:1) | 14 Query / 2 KV (GQA 7:1) |
39
- | **FFN Dimension** | 2,048 (SwiGLU) | 2,560 (SwiGLU) |
40
- | **Context Window ($T$)** | 1,024 tokens | 4,096 tokens |
41
- | **Vocabulary Size** | 16,000 (Hybrid BPE) | 16,000 (Hybrid BPE) |
42
- | **Attention Backend** | FlashAttention-2 (`F.scaled_dot_product_attention`) | FlashAttention-2 |
43
-
44
- ---
45
-
46
- ## πŸš€ Quickstart: Run in 5 Seconds via Ollama
47
-
48
- You can run EmsyAI natively without installing PyTorch or GPU drivers:
49
-
50
- ```bash
51
- ollama run hf.co/gulding/EmsyAI
52
- ```
53
-
54
- ## πŸ’» Developer & Training Pipeline
55
-
56
- This project uses [uv](https://github.com/astral-sh/uv) for fast dependency management.
57
-
58
- ```bash
59
- # 1. Clone the repository
60
- git clone https://github.com/gulding/EmsyAI.git
61
- cd EmsyAI
62
-
63
- # 2. Install dependencies (PyTorch with CUDA 12.1)
64
- uv sync
65
- ```
66
-
67
- ### 1. Data Engine & Tokenizer
68
- ```bash
69
- # Stream 100k hybrid samples (Cosmopedia v2 + Python-25k)
70
- uv run python data/download_v2.py
71
-
72
- # Or stream the 150M Token Titan Dataset with Decontamination
73
- uv run python data/download_v3.py
74
-
75
- # Train the 16k BPE Tokenizer
76
- uv run python scripts/train_tokenizer.py
77
- ```
78
-
79
- ### 2. Pretraining
80
- ```bash
81
- # Pretrain EmsyAI-v2 (88M Model)
82
- uv run python -m emsyai.training.train
83
-
84
- # Pretrain EmsyAI-v3 Titan (180M Model @ 4,096 Context)
85
- uv run python -m emsyai.training.train_v3
86
- ```
87
-
88
- ### 3. LoRA Instruction Fine-Tuning (SFT)
89
- ```bash
90
- # Download 20k CodeAlpaca instruction dataset
91
- uv run python -m emsyai.training.download_alpaca
92
-
93
- # Train LoRA adapters across all linear layers
94
- uv run python -m emsyai.training.finetune --steps 10000
95
- ```
96
-
97
- ### 4. Interactive Chat REPL
98
- ```bash
99
- uv run python -m emsyai.chat_instruct \
100
- --base_checkpoint checkpoints_v2/model_step_5000.pt \
101
- --lora_checkpoint checkpoints_v2/lora/instruct_lora_step_10000.pt \
102
- --tokenizer dataset/tokenizer_v2.json
103
- ```
104
-
105
- ## πŸ“ Prompt Template
106
-
107
- When querying the instruction model, use the exact role tags:
108
-
109
- ```text
110
- [USER]
111
- Write a Python function to check if a number is prime.
112
- [MODEL]
113
- ```
114
-
115
- ## πŸ”¬ Mathematical Verification Suite
116
-
117
- Run our verification suite to mathematically validate attention causality and KV-cache consistency:
118
-
119
- ```bash
120
- uv run python scripts/verify_model.py
121
- ```
 
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
+ ---
14
+
15
+ # EmsyAI 🧠
16
+
17
+ EmsyAI is a small, decoder-only transformer language model built entirely from scratch in pure PyTorch β€” no `transformers` library, no pre-built blocks. It's an educational project: the goal is to demystify how models like Llama 3, Qwen 2.5, and DeepSeek work internally by actually building every piece β€” tokenizer, attention, RoPE, KV cache, LoRA β€” by hand.
18
+
19
+ Full training code, data pipeline, and developer docs live on [GitHub](https://github.com/gulding/EmsyAI). This page is about the model artifact itself: what it is, how to run it, and what to expect.
20
+
21
+ > [!WARNING]
22
+ > **Read this before you run it:** EmsyAI is a small model (88M active parameters, hosted here) trained on a small, narrow dataset. It is not a general-purpose assistant and won't behave like one β€” treat it as a working demonstration of a from-scratch LLM pipeline, not a production model. See [Limitations](#limitations).
23
+
24
+ ### Built from scratch:
25
+ - βœ‚οΈ **Hand-rolled byte-pair encoding (BPE)** tokenizer
26
+ - πŸ”„ **Rotary position embeddings (RoPE)** via complex tensor rotation
27
+ - ⚑ **Grouped-query attention (GQA)**, fused via `F.scaled_dot_product_attention`
28
+ - πŸšͺ **SwiGLU** feed-forward layers
29
+ - βš–οΈ **RMSNorm** pre-normalization
30
+ - πŸ’Ύ **KV caching** for autoregressive inference
31
+ - 🎯 **LoRA fine-tuning** across all seven linear projections per block
32
+
33
+ ## Quickstart
34
+
35
+ ```bash
36
+ ollama run hf.co/gulding/EmsyAI
37
+ ```
38
+
39
+ or with `llama.cpp`:
40
+ ```bash
41
+ llama-cli -hf gulding/EmsyAI:F32
42
+ ```
43
+
44
+ > **Note:** This currently pulls EmsyAI-v2 (88M params, 1,024-token context, LoRA-instruction-tuned). EmsyAI-v3 "Titan" (178M params, 4,096-token context) is still training and will replace it here once training and instruction-tuning are finished β€” see [Project Status](#project-status) for where that stands right now.
45
+
46
+ ## Prompt format
47
+
48
+ ```text
49
+ [USER]
50
+ Write a Python function to check if a number is prime.
51
+ [MODEL]
52
+ ```
53
+
54
+ ## What's in this repo
55
+
56
+ | File | What it is | Do you need it? |
57
+ |---|---|---|
58
+ | `emsyai-v2-instruct-f32.gguf` | v2 base model + LoRA adapter, merged and exported to GGUF | **Yes.** This is what Ollama / llama.cpp actually run |
59
+ | `base_model_120M_step_5000.pt` | Raw PyTorch inference weights | Only if loading it back into the [training code](https://github.com/gulding/EmsyAI) |
60
+ | `tokenizer.json` | The trained 16k-vocab BPE tokenizer | Only needed for the PyTorch path, not GGUF |
61
+ | `Modelfile` | Ollama configuration β€” prompt template, stop token, temperature | Used automatically by `ollama run` |
62
+
63
+ *(GGUF export maps the model's tensors onto llama.cpp's naming convention for Ollama/llama.cpp compatibility β€” that's why the architecture shows as `llama` in the metadata above. The training-time implementation itself is fully custom, not derived from Llama's code.)*
64
+
65
+ ## Model Details
66
+
67
+ | Specification | EmsyAI-v2 (hosted here) | EmsyAI-v3 "Titan" (training, not yet published) |
68
+ |---|---|---|
69
+ | Parameters | 88.1M (tied embeddings) | 178.5M (tied embeddings) |
70
+ | Layers | 12 | 16 |
71
+ | Hidden dim | 768 | 896 |
72
+ | Attention heads | 12 Query / 4 KV (GQA 3:1) | 14 Query / 2 KV (GQA 7:1) |
73
+ | FFN dim | 2,048 (SwiGLU) | 2,560 (SwiGLU) |
74
+ | Context window | 1,024 tokens | 4,096 tokens |
75
+ | Vocab size | 16,000 (custom BPE) | 16,000 (custom BPE) |
76
+ | Position encoding | RoPE | RoPE |
77
+
78
+ **Training data (v2):** a ~100k-sample hybrid of Cosmopedia v2 (synthetic educational text) and a Python code subset, tokenized with the project's own BPE tokenizer. Instruction-tuned with LoRA (rank 8, alpha 16) on ~20k CodeAlpaca examples.
79
+
80
+ ## Project status
81
+
82
+ v3 "Titan" is training now, on a ~150M-token decontaminated corpus (checked against HumanEval/MBPP so benchmark problems aren't memorized). In the interest of being upfront about where a from-scratch model actually is mid-training, here's the real trajectory so far β€” perplexity is measured against a 16,000-word vocabulary, so ~16,000 is what random guessing would score:
83
+
84
+ | Step | Validation perplexity | What the sample completions look like |
85
+ |---|---|---|
86
+ | 500 | 36,987 | Empty β€” too early to produce anything |
87
+ | 1,000 | 780 | Empty β€” still too early |
88
+ | 1,500 | 485 | Fluent-sounding prose, not yet coherent |
89
+ | 2,000 | 272 | Python-shaped syntax, not yet logically correct |
90
+
91
+ For example, at step 2,000, prompting with `def calculate_fibonacci(n):` produced:
92
+ ```python
93
+ for j in range(nums) return -1[i] # Return the total += list2.56, 9:4 = 0 for i in arr: x // 2 == 1
94
+ ```
95
+ Recognizably Python-flavored β€” indentation, keywords, a comment β€” but not yet logically sound. That's the expected order for a small model early in training: surface fluency and syntax arrive before semantic correctness. This card will be updated with the v3 GGUF and real samples once training and instruction-tuning are complete.
96
+
97
+ ## Limitations
98
+
99
+ - **Small model, small data.** 88.1M active parameters trained on ~100k documents β€” closer in scale to early GPT-2-class experiments than to a modern assistant model.
100
+ - **Short context.** 1,024 tokens for the hosted v2 model.
101
+ - **No RLHF or preference tuning** β€” only supervised LoRA fine-tuning on instruction-following examples. Expect repetitive, sometimes factually wrong, or off-topic output, especially past a few sentences.
102
+ - **Code it writes may not run.** This project's own benchmark only checks that generated Python parses, not that it's logically correct β€” don't assume otherwise.
103
+ - **English only**, and narrow in domain (educational text and Python code).
104
+
105
+ ## License
106
+ MIT β€” see [LICENSE](https://github.com/gulding/EmsyAI/blob/main/LICENSE).
107
+
108
+ ## Links
109
+ - πŸ’» [Source code, training pipeline, and full docs](https://github.com/gulding/EmsyAI)
110
+ - πŸ› [Issues / discussions](https://github.com/gulding/EmsyAI/issues)