Skip to content

Instantly share code, notes, and snippets.

@lexpank
lexpank / microgpt.cu
Created March 17, 2026 22:48
CUDA C microgpt
// Nobody asked for microgpt in CUDA C, which is exactly why it had to happen.
// It is no longer particularly micro.
// It is, however, stupidly fast.
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp