Source

CUDA Mode Keynote | Andrej Karpathy | Eureka Labs

Watch on YouTube

Karpathy teaches how llm.c rebuilt GPT-2 training from explicit C and CUDA, using PyTorch as a correctness reference while manually implementing forward passes, backward passes, memory management, kernels, precision, and distributed execution. He emphasizes keeping the implementation readable and dependency-light, optimizing iteratively without accepting complexity whose gains are too small, and presents the project as evidence that future LLMs may generate highly customized low-level software.

- He describes replacing PyTorch’s abstractions with explicit float arrays, manual forward and backward passes, planned memory, precision management, kernel fusion, and distributed communication. - He uses a parallel PyTorch implementation as the correctness reference for each layer and for the complete training loop. - CUDA optimization proceeds from a simple parallel kernel to increasingly sophisticated versions that preserve the same specification and numerical results. - He recommends using strong existing implementations such as cuBLAS and cuDNN FlashAttention rather than rebuilding every difficult component. - He argues that performance improvements must be balanced against code complexity so the project remains readable and accessible to contributors. - He treats llm.c as evidence that LLMs could eventually act like compilers, producing optimized binaries and custom CUDA implementations for particular applications.

Based on Andrej Karpathy's public content. Not affiliated with or endorsed by Andrej Karpathy.

Supports these rules

Quotes from this video

“I really liked to do in Eleni I just want to keep things simple I don't want to create a tensor abstraction I don't want to create any abstraction really it's just float arrays and operations on float arrays”

“everything is just float arrays uh everything is fully self-contained there's no underlying representations abstractions to call import Etc”

“our pytorch code which Now isn't the primary thing we're working with it's only a reference that we check correctness with respect to”

“converted everything to C and made sure that everything matches our reference implementation”

“all of the allocation happens a single time at the beginning so we pre-plan all of the memory that we're going to ever use then it's fixed”

“you just pre-plan all the memory you allocate all of it”

“usually we have versions 1 2 3 four 5 six Etc and these are all different kernel implementations they're a bit faster usually over time but they match uh the specification exactly and give the exact same numbers”

“the first kernel is usually trivial but then optimiz ations can be pretty elaborate”

“when you roll your own code uh we actually switch to kuas”

“we actually switch to kuas uh step two we don't want to write our own flash attention I think that would be pretty complicated turns out CN has a very good flash attention implementation so we switch to that”

“it's just like it's it's too much complexity for not enough gain at this point”

“a lot of LMC just kind of like um balancing The Improv M and speed with the complexity of what you're actually introducing”

“I've actually rejected a lot of PRS because of that because the code starts to get crazy and I think that decreases the amount of people that can be on board in the project”

Topics