gulding commited on
Commit
0562ca6
·
verified ·
1 Parent(s): f8ec197

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +52 -0
README.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - from-scratch
7
+ - pytorch
8
+ - educational
9
+ - lora
10
+ - code-generation
11
+ ---
12
+
13
+ # EmsyAI 🧠
14
+
15
+ EmsyAI is a **28 Million Parameter Decoder-only Transformer** built entirely from scratch in pure PyTorch for educational purposes. It is not a wrapper around the `transformers` library, but a fully hand-rolled implementation of a modern LLM architecture (heavily inspired by Llama 3).
16
+
17
+ ## 🏗️ Model Architecture
18
+
19
+ - **Parameters**: ~28 Million
20
+ - **Layers**: 8
21
+ - **Hidden Dimension**: 512
22
+ - **Attention Heads**: 8 Query, 4 KV (Grouped Query Attention)
23
+ - **FFN Hidden Dimension**: 1408 (SwiGLU)
24
+ - **Context Length**: 512
25
+ - **Vocab Size**: 8000
26
+ - **Normalization**: Pre-RMSNorm
27
+ - **Positional Encoding**: Rotary Positional Embeddings (RoPE)
28
+
29
+ ## 🔧 Training Details
30
+
31
+ ### Phase 1: Base Pretraining
32
+ The base model was pretrained from scratch on ~40MB of Python source code (from the CPython repository) using a hand-rolled Byte-Pair Encoding (BPE) tokenizer.
33
+ - **Optimizer**: AdamW with `bfloat16` mixed precision
34
+ - **Learning Rate**: Cosine decay with linear warmup
35
+ - **Final Perplexity**: ~10.77
36
+
37
+ ### Phase 2: Instruction Fine-Tuning (LoRA)
38
+ The model was fine-tuned to follow instructions using a custom, from-scratch Low-Rank Adaptation (LoRA) implementation.
39
+ - **Dataset**: `CodeAlpaca-20k`
40
+ - **LoRA Targets**: All linear layers (Q, K, V, O, w1, w2, w3)
41
+ - **Trainable Parameters**: 598,016 (2.11%)
42
+ - **Final Loss**: ~1.92
43
+
44
+ ## 💻 Usage
45
+
46
+ To use this model, you will need the custom inference code from the GitHub repository:
47
+ [https://github.com/gulding/EmsyAI](https://github.com/gulding/EmsyAI)
48
+
49
+ Because the tokenizer and architecture are custom-built, this model is **not directly compatible** with the `transformers` `AutoModel` API. It is designed to be run using the `chat_instruct.py` script provided in the GitHub repo.
50
+
51
+ ## 🎓 Educational Value
52
+ This project demonstrates how to build every layer of a modern Large Language Model from mathematical first principles, including the data pipeline, the Transformer core, LoRA adapters, and autoregressive KV-caching generation.