AbdelrhmanEbied commited on
Commit
bb4d647
Β·
verified Β·
1 Parent(s): 5752d99

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +180 -1
README.md CHANGED
@@ -15,4 +15,183 @@ tags:
15
  - llm
16
  - text-generation
17
  - causal-lm
18
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  - llm
16
  - text-generation
17
  - causal-lm
18
+ ---
19
+ # Model Card for Tiny-MoE
20
+
21
+ <!-- Provide a quick summary of what the model is/does. -->
22
+
23
+ Tiny-MoE is a lightweight Mixture-of-Experts (MoE) decoder-only language model implemented entirely from scratch in native PyTorch, and trained end-to-end on Kaggle's free-tier hardware (2Γ— NVIDIA T4 GPUs).
24
+
25
+ ## Model Details
26
+
27
+ ### Model Description
28
+
29
+ <!-- Provide a longer summary of what this model is. -->
30
+
31
+ Tiny-MoE is an open-source, highly efficient Mixture-of-Experts language model built entirely from scratch using native PyTorch, without relying on high-level modeling frameworks. It was designed to maximize compute efficiency on Kaggle's free-tier cloud hardware and serves as a bottom-up implementation of modern LLM techniques, including Multi-head Latent Attention (MLA), YaRN long-context extension, and optimized MoE routing.
32
+
33
+ The model is a 14-layer decoder-only Transformer. Each layer combines an MLA attention block with a Mixture-of-Experts feed-forward network made up of 8 routed experts, 1 shared expert, and Top-2 routing. Weight absorption can be enabled at inference time to reduce computation.
34
+
35
+ - **Developed by:** Abdelrhman Ebied
36
+ - **Funded by:** Self-funded (trained on Kaggle's free-tier compute)
37
+ - **Shared by:** Abdelrhman Ebied
38
+ - **Model type:** MoE decoder-only Transformer (causal language model)
39
+ - **Language(s) (NLP):** English
40
+ - **License:** Apache License 2.0
41
+ - **Finetuned from model:** Not applicable β€” trained from scratch (base model)
42
+
43
+ ### Model Sources
44
+
45
+ <!-- Provide the basic links for the model. -->
46
+
47
+ - **Repository:** https://github.com/AbdelrhmanEbied/Tiny-MoE
48
+
49
+ ## Uses
50
+
51
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
52
+
53
+ ### Direct Use
54
+
55
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
56
+
57
+ Tiny-MoE is a base (pretrained) model β€” it has not been instruction fine-tuned. It can be used directly for raw text generation / completion via the project's inference pipeline, which supports temperature sampling, top-k sampling, top-p (nucleus) sampling, repetition penalty, and n-gram blocking. As a base model, it is not expected to reliably follow instructions or hold a conversation out of the box.
58
+
59
+ ## Bias, Risks, and Limitations
60
+
61
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
62
+
63
+ Tiny-MoE is primarily a research and learning project, and is currently a base model (no instruction fine-tuning). It should not be expected to follow instructions, hold a conversation, or produce chat-style responses reliably β€” its outputs are raw text continuations shaped by its pretraining data. The project's primary focus has been implementing and understanding modern LLM architectures and training techniques from scratch, rather than downstream task or chat performance. Beyond this, no formal bias or risk evaluation is documented.
64
+
65
+ ### Recommendations
66
+
67
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
68
+
69
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. Given the model's small scale, research-oriented training focus, and base (non-instruction-tuned) status, it should not be relied on for production, chat, or safety-critical use cases without further fine-tuning. Future updates are planned to include instruction tuning, preference optimization, and continued training to improve conversational quality.
70
+
71
+ ## How to Get Started with the Model
72
+
73
+ Use the code below to get started with the model.
74
+
75
+ ```bash
76
+ git clone https://github.com/AbdelrhmanEbied/Tiny-MoE.git
77
+ cd Tiny-MoE
78
+ pip install -r requirements.txt
79
+ !python -m inference.generate
80
+ ```
81
+
82
+ ## Training Details
83
+
84
+ ### Training Data
85
+
86
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
87
+
88
+ Tiny-MoE was pretrained on a streaming mixture of three Hugging Face datasets, interleaved with fixed sampling probabilities using the `all_exhausted` stopping strategy:
89
+
90
+ | Dataset | Purpose | Sampling Probability |
91
+ |----------|---------|--------------------:|
92
+ | FineWeb-Edu (sample-10BT) | General web and educational text | 60% |
93
+ | Cosmopedia v2 | Synthetic educational corpus | 25% |
94
+ | Open-Web-Math | Mathematical reasoning | 15% |
95
+
96
+ ### Training Procedure
97
+
98
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
99
+
100
+ Training used a streaming data pipeline that tokenizes incoming text, packs it into a continuous token buffer, and slices fixed-length (512-token) training sequences rather than padding individual documents β€” maximizing GPU utilization on constrained hardware.
101
+
102
+ #### Preprocessing
103
+
104
+ Text is streamed directly from Hugging Face (no full dataset download), interleaved across the three source datasets, shuffled with a large buffer, sharded across distributed processes and DataLoader workers, tokenized, and packed into contiguous 512-token windows to generate `input_ids`, `position_ids`, and shifted `labels`.
105
+
106
+ #### Training Hyperparameters
107
+
108
+ - **Training regime:** FP16 mixed precision
109
+ - **Optimizer:** 8-bit AdamW
110
+ - **Learning Rate:** 2.5e-4
111
+ - **Weight Decay:** 0.1
112
+ - **Betas:** (0.9, 0.95)
113
+ - **Gradient Clipping:** 1.0
114
+ - **Training Steps:** 30,000
115
+ - **Warmup Steps:** 2,800
116
+ - **Micro Batch Size:** 64
117
+ - **Gradient Accumulation:** 4
118
+ - **Effective Sequence Length:** 512
119
+
120
+ ## Evaluation
121
+
122
+ <!-- This section describes the evaluation protocols and provides the results. -->
123
+
124
+ ### Testing Data, Factors & Metrics
125
+
126
+ #### Metrics
127
+
128
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ During training, the following metrics were tracked: training and validation loss, perplexity, router entropy, router confidence, expert utilization, load ratio, load standard deviation, and minimum/maximum expert load, logged via Weights & Biases.
131
+
132
+ ### Results
133
+
134
+ **Training Loss:** Loss starts around ~10.5 at the beginning of training and drops sharply within the first ~2k–3k steps to roughly 3–4. From there it continues a slower downward trend, settling into a noisy band roughly between 2 and 4 for the remainder of the 30k training steps, ending around ~2.5–3.
135
+
136
+ **Validation Perplexity (val_ppl):** Evaluated periodically at checkpoints (labeled Base-1 through Base-11). It starts extremely high (~375 at Base-1, the first checkpoint) and falls steeply over the first several checkpoints β€” dropping to roughly ~170 (Base-1 end), ~75–115 (Base-2), then under 60 by Base-3, and below 50 from Base-4 onward. From there it continues to decrease gradually and more gently through the remaining checkpoints, trending toward the low-to-mid 40s by the final checkpoints near step 30k. I can't read exact numeric values off the chart with full precision, so treat these as approximate.
137
+
138
+ **Router Confidence:** Starts low (~0.2) early in training, consistent with an untrained/undecided router, and rises quickly to roughly 0.4 within the first ~2k–3k steps. It then stays relatively stable in the ~0.35–0.45 range for the rest of training, with periodic dips that align with the same checkpoint boundaries seen in the val_ppl chart β€” likely corresponding to evaluation or checkpoint-switch points rather than a genuine drop in routing stability.
139
+
140
+ **Router Load Ratio:** Fluctuated between roughly 1.2 and 2.0 across training, with typical values sitting around 1.4–1.5 β€” indicating experts were generally load-balanced with occasional wider imbalance spikes.
141
+
142
+ **Router Entropy:** Stayed near the theoretical maximum of ln(8) β‰ˆ 2.08 (the max entropy for 8 routed experts), reflecting near-uniform routing. It occasionally dropped below this but recovered quickly, suggesting temporary routing imbalances rather than persistent collapse.
143
+
144
+ **Expert Utilization:** Ranged from about 0.975 to 0.999, typically hovering around 0.99 β€” indicating experts were consistently and almost fully utilized throughout training.
145
+
146
+ **Training Duration:** ~90 hours total
147
+
148
+ ## Technical Specifications
149
+
150
+ ### Model Architecture and Objective
151
+
152
+ Tiny-MoE is a 14-layer decoder-only Mixture-of-Experts Transformer trained with a causal language modeling objective. Each layer applies RMSNorm, Multi-head Latent Attention (MLA) with RoPE positional encoding and SDPA attention, followed by RMSNorm and a Top-2-routed MoE feed-forward block (8 routed experts + 1 shared expert) executed via grouped GEMM. Auxiliary router loss and router z-loss are used to stabilize routing during training, and YaRN can be applied to extend context length.
153
+
154
+ | Parameter | Value |
155
+ |-----------|------:|
156
+ | Vocabulary Size | 32,000 |
157
+ | Hidden Size | 512 |
158
+ | Transformer Layers | 14 |
159
+ | Attention Heads | 8 |
160
+ | Routed Experts | 8 |
161
+ | Shared Experts | 1 |
162
+ | Experts per Token | 2 |
163
+ | MoE Intermediate Size | 1024 |
164
+ | Maximum Context Length | 512 (2048 via YaRN) |
165
+ | RMSNorm Epsilon | 1e-6 |
166
+ | RoPE Theta | 10,000 |
167
+ | Attention Implementation | SDPA |
168
+ | Weight Tying | Enabled |
169
+ | Total Parameters | ~150M–200M |
170
+ | Active Parameters | ~70M–90M per token |
171
+
172
+ ### Compute Infrastructure
173
+
174
+ The model was developed and trained entirely on Kaggle.
175
+
176
+ #### Hardware
177
+
178
+ - **Hardware Type:** 2Γ— NVIDIA T4 GPUs
179
+ - **Cloud Provider:** Kaggle
180
+
181
+
182
+ #### Software
183
+
184
+ Native PyTorch, DeepSpeed (ZeRO Stage 2, expert parallelism), Hugging Face Datasets, Torch Compile.
185
+
186
+ ## Glossary
187
+
188
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
189
+
190
+ - **MoE (Mixture-of-Experts):** An architecture where only a subset of specialized "expert" sub-networks are activated per token, reducing active compute relative to total parameter count.
191
+ - **MLA (Multi-head Latent Attention):** An attention variant that compresses key/value representations into a latent space to reduce memory and compute.
192
+ - **YaRN:** A technique for extending a model's usable context length beyond what it was originally trained on.
193
+ - **RoPE (Rotary Position Embeddings):** A positional encoding method that rotates query/key vectors to encode relative position information.
194
+
195
+ ## Model Card Authors
196
+
197
+ Abdelrhman Ebied