femtoGPT
FreePure Rust implementation of a minimal Generative Pretrained Transformer.
About femtoGPT
femtoGPT is a pure Rust implementation of a minimal Generative Pretrained Transformer (GPT), built entirely from scratch including tensor processing logic, training, and inference code. It is designed for both training and inference of GPT-style language models on CPUs and GPUs (via OpenCL, supporting both NVIDIA and AMD cards). The implementation uses only basic Rust libraries (rand, serde, rayon) and verifies gradient correctness via gradient checking. While it is relatively slow on CPU and produces low-quality outputs on small models, it serves as an excellent educational tool for understanding how large language models work at a deep level. The project includes a simple CLI for training on custom datasets and running inference, with the ability to save and resume training.
Key Features
Pros & Cons
- Completely self-contained implementation with minimal dependencies
- GPU support via OpenCL without needing CUDA toolkits
- Gradient checking ensures training correctness
- Great educational resource for understanding GPT internals
- Supports saving and resuming training
- Free and open-source
- Extremely slow on CPU (as stated by the author)
- Output quality is poor for small models (e.g., 300k parameters on Shakespeare)
- Some layers may still have implementation bugs despite gradient checking
- Limited to small datasets with few unique characters
- Not suitable for production use