smolGPT is a minimalist PyTorch implementation designed to help users train their own small language models from scratch. The project emphasizes educational purpose and code simplicity, while integrating efficient techniques from modern LLM training.
Purpose
smolGPT is mainly used for education and learning scenarios, allowing developers to understand and practice the complete training process of small LLMs. It is suitable for individuals or teaching environments that want to gain an in-depth understanding of Transformer architecture, training techniques, and sampling methods.
Main Capabilities
- Minimalist codebase: Pure PyTorch implementation, with no abstraction layer overhead, making it easy to read and modify.
- Modern architecture: The GPT model includes Flash Attention (when available), RMSNorm, SwiGLU, rotary embeddings (RoPE, optional), and efficient top-k/p/min-p sampling.
- Training features: Supports mixed precision (bfloat16/float16), gradient accumulation, learning rate decay with warmup, weight decay, and gradient clipping.
- Dataset support: Built-in TinyStories dataset processing pipeline.
- Custom tokenizer: Integrated SentencePiece tokenizer training.
Usage
Installation Requirements
- PyTorch 2.0+ with CUDA support
- A modern GPU is recommended
Option 1: Full Training Cycle
- Prepare the dataset
- Perform training; training and validation losses will be recorded in the
out/logs/directory. You can visualize with TensorBoard by running the corresponding command.
Option 2: Use a Pretrained Model
- Download the resources
- Load the pretrained model for inference or continued training.
Pretrained Model Details
The provided checkpoint is trained on the TinyStories dataset, with the following specific parameters:
- 4096 token vocabulary
- 8-layer Transformer
- 512 embedding dimension
- Trained on about 4 billion tokens for about 18.5 hours
- Validation loss: 1.0491
Configuration
Key parameters can be modified in config.py , including the model architecture, etc.
File Structure
The project includes a clear directory structure for easy navigation.
Applicable Scenarios
- Learning the LLM training process and modern architecture components
- Experimenting with language model training on small datasets
- Serving as teaching material to demonstrate how to build a GPT model from scratch
- Rapid prototyping to validate training ideas
Limitations
- This project is mainly intended for educational purposes and is not designed for production environments. For production use, it is recommended to scale up the model size and dataset.
- The pretrained model is small in scale and has limited capabilities.
- GPU support is required for efficient training.
- Training RIG specifications: Uses an NVIDIA L4 Tensor Core GPU (rented through LightningAI).
Contributions
Contributions are welcome! You can improve performance or training, etc., by submitting an issue or PR.