An interactive, browser-side, 3D-visual tutorial for Andrej Karpathy's ~150-line microGPT — a complete decoder-only transformer written in pure Python with no libraries. A TypeScript port of the same model runs entirely in the browser, so every logit and gradient you see in the 3D scenes is computed live, with no backend.
Live site: https://lxb12123.github.io/microgpt-3d-tutorial/
- Next.js 16 with App Router, static export to
out/. - Nextra v4 for MDX-driven lesson content.
- React 19.
- React Three Fiber + three.js for every 3D scene.
- Tailwind CSS v4 for UI chrome.
- Blender CLI for authoring
.glbassets; scripts live inblender/scripts/.
pnpm install
pnpm dev
# open http://localhost:3000/microgpt-3d-tutorial/Node >= 20.10, pnpm >= 9 (see engines in package.json).
| Command | Purpose |
|---|---|
pnpm dev |
Next dev server with HMR. |
pnpm build |
Static export to out/. |
pnpm start |
Serve a built site (used rarely; we ship a static export). |
pnpm typecheck |
tsc --noEmit. |
pnpm lint |
ESLint. |
pnpm test |
Vitest unit + component tests. |
pnpm e2e:ci |
Playwright smoke tests against the built static export. |
pnpm check-assets |
Enforce .glb size, naming, and location rules. |
pnpm analyze |
ANALYZE=true next build — generates a bundle report under .next/. |
pnpm bench |
Run the inference micro-benchmark (scripts/bench-inference.ts). |
app/— Next App Router shell. The[[...mdxPath]]catch-all hands every route to Nextra, which renders the MDX incontent/.layout.tsxandnot-found.tsxare the only hand-written routes.content/— MDX lessons (one file per lesson) plusindex.mdxfor the homepage._meta.tscontrols sidebar order and labels.components/3d/— All R3F code.SceneViewer.tsxis the shared canvas wrapper with WebGL detection and a fallback image;primitives/holds generic building blocks (NodeBlock,MatrixGrid,TokenCube,ConnectorArrow); per-lesson sandboxes live inoverview/,autograd/, andattention/.hud/has shared UI widgets (timeline scrubber, info panel).src/inference/— TypeScript port of microGPT inference: theValueautograd type, tokenizer, model forward pass, and trained-weights loader.src/microgpt_annotated.py— Karpathy's original Python with line-level English annotations; lessons reference exact line ranges from this file.blender/scripts/— Python scripts run under Blender's CLI to produce every.glbinpublic/models/. Seeblender/README.mdfor setup.public/models/— Committed.glbassets (one subdir per lesson plus sharedprimitives/).scripts/check-assets.mjsenforces size, naming, and location rules at build time.public/data/holds the trained microGPT weights blob (~89 KB) served to the browser.scripts/— Build-time helpers:check-assets.mjs, the inference benchmark, andtrain_and_export_weights.py(one-shot weight export).tests/e2e/— Playwright smoke tests (one per lesson + homepage).__tests__/andcomponents/3d/__tests__/— Vitest unit + component tests.docs/superpowers/— Implementation plans and design specs that drove each phase.
Every .glb under public/models/ is produced by a Python script in
blender/scripts/ run via Blender's headless CLI (typically through the
Blender MCP server). See blender/README.md for
setup, authoring rules, and the per-asset script index.
MIT. Karpathy's original microGPT gist is published without an explicit license; this project treats it as MIT-equivalent in keeping with the rest of his small-language-model work and the broader R3F / three.js demo ecosystem.
Built on Andrej Karpathy's
microGPT gist —
the ~150-line pure-Python transformer that this tutorial visualizes. The
TypeScript port mirrors that file line-for-line; the annotated source lives
at src/microgpt_annotated.py.