Downloads · 30 days
0
hey-shiv/mini-modern-llm
mini-modern-llm is a text generation model from hey-shiv. Use it when you need the model to write or continue text. The card lists the license as mit.
Mini Modern LLM is a compact, educational language model built with PyTorch. It takes the ideas implemented in the accompanying notebook and turns them into a small runnable codebase with reusable modules for tokeniza…
Downloads · 30 days
0
Access
Public
Updated Mar 15, 2026
Repo size
15.1 MB
Likes
0
Public
Click a slice to open those files.
.pt15.1 MB · 95%
From the Hugging Face model README
Mini Modern LLM is a compact, educational language model built with PyTorch. It takes the ideas implemented in the accompanying notebook and turns them into a small runnable codebase with reusable modules for tokenization, dataset preparation, training, and text generation.
The project is designed to be easy to read while still using several ideas from modern transformer architectures:
RMSNorm instead of standard LayerNormRoPE (Rotary Positional Embeddings) instead of learned positional embeddingsGrouped Query Attention (GQA) to reduce KV head costSwiGLU as the feed-forward activation blockThe core model lives in src/model.py and is implemented as a pre-norm transformer.
RMSNormGroupedQueryAttention with RoPERMSNormSwiGLURMSNorm is applied.RMSNorm
Normalizes activations using root-mean-square statistics with a learned scale parameter.RoPE
Encodes token position by rotating query and key vectors, allowing attention to capture relative positions naturally.Grouped Query Attention
Uses more query heads than key/value heads, which keeps attention expressive while reducing KV projection cost.SwiGLU
Uses a SiLU-gated feed-forward pathway that is commonly used in modern LLMs.The current training script uses:
d_model = 256n_layers = 4n_heads = 8n_kv_heads = 2ffn_hidden_dim = 680context_length = 256batch_size = 64The project trains on the TinyStories dataset from Hugging Face.
roneneldan/TinyStoriesdata/dataset.txttokenizer.jsonThe dataset is downloaded automatically the first time you run download_dataset.py, train_tokenizer.py, or train.py.
Create a virtual environment if you want, then install dependencies:
pip install -r requirements.txt
For Google Colab, install only the missing libraries so you keep Colab's GPU-enabled PyTorch:
pip install tokenizers datasets numpy
Run the full pipeline:
python download_dataset.py
python train_tokenizer.py
python train.py
What the training script does:
data/dataset.txt existstokenizer.jsonMiniLLMAdamWmodel.ptThe saved checkpoint includes:
If you push this repository to Hugging Face, do not commit generated training artifacts such as data/dataset.txt, token caches, or model.pt. The included .gitignore already excludes them.
After training, generate text with:
python generate.py --prompt "Once upon a time"
You can also control sampling temperature and output length:
python generate.py --prompt "Once upon a time" --temperature 0.8 --max-new-tokens 300
Useful flags:
--prompt starting text for generation--temperature sampling temperature, where 0 is greedy decoding--max-new-tokens number of tokens to generate--model-path optional path to a checkpoint--seed optional random seed for reproducible sampling.
├── src/
│ ├── model.py
│ ├── tokenizer.py
│ └── dataset.py
├── notebooks/
│ └── first-mini-modern-llm.ipynb
├── train.py
├── generate.py
└── requirements.txt
This repository is a small but modern LLM training project focused on clarity and learning. It is a good starting point for experimenting with transformer internals, BPE tokenization, and compact end-to-end language model workflows.