ai-glimpse/toyllm
ai-glimpse/toyllm has 26 GitHub stars and 2 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-11 21:58 UTC. Last push 2026-11-01.
ToyLLM: Learning LLM from Scratch
Measured star growth
- in 24h
- 0
- in 7 days
- Update delayed
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalToyLLM: Learning LLM from Scratch
A hands-on educational project for understanding and implementing Large Language Models (LLMs) from scratch. This project provides implementations of GPT-2 and related techniques, making it an excellent resource for learning about transformer architectures and modern language models.
Features
GPT-2 Implementation
A clean, educational implementation of GPT-2 with type hints, supporting both training and inference.
Speculative Sampling
An implementation of speculative sampling for faster inference, featuring configurable draft models and performance benchmarking.
KV Cache Optimization
A memory-efficient GPT-2 implementation with KV cache optimization for handling longer sequences.
Quick Start
Prerequisites
- Python 3.14
- Git and Git LFS (for model files)
- UV (recommended package manager)
Installation
Clone the repository:
git clone https://github.com/ai-glimpse/toyllm.git cd toyllmSet up the environment:
# Create the environment and install the project uv syncDownload model files:
# Install Git LFS if not already installed git lfs install # Download model files git clone https://huggingface.co/MathewShen/toyllm-gpt2 modelsAlternatively, you can manually download the model files from Hugging Face and place them in the
modelsdirectory.
Usage Examples
Basic GPT-2 Inference
uv run python -m toyllm.cli.run_gpt2 --help # View available options
uv run python -m toyllm.cli.run_gpt2 # Run with default settings
KV Cache Optimized GPT-2
uv run python -m toyllm.cli.run_gpt2_kv --help # View available options
uv run python -m toyllm.cli.run_gpt2_kv # Run with default settings
Speculative Sampling
uv run python -m toyllm.cli.run_speculative_sampling --help # View available options
uv run python -m toyllm.cli.run_speculative_sampling # Run with default settings
Benchmarking
uv run python -m toyllm.cli.benchmark.bench_gpt2kv --help # View available options
uv run python -m toyllm.cli.benchmark.bench_gpt2kv # Run benchmarks
Project Structure
src/toyllm/
├── cli/ # Command-line interface modules
├── core/ # Shared generation primitives
├── gpt2/ # GPT-2 specific implementations
├── gpt2kv/ # KV-cache optimized GPT-2
├── sps/ # Speculative sampling implementations
└── util/ # Utility functions
Acknowledgements
This project is inspired by and builds upon the following excellent resources:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Explore related projects
affaan-m/ECC
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
302,019 starsNousResearch/hermes-agent
The agent that grows with you
262,969 starsmultica-ai/andrej-karpathy-skills
A single CLAUDE.md file to improve Claude Code behavior, derived from Andrej Karpathy's observations on LLM coding pitfalls.
232,544 starsfirecrawl/firecrawl
Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
200,932 stars