llm.mojo  by dorjeduck

Mojo port of Karpathy's llm.c for GPT-2 training

created 1 year ago
353 stars

Top 80.0% on sourcepulse

GitHubView on GitHub
Project Summary

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

  • Install dependencies: pip install -r requirements.txt
  • Run preparatory scripts: python prepro_tinyshakespeare.py and python train_gpt2.py
  • Requires Modular's magic CLI tool.
  • Run training: magic shell then mojo train_gpt2.mojo
  • Detailed usage: https://github.com/dorjeduck/llm.mojo/blob/main/usage.md

Highlighted Details

  • Benchmarks on an M2 MacBook Pro show train_gpt2.mojo achieving 1819ms loop time, slightly faster than train_gpt2.c with OpenMP (1849ms) and significantly faster than C without OpenMP (7473ms).
  • Includes a ported test suite (test_gpt2.mojo) for validation.
  • Actively updated to track Mojo language releases.

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

  • License: MIT
  • Compatible with commercial and closed-source applications.

Limitations & Caveats

The project is currently in beta and serves as a proof of concept, with no further development planned beyond Mojo version compatibility.

Health Check
Last commit

6 days ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
1
Star History
6 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Alex Cheema Alex Cheema(Cofounder of EXO Labs), and
1 more.

recurrent-pretraining by seal-rg

0.1%
806
Pretraining code for depth-recurrent language model research
created 5 months ago
updated 2 weeks ago
Starred by Stas Bekman Stas Bekman(Author of Machine Learning Engineering Open Book; Research Engineer at Snowflake) and Travis Fischer Travis Fischer(Founder of Agentic).

lingua by facebookresearch

0.1%
5k
LLM research codebase for training and inference
created 9 months ago
updated 2 weeks ago
Feedback? Help us improve.