The write-up

How mindcontrol is built

dials on a language model’s brain

ML · GPU

What

Gemma 2 running on the visitor’s own graphics card, in the page, with dials that reach inside it while it talks.

Why

To see inside a language model by touching it: stimulate a layer with Pirate and it starts talking like one, cut a layer out and watch what breaks.

How

The engine is written from scratch in Rust: its own tokenizer, 4-bit quantizer and twelve GPU kernels, checked layer by layer against the reference at full precision until 23 of 23 tokens matched.

Built with

  • Rust 2024
  • wgpu 30
  • WGSL
  • wasm-bindgen
  • wasm-pack
  • Gemma 2 2B
  • safetensors
  • PyTorch, offline only

By the numbers

million parameters, on your graphics card
2,614
lines of source
8,821
commits in 1 day
20
tests
34
GPU kernels, written by hand
12
dials
11
layers you can see inside
26
tokens a second on an RTX 3060, run natively
84
servers
0

Languages

Rust4,78454.2%
JavaScript1,40716.0%
CSS1,22213.9%
WGSL shaders7518.5%
Python5045.7%
HTML1531.7%

On the wire

WebGPU
every multiply in a hand-written WGSL shader
Worker
the engine runs off the page, steering applied between tokens
OPFS
1.63 GB downloaded once, then read in place
Share link
the dials ride in the URL hash
Server
none: nothing typed leaves the machine

Kernels

  • 4-bit GEMV
  • 4-bit GEMM
  • Flash-decoding attention
  • RMSNorm
  • RoPE
  • GeGLU
  • Steering add

APIs

  • WebGPU
  • WebAssembly
  • Web Workers
  • Origin Private File System
  • HTTP range requests

Also

Click any word to see what each of its 26 layers was guessing at the time.