Update README.md
Browse files
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
language: en
|
| 3 |
-
license:
|
| 4 |
library_name: pytorch
|
| 5 |
tags:
|
| 6 |
- transformer
|
|
@@ -12,369 +12,123 @@ tags:
|
|
| 12 |
|
| 13 |
# Model Card for LumenBase
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
LumenBase is a 128M parameter GPT-style transformer language model built entirely from scratch for educational and research purposes. The model features modern architectural components including Grouped Multi-Query Attention (GQA), SwiGLU activation, RMSNorm, and Rotary Position Embeddings (RoPE).
|
| 18 |
|
| 19 |
## Model Details
|
| 20 |
|
| 21 |
### Model Description
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
- **Grouped Multi-Query Attention (GQA)**: Efficient attention mechanism with 12 query heads and 4 key-value heads (3 groups)
|
| 28 |
-
- **SwiGLU Activation**: Advanced feed-forward network activation function
|
| 29 |
-
- **RMSNorm**: Layer normalization for improved training stability
|
| 30 |
-
- **Rotary Position Embeddings (RoPE)**: Relative position encoding
|
| 31 |
-
- **Weight Tying**: Shared weights between embedding and output layers
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
- **
|
| 36 |
-
- **Model type:** Decoder-only Transformer Language Model
|
| 37 |
-
- **Language(s) (NLP):** English
|
| 38 |
- **License:** MIT
|
| 39 |
-
- **Finetuned from model [optional]:** N/A (trained from scratch)
|
| 40 |
-
|
| 41 |
-
### Model Sources [optional]
|
| 42 |
-
|
| 43 |
-
<!-- Provide the basic links for the model. -->
|
| 44 |
-
|
| 45 |
- **Repository:** https://github.com/HariomJangra/project-lumen
|
| 46 |
-
- **Paper [optional]:** N/A
|
| 47 |
-
- **Demo [optional]:** N/A
|
| 48 |
|
| 49 |
## Uses
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
-
|
| 59 |
-
-
|
| 60 |
-
-
|
| 61 |
-
-
|
| 62 |
-
- Understanding modern LLM architectural components
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
-
|
| 70 |
-
-
|
| 71 |
-
-
|
| 72 |
-
-
|
| 73 |
-
- Further research on specialized applications
|
| 74 |
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
-
- Production deployments requiring high-quality generation
|
| 81 |
-
- Safety-critical applications
|
| 82 |
-
- Applications requiring factual accuracy without verification
|
| 83 |
-
- Generation of harmful, hateful, or biased content
|
| 84 |
-
- Large-scale commercial applications without proper evaluation
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
-
- Limited model size (128M parameters) compared to larger production models
|
| 94 |
-
- Performance on benchmarks is below state-of-the-art models
|
| 95 |
-
- May generate incoherent or nonsensical text for complex prompts
|
| 96 |
-
- Limited context window (2048 tokens)
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
-
|
| 101 |
-
-
|
| 102 |
-
|
| 103 |
|
| 104 |
-
**
|
| 105 |
-
- This is a learning project, not optimized for production use
|
| 106 |
-
- Training data sources and quality may vary
|
| 107 |
-
- Limited testing across diverse use cases
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
-
- Be aware this is an educational model with limited capabilities
|
| 115 |
-
- Not use for safety-critical or production applications
|
| 116 |
-
- Verify all generated content before use
|
| 117 |
-
- Implement appropriate content filtering for downstream applications
|
| 118 |
-
- Consider the model's limitations when interpreting results
|
| 119 |
-
- Use established production-ready models for commercial applications
|
| 120 |
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
|
| 125 |
```python
|
| 126 |
import torch
|
| 127 |
from ModelArchitecture import Transformer, ModelConfig, generate
|
| 128 |
from tokenizers import Tokenizer
|
| 129 |
|
| 130 |
-
# Load model
|
| 131 |
-
config = ModelConfig(
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
n_kv_heads=4,
|
| 136 |
-
n_kv_groups=3,
|
| 137 |
-
head_dim=64,
|
| 138 |
-
n_layers=12,
|
| 139 |
-
attention_bias=False,
|
| 140 |
-
intermediate_size=3072,
|
| 141 |
-
mlp_bias=False,
|
| 142 |
-
eps=1e-5,
|
| 143 |
-
dropout=0.0,
|
| 144 |
-
max_position_embeddings=2048,
|
| 145 |
-
pre_norm=True,
|
| 146 |
-
tie_weights=True,
|
| 147 |
-
max_seq_len=2048
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
-
# Initialize model
|
| 151 |
-
model = Transformer(config)
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
model.load_state_dict(checkpoint)
|
| 156 |
model.eval()
|
| 157 |
|
| 158 |
-
# Load tokenizer
|
| 159 |
-
tokenizer = Tokenizer.from_file('LumenTokenizer.json')
|
| 160 |
-
|
| 161 |
# Generate text
|
|
|
|
| 162 |
prompt = "Once upon a time"
|
| 163 |
input_ids = torch.tensor([tokenizer.encode(prompt).ids])
|
| 164 |
|
| 165 |
-
output = generate(
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
max_new_tokens=100,
|
| 169 |
-
temperature=0.8,
|
| 170 |
-
top_k=50,
|
| 171 |
-
top_p=0.9,
|
| 172 |
-
do_sample=True
|
| 173 |
-
)
|
| 174 |
-
|
| 175 |
-
generated_text = tokenizer.decode(output[0].tolist())
|
| 176 |
-
print(generated_text)
|
| 177 |
-
```
|
| 178 |
-
|
| 179 |
-
## Training Details
|
| 180 |
-
|
| 181 |
-
### Training Data
|
| 182 |
-
|
| 183 |
-
<!-- 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. -->
|
| 184 |
-
|
| 185 |
-
The model was trained on custom datasets prepared specifically for this project. The training pipeline included:
|
| 186 |
-
|
| 187 |
-
1. **Dataset Preparation**: Text data collection and preprocessing
|
| 188 |
-
2. **Tokenization**: Custom BPE (Byte Pair Encoding) tokenizer trained with a vocabulary size of 32,000 tokens
|
| 189 |
-
3. **Data Processing**: Text tokenization and conversion to token IDs stored as NumPy arrays
|
| 190 |
-
- TokenizedDataSet1.npy
|
| 191 |
-
- TokenizedDataSet2.npy
|
| 192 |
-
- TokenizedDataset3.npy
|
| 193 |
-
|
| 194 |
-
The training data was tokenized using a custom-trained tokenizer (LumenTokenizer) optimized for the target domain.
|
| 195 |
-
|
| 196 |
-
### Training Procedure
|
| 197 |
-
|
| 198 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 199 |
-
|
| 200 |
-
#### Preprocessing [optional]
|
| 201 |
-
|
| 202 |
-
- Text cleaning and normalization
|
| 203 |
-
- BPE tokenization with 32K vocabulary
|
| 204 |
-
- Sequence chunking to 2048 token context windows
|
| 205 |
-
- Data stored in efficient NumPy format for fast loading
|
| 206 |
-
|
| 207 |
-
#### Training Hyperparameters
|
| 208 |
-
|
| 209 |
-
- **Optimizer**: AdamW (lr=3e-4, betas=(0.9, 0.95), weight_decay=0.1)
|
| 210 |
-
- **Scheduler**: Linear warmup (2000 steps) + Cosine annealing
|
| 211 |
-
- **Batch Size**: 12 sequences per batch
|
| 212 |
-
- **Gradient Accumulation Steps**: 4 (effective batch size: 48)
|
| 213 |
-
- **Sequence Length**: 2048 tokens
|
| 214 |
-
- **Dropout**: 0.1 during training, 0.0 during inference
|
| 215 |
-
- **Gradient Clipping**: Max norm 1.0
|
| 216 |
-
- **Training regime**: Mixed precision (automatic FP16/BF16/FP32 based on hardware)
|
| 217 |
-
|
| 218 |
-
#### Speeds, Sizes, Times [optional]
|
| 219 |
-
|
| 220 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 221 |
-
|
| 222 |
-
- **Model Parameters**: 128M (128 million)
|
| 223 |
-
- **Model Size**: ~512 MB (FP32), ~256 MB (FP16)
|
| 224 |
-
- **Checkpoint Frequency**: Every N steps with automatic best model saving
|
| 225 |
-
- **Training monitored with**: Training and validation loss curves
|
| 226 |
-
- **Final checkpoint**: best_model_params_110k.pt
|
| 227 |
-
|
| 228 |
-

