Instructions to use gulding/EmsyAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use gulding/EmsyAI with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf gulding/EmsyAI:F32 # Run inference directly in the terminal: llama cli -hf gulding/EmsyAI:F32
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf gulding/EmsyAI:F32 # Run inference directly in the terminal: llama cli -hf gulding/EmsyAI:F32
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf gulding/EmsyAI:F32 # Run inference directly in the terminal: ./build/bin/llama cli -hf gulding/EmsyAI:F32
Use Docker
docker model run hf.co/gulding/EmsyAI:F32
- Llama new
- LM Studio
- Jan
- vLLM
How to use gulding/EmsyAI with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gulding/EmsyAI" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gulding/EmsyAI", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/gulding/EmsyAI:F32
- Ollama
How to use gulding/EmsyAI with Ollama:
ollama run hf.co/gulding/EmsyAI:F32
- Unsloth Desktop
- Docker Model Runner
How to use gulding/EmsyAI with Docker Model Runner:
docker model run hf.co/gulding/EmsyAI:F32
- Lemonade
How to use gulding/EmsyAI with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull gulding/EmsyAI:F32
Run and chat with the model
lemonade run user.EmsyAI-F32
List all available models
lemonade list
- Atomic Chat
Update Model Card
Browse files
README.md
CHANGED
|
@@ -1,99 +1,121 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: mit
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
tags:
|
| 6 |
-
-
|
| 7 |
- pytorch
|
| 8 |
-
-
|
| 9 |
-
- lora
|
| 10 |
-
- code-generation
|
| 11 |
---
|
| 12 |
-
|
| 13 |
# EmsyAI π§
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
- Hand-rolled Byte-Pair Encoding (BPE) Tokenizer
|
| 19 |
-
- Rotary Positional Embeddings (RoPE)
|
| 20 |
-
- Grouped Query Attention (GQA)
|
| 21 |
-
- SwiGLU Feed-Forward Networks
|
| 22 |
-
- RMSNorm Pre-Normalization
|
| 23 |
-
- KV Caching Autoregressive Inference
|
| 24 |
-
- Low-Rank Adaptation (LoRA) Fine-tuning
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
- **Parameters**: ~89 Million (120M class with weight tying)
|
| 30 |
-
- **Layers**: 12
|
| 31 |
-
- **Hidden Dimension**: 768
|
| 32 |
-
- **Attention Heads**: 12 Query, 4 KV (GQA)
|
| 33 |
-
- **FFN Hidden Dimension**: 2048
|
| 34 |
-
- **Context Length**: 1024
|
| 35 |
-
- **Vocab Size**: 16000
|
| 36 |
-
- **Attention Kernel**: PyTorch Native FlashAttention-2 (SDPA)
|
| 37 |
|
| 38 |
-
## π
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
```bash
|
| 43 |
-
|
| 44 |
-
uv sync
|
| 45 |
```
|
| 46 |
|
| 47 |
-
##
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
```bash
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
```
|
| 53 |
|
| 54 |
-
### 1.
|
| 55 |
-
The pure-Python BPE tokenizer is trained on the CPython source code.
|
| 56 |
```bash
|
| 57 |
-
#
|
| 58 |
uv run python data/download_v2.py
|
| 59 |
|
| 60 |
-
#
|
|
|
|
|
|
|
|
|
|
| 61 |
uv run python scripts/train_tokenizer.py
|
| 62 |
```
|
| 63 |
|
| 64 |
-
### 2.
|
| 65 |
-
The training loop features AdamW, Cosine Learning Rate decay with linear warmup, Gradient Accumulation, and `bfloat16` Mixed Precision.
|
| 66 |
-
|
| 67 |
```bash
|
|
|
|
| 68 |
uv run python -m emsyai.training.train
|
| 69 |
-
```
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
|
|
|
| 73 |
|
|
|
|
| 74 |
```bash
|
| 75 |
-
# Download 20k CodeAlpaca instruction
|
| 76 |
uv run python -m emsyai.training.download_alpaca
|
| 77 |
|
| 78 |
-
# Train
|
| 79 |
uv run python -m emsyai.training.finetune --steps 10000
|
| 80 |
```
|
| 81 |
|
| 82 |
-
### 4.
|
| 83 |
-
We include a custom `export_gguf.py` script that merges the base weights with the LoRA matrices and exports the full PyTorch model directly to a `.gguf` file compatible with `llama.cpp`.
|
| 84 |
-
|
| 85 |
```bash
|
| 86 |
-
uv run python
|
|
|
|
|
|
|
|
|
|
| 87 |
```
|
| 88 |
|
| 89 |
-
##
|
| 90 |
-
You can interact with the instruction-tuned model via a command-line REPL. It implements KV caching, top-k/top-p sampling, and repetition penalties.
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
```
|
| 95 |
|
| 96 |
-
##
|
| 97 |
-
|
| 98 |
-
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
[](https://opensource.org/licenses/MIT)
|
| 13 |
+
[](https://www.python.org/)
|
| 14 |
+
[](https://pytorch.org/)
|
| 15 |
+
[](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 |
+
```
|