Home

Awesome

llm.rs

Migration of Karpathy's llm.c project into Rust

Development Process

The development steps taken to migrate llm.c into Rust

1. Utilizing c2rust

Using c2rust, train_gpt2.c was translated from Karpathy's llm.c project to Rust.

2. Utilizing GPT4

Although the transpilation of c2rust was successful, all the for loops have been turned into while loops.

Using GPT-4, we are able to convert all the while loops back into for loops.

3. Utilizing Mate

Furthermore, using Mate, we converted some of these for loops into iter() functions using the Rayon library.

4. Manual Updates

Currently, the project is undergoing manual updates to find performance improvements

Performance

Currently this implementation is still slower than the C version based on the following benchmarks:

CRustC++Mojo
Intel Core i7-9700 8-core2.447s2.530s
Intel Xeon E5-2690 v3 12-core2.110s2.439s1.037s6.190s

LLM Training Results

Quick Start

Install python dependencies, output tokenized dataset, and load in the weights:

make setup

Run the training script:

make train

This will run cargo build --release from the llm-rs cargo project after which the binary will be copied into the main project folder.

TODO