|
| 229 |
-
|
| 230 |
-
## Evaluation
|
| 231 |
-
|
| 232 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 233 |
-
|
| 234 |
-
### Testing Data, Factors & Metrics
|
| 235 |
-
|
| 236 |
-
#### Testing Data
|
| 237 |
-
|
| 238 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 239 |
-
|
| 240 |
-
The model was evaluated on three standard NLP benchmarks:
|
| 241 |
-
|
| 242 |
-
1. **ARC-Easy** (AI2 Reasoning Challenge - Easy): 2,376 questions
|
| 243 |
-
2. **ARC-Challenge** (AI2 Reasoning Challenge - Challenge): 1,172 questions
|
| 244 |
-
3. **HellaSwag**: 1,024 examples for commonsense reasoning
|
| 245 |
-
|
| 246 |
-
#### Factors
|
| 247 |
-
|
| 248 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 249 |
-
|
| 250 |
-
The model was evaluated on:
|
| 251 |
-
- Multiple-choice question answering
|
| 252 |
-
- Commonsense reasoning
|
| 253 |
-
- Scientific reasoning
|
| 254 |
-
- Reading comprehension
|
| 255 |
-
|
| 256 |
-
#### Metrics
|
| 257 |
-
|
| 258 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 259 |
-
|
| 260 |
-
**Accuracy**: The primary metric used for all benchmarks, measuring the percentage of correctly answered questions.
|
| 261 |
-
|
| 262 |
-
### Results
|
| 263 |
-
|
| 264 |
-
| Benchmark | Accuracy | Correct | Total |
|
| 265 |
-
|-----------|----------|---------|-------|
|
| 266 |
-
| **ARC-Easy** | 39.48% | 938 | 2,376 |
|
| 267 |
-
| **ARC-Challenge** | 23.55% | 276 | 1,172 |
|
| 268 |
-
| **HellaSwag** | 32.62% | 334 | 1,024 |
|
| 269 |
-
|
| 270 |
-
#### Summary
|
| 271 |
-
|
| 272 |
-
The LumenBase model demonstrates baseline performance on standard NLP benchmarks. As expected for a 128M parameter model trained from scratch for educational purposes:
|
| 273 |
-
|
| 274 |
-
- **ARC-Easy**: Achieves ~39% accuracy, showing some capability on easier scientific reasoning tasks
|
| 275 |
-
- **ARC-Challenge**: Scores ~24% on the more difficult version, indicating room for improvement on complex reasoning
|
| 276 |
-
- **HellaSwag**: Reaches ~33% on commonsense reasoning, slightly above random chance (25% for 4-choice questions)
|
| 277 |
-
|
| 278 |
-
These results are consistent with a small-scale educational model and provide a baseline for future improvements through:
|
| 279 |
-
- Additional training data
|
| 280 |
-
- Longer training duration
|
| 281 |
-
- Model scaling
|
| 282 |
-
- Fine-tuning on specific tasks
|
| 283 |
-
- Improved training techniques
|
| 284 |
-
|
| 285 |
-
## Model Examination [optional]
|
| 286 |
-
|
| 287 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 288 |
-
|
| 289 |
-
**Architecture Details:**
|
| 290 |
-
- **Attention Mechanism**: Grouped Multi-Query Attention reduces KV cache size while maintaining performance
|
| 291 |
-
- **Activation Function**: SwiGLU provides better gradient flow compared to traditional ReLU
|
| 292 |
-
- **Normalization**: RMSNorm (Root Mean Square Layer Normalization) for improved stability
|
| 293 |
-
- **Position Encoding**: RoPE (Rotary Position Embeddings) for better handling of relative positions
|
| 294 |
-
- **Weight Tying**: Embedding and output layer share weights, reducing parameter count
|
| 295 |
-
|
| 296 |
-
**Key Design Choices:**
|
| 297 |
-
- Decoder-only architecture following GPT design principles
|
| 298 |
-
- Pre-normalization for better training stability
|
| 299 |
-
- Efficient attention with 12 query heads, 4 KV heads (grouped into 3)
|
| 300 |
-
- Intermediate FFN size of 3072 (4x hidden size)
|
| 301 |
-
|
| 302 |
-
**Implementation Highlights:**
|
| 303 |
-
- Custom implementation from scratch using PyTorch
|
| 304 |
-
- Supports various sampling strategies: greedy, top-k, top-p (nucleus), temperature scaling
|
| 305 |
-
- Gradient accumulation for effective larger batch sizes
|
| 306 |
-
- Automatic mixed precision training support
|
| 307 |
-
|
| 308 |
-
## Environmental Impact
|
| 309 |
-
|
| 310 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 311 |
-
|
| 312 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 313 |
-
|
| 314 |
-
- **Hardware Type:** Consumer-grade GPU (specific hardware varies)
|
| 315 |
-
- **Hours used:** Educational project, training time not formally tracked
|
| 316 |
-
- **Cloud Provider:** N/A (local training)
|
| 317 |
-
- **Compute Region:** N/A
|
| 318 |
-
- **Carbon Emitted:** Not formally measured
|
| 319 |
-
|
| 320 |
-
**Note**: As an educational project, formal carbon footprint tracking was not implemented. Future iterations could benefit from tracking environmental impact.
|
| 321 |
-
|
| 322 |
-
## Technical Specifications [optional]
|
| 323 |
-
|
| 324 |
-
### Model Architecture and Objective
|
| 325 |
-
|
| 326 |
-
**Architecture**: Decoder-only Transformer (GPT-style)
|
| 327 |
-
|
| 328 |
-
**Configuration:**
|
| 329 |
-
```python
|
| 330 |
-
vocab_size: 32000
|
| 331 |
-
hidden_size: 768
|
| 332 |
-
n_heads: 12
|
| 333 |
-
n_kv_heads: 4
|
| 334 |
-
n_kv_groups: 3
|
| 335 |
-
head_dim: 64
|
| 336 |
-
n_layers: 12
|
| 337 |
-
intermediate_size: 3072
|
| 338 |
-
max_position_embeddings: 2048
|
| 339 |
-
dropout: 0.1 (training) / 0.0 (inference)
|
| 340 |
-
```
|
| 341 |
-
|
| 342 |
-
**Key Components:**
|
| 343 |
-
- **Grouped Multi-Query Attention**: 12 query heads, 4 key-value heads
|
| 344 |
-
- **Feed-Forward Network**: SwiGLU activation with 3072 intermediate dimensions
|
| 345 |
-
- **Layer Normalization**: RMSNorm (epsilon=1e-5)
|
| 346 |
-
- **Position Encoding**: Rotary Position Embeddings (RoPE)
|
| 347 |
-
- **Weight Tying**: Shared embedding and output projection weights
|
| 348 |
-
|
| 349 |
-
**Training Objective**: Causal language modeling with cross-entropy loss
|
| 350 |
-
|
| 351 |
-
### Compute Infrastructure
|
| 352 |
-
|
| 353 |
-
Educational project trained on consumer hardware.
|
| 354 |
-
|
| 355 |
-
#### Hardware
|
| 356 |
-
|
| 357 |
-
- Consumer-grade GPU (specific configuration varies)
|
| 358 |
-
- Training performed locally, not on cloud infrastructure
|
| 359 |
-
|
| 360 |
-
#### Software
|
| 361 |
-
|
| 362 |
-
```
|
| 363 |
-
Python 3.13
|
| 364 |
-
PyTorch (latest)
|
| 365 |
-
NumPy
|
| 366 |
-
Tokenizers (Hugging Face)
|
| 367 |
-
tqdm (progress tracking)
|
| 368 |
-
matplotlib (visualization)
|
| 369 |
```
|
| 370 |
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
## Citation [optional]
|
| 374 |
-
|
| 375 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 376 |
-
|
| 377 |
-
**BibTeX:**
|
| 378 |
|
| 379 |
```bibtex
|
| 380 |
@misc{lumenbase2024,
|
|
@@ -382,66 +136,12 @@ matplotlib (visualization)
|
|
| 382 |
title = {LumenBase: A 128M Parameter Language Model Built from Scratch},
|
| 383 |
year = {2024},
|
| 384 |
publisher = {GitHub},
|
| 385 |
-
journal = {GitHub repository},
|
| 386 |
howpublished = {\url{https://github.com/HariomJangra/project-lumen}}
|
| 387 |
}
|
| 388 |
```
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
Jangra, H. (2024). *LumenBase: A 128M Parameter Language Model Built from Scratch* [Computer software]. GitHub. https://github.com/HariomJangra/project-lumen
|
| 393 |
-
|
| 394 |
-
## Glossary [optional]
|
| 395 |
-
|
| 396 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 397 |
-
|
| 398 |
-
**Terms:**
|
| 399 |
-
|
| 400 |
-
- **BPE (Byte Pair Encoding)**: Tokenization algorithm that builds vocabulary by iteratively merging frequent character pairs
|
| 401 |
-
- **GQA (Grouped Multi-Query Attention)**: Attention mechanism where multiple query heads share fewer key-value heads, reducing memory and computation
|
| 402 |
-
- **RMSNorm**: Root Mean Square Layer Normalization - simplified normalization that only rescales using RMS statistics
|
| 403 |
-
- **RoPE (Rotary Position Embeddings)**: Position encoding that encodes absolute positions with rotation matrices and naturally incorporates relative position information
|
| 404 |
-
- **SwiGLU**: Activation function combining Swish activation with Gated Linear Units for improved model performance
|
| 405 |
-
- **Weight Tying**: Technique where embedding and output layers share parameters to reduce model size
|
| 406 |
-
|
| 407 |
-
**Sampling Strategies:**
|
| 408 |
-
- **Greedy Decoding**: Always select the token with highest probability
|
| 409 |
-
- **Top-k Sampling**: Sample from the k most likely tokens
|
| 410 |
-
- **Top-p (Nucleus) Sampling**: Sample from smallest set of tokens whose cumulative probability exceeds p
|
| 411 |
-
- **Temperature Scaling**: Adjust probability distribution sharpness (lower = more deterministic, higher = more random)
|
| 412 |
-
|
| 413 |
-
## More Information [optional]
|
| 414 |
-
|
| 415 |
-
**Project Structure:**
|
| 416 |
-
- `PreTraining/Implementation/`: Training scripts and data preparation notebooks
|
| 417 |
-
- `PreTraining/Benchmark/`: Evaluation scripts and results
|
| 418 |
-
- `PreTraining/Inference/`: Text generation and inference code
|
| 419 |
-
- `PreTraining/Models/`: Saved model checkpoints
|
| 420 |
-
- `PreTraining/DataSets/`: Tokenized training data
|
| 421 |
-
|
| 422 |
-
**Future Work:**
|
| 423 |
-
- Fine-tuning for instruction following
|
| 424 |
-
- Chat model adaptation
|
| 425 |
-
- Task-specific fine-tuning
|
| 426 |
-
- Scaling to larger model sizes
|
| 427 |
-
- Improved training data curation
|
| 428 |
-
- Advanced sampling techniques
|
| 429 |
-
|
| 430 |
-
**Learning Resources:**
|
| 431 |
-
This project serves as a comprehensive educational resource covering:
|
| 432 |
-
1. Dataset preparation and cleaning
|
| 433 |
-
2. Custom tokenizer training
|
| 434 |
-
3. Transformer architecture implementation
|
| 435 |
-
4. Training loop with modern optimizations
|
| 436 |
-
5. Evaluation on standard benchmarks
|
| 437 |
-
6. Text generation with various sampling strategies
|
| 438 |
-
|
| 439 |
-
For detailed implementation and usage, please refer to the [GitHub repository](https://github.com/HariomJangra/project-lumen).
|
| 440 |
-
|
| 441 |
-
## Model Card Authors [optional]
|
| 442 |
-
|
| 443 |
-
Hariom Jangra ([@HariomJangra](https://github.com/HariomJangra))
|
| 444 |
|
| 445 |
-
|
| 446 |
|
| 447 |
-
For questions or feedback
|
|
|
|
| 1 |
---
|
| 2 |
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
library_name: pytorch
|
| 5 |
tags:
|
| 6 |
- transformer
|
|
|
|
| 12 |
|
| 13 |
# Model Card for LumenBase
|
| 14 |
|
| 15 |
+
A 128M parameter GPT-style transformer built from scratch for educational purposes, featuring Grouped Multi-Query Attention (GQA), SwiGLU, RMSNorm, and RoPE.
|
|
|
|
|
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
| 19 |
### Model Description
|
| 20 |
|
| 21 |
+
LumenBase is a decoder-only transformer language model implementing modern architectural optimizations:
|
| 22 |
+
- **Architecture**: 12-layer transformer with GQA (12 query heads, 4 KV heads), SwiGLU activation, RMSNorm, and RoPE
|
| 23 |
+
- **Parameters**: 128M (768 hidden size, 3072 FFN, 2048 context length)
|
| 24 |
+
- **Training**: Mixed precision (FP16/BF16) with custom tokenizer (32K vocab)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
- **Developed by:** Hariom Jangra
|
| 27 |
+
- **Model type:** Decoder-only Transformer
|
| 28 |
+
- **Language:** English
|
|
|
|
|
|
|
| 29 |
- **License:** MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
- **Repository:** https://github.com/HariomJangra/project-lumen
|
|
|
|
|
|
|
| 31 |
|
| 32 |
## Uses
|
| 33 |
|
| 34 |
+
**Direct Use:**
|
| 35 |
+
- Text generation and completion
|
| 36 |
+
- Educational resource for understanding transformer architecture
|
| 37 |
+
- Research baseline for language models
|
| 38 |
+
- Foundation for fine-tuning on specific tasks
|
| 39 |
|
| 40 |
+
**Downstream Use:**
|
| 41 |
+
- Instruction tuning
|
| 42 |
+
- Chat applications
|
| 43 |
+
- Domain-specific fine-tuning
|
| 44 |
|
| 45 |
+
**Out-of-Scope:**
|
| 46 |
+
- Production deployments
|
| 47 |
+
- Safety-critical applications
|
| 48 |
+
- Applications requiring factual accuracy without verification
|
| 49 |
+
- This is an educational model - use established frameworks for production
|
|
|
|
| 50 |
|
| 51 |
+
## Limitations
|
| 52 |
|
| 53 |
+
**Technical:**
|
| 54 |
+
- Limited size (128M parameters) - below state-of-the-art performance
|
| 55 |
+
- 2048 token context window
|
| 56 |
+
- May generate incoherent text for complex prompts
|
| 57 |
|
| 58 |
+
**Bias & Safety:**
|
| 59 |
+
- May perpetuate training data biases
|
| 60 |
+
- Not evaluated for fairness across demographics
|
| 61 |
+
- Can generate inappropriate content
|
| 62 |
+
- Should not be relied upon for factual information
|
|
|
|
| 63 |
|
| 64 |
+
**Recommendations:** This is an educational model. Verify all outputs, implement content filtering for applications, and use production-ready models for commercial use.
|
| 65 |
|
| 66 |
+
## Training
|
| 67 |
|
| 68 |
+
**Data:** Custom datasets tokenized with BPE (32K vocab)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
**Hyperparameters:**
|
| 71 |
+
- Optimizer: AdamW (lr=3e-4, weight_decay=0.1)
|
| 72 |
+
- Batch: 12 × 4 gradient accumulation = 48 effective
|
| 73 |
+
- Sequence length: 2048 tokens
|
| 74 |
+
- Scheduler: Linear warmup + Cosine annealing
|
| 75 |
+
- Precision: Mixed (FP16/BF16/FP32)
|
| 76 |
+
- Dropout: 0.1 (training), 0.0 (inference)
|
| 77 |
|
| 78 |
+

|
| 79 |
|
| 80 |
+
## Evaluation
|
| 81 |
|
| 82 |
+
Evaluated on standard NLP benchmarks:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
| Benchmark | Accuracy | Correct/Total |
|
| 85 |
+
|-----------|----------|---------------|
|
| 86 |
+
| **ARC-Easy** | 39.48% | 938/2,376 |
|
| 87 |
+
| **ARC-Challenge** | 23.55% | 276/1,172 |
|
| 88 |
+
| **HellaSwag** | 32.62% | 334/1,024 |
|
| 89 |
|
| 90 |
+
**Summary:** Baseline performance consistent with a 128M educational model. Results show capability on easier tasks with room for improvement on complex reasoning.
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
## Technical Specifications
|
| 93 |
|
| 94 |
+
**Architecture:** Decoder-only Transformer
|
| 95 |
+
- 12 layers, 768 hidden size, 12 attention heads (4 KV heads)
|
| 96 |
+
- SwiGLU FFN (3072 intermediate), RMSNorm, RoPE
|
| 97 |
+
- 32K vocab, 2048 max sequence length
|
| 98 |
+
- Weight tying between embedding and output layers
|
| 99 |
|
| 100 |
+
**Implementation:** Custom PyTorch implementation from scratch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
**Software:** Python 3.13, PyTorch, NumPy, Tokenizers, tqdm, matplotlib
|
| 103 |
|
| 104 |
+
## How to Use
|
| 105 |
|
| 106 |
```python
|
| 107 |
import torch
|
| 108 |
from ModelArchitecture import Transformer, ModelConfig, generate
|
| 109 |
from tokenizers import Tokenizer
|
| 110 |
|
| 111 |
+
# Load configuration and model
|
| 112 |
+
config = ModelConfig(vocab_size=32000, hidden_size=768, n_heads=12,
|
| 113 |
+
n_kv_heads=4, n_kv_groups=3, head_dim=64, n_layers=12,
|
| 114 |
+
intermediate_size=3072, max_position_embeddings=2048,
|
| 115 |
+
dropout=0.0, pre_norm=True, tie_weights=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
model = Transformer(config)
|
| 118 |
+
model.load_state_dict(torch.load('LumenBase.safetensors'))
|
|
|
|
| 119 |
model.eval()
|
| 120 |
|
|
|
|
|
|
|
|
|
|
| 121 |
# Generate text
|
| 122 |
+
tokenizer = Tokenizer.from_file('LumenTokenizer.json')
|
| 123 |
prompt = "Once upon a time"
|
| 124 |
input_ids = torch.tensor([tokenizer.encode(prompt).ids])
|
| 125 |
|
| 126 |
+
output = generate(model, input_ids, max_new_tokens=100,
|
| 127 |
+
temperature=0.8, top_k=50, top_p=0.9)
|
| 128 |
+
print(tokenizer.decode(output[0].tolist()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
```
|
| 130 |
|
| 131 |
+
## Citation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
```bibtex
|
| 134 |
@misc{lumenbase2024,
|
|
|
|
| 136 |
title = {LumenBase: A 128M Parameter Language Model Built from Scratch},
|
| 137 |
year = {2024},
|
| 138 |
publisher = {GitHub},
|
|
|
|
| 139 |
howpublished = {\url{https://github.com/HariomJangra/project-lumen}}
|
| 140 |
}
|
| 141 |
```
|
| 142 |
|
| 143 |
+
## Contact
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
**Author:** Hariom Jangra ([@HariomJangra](https://github.com/HariomJangra))
|
| 146 |
|
| 147 |
+
For questions or feedback, please open an issue on the [GitHub repository](https://github.com/HariomJangra/project-lumen).
|