Mojo port of Karpathy's llm.c for GPT-2 training
Top 80.0% on sourcepulse
This project ports Andrej Karpathy's llm.c
to Mojo, aiming to demonstrate Mojo's performance and low-level capabilities for C-like applications. It's targeted at developers interested in high-performance AI model implementation and systems programming, offering a potential speed advantage over C with OpenMP.
How It Works
The project directly translates the C implementation of a GPT-2 model training loop into Mojo. It leverages Mojo's features, including its Python-like syntax, static typing, and low-level memory management capabilities, to achieve performance comparable to or exceeding optimized C code. The use of vectorize
and unroll_factor
optimizations is highlighted.
Quick Start & Requirements
pip install -r requirements.txt
python prepro_tinyshakespeare.py
and python train_gpt2.py
magic
CLI tool.magic shell
then mojo train_gpt2.mojo
Highlighted Details
train_gpt2.mojo
achieving 1819ms loop time, slightly faster than train_gpt2.c
with OpenMP (1849ms) and significantly faster than C without OpenMP (7473ms).test_gpt2.mojo
) for validation.Maintenance & Community
The project is primarily a proof of concept, with development focused on keeping pace with Mojo updates. The author is open to collaboration.
Licensing & Compatibility
Limitations & Caveats
The project is currently in beta and serves as a proof of concept, with no further development planned beyond Mojo version compatibility.
6 days ago
Inactive