kw.gl

A 30B AI in 10 KB, no OS, on a 1987 laptop

· Uladzimir Kazakevich · 14 min read

A cartoon: a tiny cheerful SD card with pixel sunglasses, labelled “10 KB”, lifts a huge glowing brain labelled “30B” over its head in front of an old beige laptop, whose screen shows “10KILOMIND”, “2.7 t/s” and a grid of pink and blue cells

10KILOMIND is a chat window for a large language model, and the whole program is 9,972 bytes. There is no Linux and no operating system under it: the Raspberry Pi’s firmware loads those 9,972 bytes, they unpack themselves, and then they run Qwen3-30B-A3B, a model with 30 billion weights, straight from the SD card. It answers at 2.7 tokens per second (about two words a second) inside the case of a Toshiba T1200, a laptop from 1987, and on the right of the screen a map lights up with every expert the model uses.

It’s a demo in the old demoscene sense, with a tiny file, a big effect and every byte fought for. Ask it for a haiku about a computer that is only 10 kilobytes, and it writes:

Tiny brain, so small,
10 KB, no room to roam.
Silent, fast, and bright.

The code, the docs and ready-made card files are on GitHub.

10KILOMIND on the Toshiba T1200: the old beige laptop’s screen shows the model’s name and three questions, “tell me a joke” (Why don’t skeletons ever play hide and seek? Because they’re always dead!), a haiku about a computer that is only 10 kilobytes (“Tiny brain, so small, / 10 KB, no room to roam. / Silent, fast, and bright.”) and how it feels to run on a Toshiba T1200 from 1987 with no operating system (“Cold metal, whirring tape. No OS, just”, still writing); the answers ran at 2.7 t/s, the big counter shows 2.9 t/s, the expert map on the right is full of lit cells, and the footer says 9972 bytes, Raspberry Pi 4, 8 GB RAM

The short version

The demo at four times the real speed: 10KILOMIND on the Toshiba T1200 on YouTube.

A few names you’ll meet:

NameWhat it is
Bare metala program that runs on the hardware directly, with no operating system
Tokena piece of a word; a model reads and writes one token at a time
Mixture of experts (MoE)a model whose layers have many small “experts”; each token goes through only a few of them (here 8)
Perplexityhow surprised a model is by real text; lower is better
GGUF, llama.cppthe usual file format for local models and the engine most people run them with
Packera compressor whose output unpacks itself when it starts
Demoscenethe people who make 4 KB and 64 KB programs that play whole films of graphics and music

The machine and the rules

The Toshiba T1200 keeps its original case and its keyboard, which sounds wonderful (here it is). A Teensy 4.1 reads the keyboard through its 22-pin ribbon cable and speaks USB (following this guide), a Waveshare 10.4-inch panel with 1600 x 720 pixels sits where the old screen was, and the brain is a Raspberry Pi 4 with 8 GB.

For a language model that brain is weak. Its Cortex-A72 cores have no dot-product instructions, which fast AI engines on ARM use for almost everything, its memory moves about 3.5 GB/s, far less than a Pi 5, and the SD card is the only disk.

So I set rules like a demo competition:

RuleWhy
One SD card image, flash it and power onno installer, no second disk
No operating system, AArch64 assemblynothing between the program and the hardware
Only the file on the card countsRAM is free, so the program may use megabytes to save bytes
Speed counts as much as sizea small program that answers slowly is no fun
English only, the font inside the programfewer tokens, no font files
It has to look coolit’s a demo

The smallest thing that runs an LLM

The usual way to run this model on a Pi is Raspberry Pi OS and llama.cpp. That gives you every model, sampling settings and a network, and it costs gigabytes of operating system that has to boot before anything happens. The closest relative of 10KILOMIND is llm.asm, a set of x86-64 assembly programs that run Qwen3-0.6B at 8 bits: as a Linux program it’s 14,712 bytes, as its own bootable bare-metal OS 24,252 bytes, and on a big server CPU it beats llama.cpp on the same model.

Raspberry Pi OS + llama.cppllm.asm10KILOMIND
Runs onLinuxx86-64 with AVX2, as a static program or its own OSa Raspberry Pi 4 (or 5), no OS
Modelany GGUFQwen3-0.6B, 8 bitsQwen3-30B-A3B, 2-3 bits, 80 experts
Program sizegigabytes with the OS14,712 / 24,252 bytes9,972 bytes
StartOS boot, then loadingits own OS boots in 74-94 msprompt after 13 s, rest in the background

10KILOMIND doesn’t use code from either, but it leans on both. It reads llama.cpp’s GGUF quantization formats bit for bit and quantizes its activations the way llama.cpp does, so its answers can be checked against llama.cpp token by token. What I’d love to know is the race on the same board, the same 80-expert model under Raspberry Pi OS and llama.cpp. The estimate is 1.5-2.5 tokens per second there, because Linux uses small memory pages and llama.cpp’s routines are more general, but nobody has measured it yet.

How one token is made

One token through 10KILOMIND: your keys are turned into tokens while you type; the embedding is one row of the table, unpacked by the weight kernel; then 48 layers, each with attention (32 query heads, 4 key/value heads, 8-bit cache) and a router that picks 8 of 80 experts, each pick lighting a cell on the expert map; the output layer scores 92,579 tokens; the most likely token is printed and fed back in for the next one; 1,098 MiB read per token, 2.7 tokens per second

A language model only ever answers one question: given everything so far, what’s the next token? The tokenizer, also in assembly, cuts the text into pieces with Qwen’s split rule and merges letters into tokens with a hash table of merge pairs. The token’s row of the embedding table becomes the starting vector, and that vector goes through 48 layers. In each layer, attention looks back at every earlier token through the key/value cache, and then the router scores the layer’s experts and routes the token to the best 8, each a small network of three matrices. At the end the output layer gives a score to each of the 92,579 tokens, the best one is printed, and it goes back in as the next input.

There’s no sampling and no temperature: 10KILOMIND always takes the most likely token. Everything the engine needs to know about the model is in the model file (sizes, token strings, merge table, rotation table, the chat template), so the same 10 KB would run any Qwen3-style model, and a dense model is simply a model with one expert.

The expert map

The coolest part of the screen is the map on the right. It has a column for each of the 48 layers and a row for each expert, and every time the router picks an expert, its cell lights up: pink when the expert was already in RAM, orange when it first had to be read from the SD card. Then the cell fades through blue to dark in about a second, 15 steps of 83 ms. A grey marker above the map sweeps from left to right once per token, so you see the model think layer by layer, and nothing is reset between tokens, so an expert the model keeps using leaves a bright streak.

Right after a cold boot: “loaded in 13.0 s, 43 MB/s”, the question “tell me a joke” being processed, the counter still at 0.0 t/s, and the expert map with a scatter of orange cells for the experts this question needed that had to be read from the card first, while the top rows are already lighter because the most used experts load first

The map also shows what’s in memory. The experts are numbered by how often they’re used, so the most used sit in the top rows, and a resting cell is dark while its expert is still on the card and lighter once it’s in RAM. Right after start-up only the top rows are light, the first question lights up orange wherever it needs an expert from the card, and over the next minutes you can watch the whole map turn light as the background loading completes. Before all that, while the shared part of the model is read, the map works as a progress bar: it fills column by column, blue at the top to pink at the bottom, with the percentage in big letters where the tokens per second will be.

The start-up screen at 50.2 %: the expert map filling column by column in blue and pink while the shared part of the model is read from the card

The drawing never slows the model down. The engine calls the map once for each expert it runs, the fading happens between layers and while the program waits for a key, and only cells whose colour really changed are drawn. With 80 experts the rows are 5 pixels high and fill the same 512-pixel panel as 128 would. The whole map costs 555 bytes on the card, and it’s my favourite part of the screen.

Typing in real time

A chat feels slow mostly in the pause after Enter, while the model prefills your whole question. In 10KILOMIND prefill runs while you type. Every pre-tokenizer piece except the last is stable under appending (typing more can only change the last word, number or run of punctuation), so those pieces go through the model between keystrokes, with the keyboard polled between layers so typing stays smooth. Backspace keeps the pieces that are still valid and rolls the context position back.

After Enter only the last piece and the chat-template tokens are left. The experts your question needs are routed while you type, so any that were still on the card are already read by then. The first chat starts even earlier: the system prompt’s KV state ships precomputed in the model file, so the Pi copies it into the cache and never runs the system prompt.

Speed: it’s all about memory

For every token the model has to read every weight that token uses. On a small board the memory bus is the limit, rarely the CPU, so the speed trick is to read fewer bytes per token and to read each of them only once.

What one token reads from memory: experts 573 MiB (8 per token, 2-3 bits per weight), attention 396 MiB, the output layer 81 MiB with 92,579 ASCII tokens (134 MiB with all 151,936), the router 48 MiB; 1,098 MiB per token, so the ceiling at 3.5 GB/s is 3.2 tokens per second

The biggest trick is the model itself. Qwen3-30B-A3B routes each token to 8 of 128 experts per layer, so it has the knowledge of a 30B model and streams only about 3 billion weights per token, which makes it faster on this board than an ordinary 4B model and much smarter. The Q2_K/Q3_K weights stay bit-exact GGUF and are never dequantized into memory: each row is read once and multiplied on the fly, about 1.1 GB per token.

Then come the small tricks:

The model also had to fit into 8 GB, and the full 9.6 GB file doesn’t. So I pruned it by routing statistics: on almost 14,000 tokens of English chat I counted which experts the router picks, and kept the 80 most used per layer.

How many experts per layer can go: perplexity 6.75 with all 128 experts, 6.66 with 96, 7.63 (+13 %) with 80, the version on my Pi 4, 8.73 (+29 %) with 64 and 12.10 (+79 %) with 48

A quarter of the experts can go for free, and 80 of 128 fits 8 GB for +13 % perplexity. A smaller ordinary model would fit easily, but it would read more bytes per token and be slower.

It’s memory-bound, and the proof came when the CPU clock went from 1,500 to 1,800 MHz and the speed didn’t change a thing.

Tokens per second on the Pi 4: 0.3 while loading, 2.7 at 1,500 MHz and 2.7 at 1,800 MHz with all experts in RAM, against a computed limit of 3.2 from the memory bus

The engine streams about 1.1 GB per token at roughly 83 % of the measured DRAM bandwidth, so the only way up is fewer bytes. Six experts per token instead of eight would be 13 % faster for 5 % worse perplexity, and I kept eight.

Size: the demoscene part

The program is about 18 KB before any packing, so most of the size work happens in the packer. Demosceners use context-mixing packers for 4 KB intros, and they have one great idea: the unpacker may use lots of memory. Here RAM is free, so the unpacker uses 9.5 MB of tables.

It works bit by bit, and several small models each guess the next bit: one looks at the bytes just before it, one at where the byte sits inside its 4-byte instruction, one follows the longest earlier match, and so on. A tiny mixer learns which model to trust, and a range coder stores only the surprise. The packer tries all 255 combinations of models and keeps the best. gzip makes 12,812 bytes of the same program, and this packer makes 10,607 including its own unpacker.

Bytes on the SD card, step by step: the plain program 18,372; gzip 10,755; own LZ packer 10,017; context mixing 9,722; with the expert map and a boot animation 10,757; opcode first and order search 10,169; the Pi 4 port 11,380; lean card start without checksums 10,430; the release 9,972

The best tricks were about what this packer likes:

TrickBytes saved on the card
Store every instruction with its opcode byte first, so the models see the opcode before the operands, and give calls absolute targets, so the same call looks the same everywhere450, for one extra instruction in the unpacker
Cut the program into units and search their order, with the real packer as the judgeabout 160
Put small routines into the empty space before the exception vector212 of padding
Fill only one exception vector slot and lay the table over the program’s own startabout 2 KB of table
Keep all model knowledge in the model filealmost no tables in the program besides the font
Unpack the embedding table with the weight kernel itself, run on an input with a single 1no unpacking code at all

The surprise was that the usual size-coding habits work against this packer. Shared subroutines with common exit code made the packed file 20 bytes bigger, because repeated identical code costs almost nothing once the models have seen it, while every jump to shared code is new information. So the routines got their own exit code back, 330 bytes bigger in memory and 20 smaller on the card. A bytecode interpreter for the drivers is unlikely to help for the same reason, and no published measurement shows it beating strongly packed native code.

The ideas that didn’t pay teach as much. Three ideas from demoscene research promised 190-570 bytes together, and they gave 60. Separate models for code, text and font saved 68 bytes of data and cost 108 bytes of unpacker. An 8 x 8 font was supposed to save 250-300 bytes and saved 55 to 59, because the 8 x 16 glyphs already pack to a third and the small ones barely pack at all.

The last 1,400 bytes, from 11,380 down to 9,972, came from removing everything my board doesn’t need.

How it works now

One SD card, no operating system: the card holds the Pi firmware, 10KILOMIND (9,972 bytes) and Qwen3-30B-A3B with 80 experts (6.6 GB); the program unpacks itself; on the Raspberry Pi 4 with 8 GB it drives the USB keyboard, the 1600 x 720 screen and the engine on 4 cores; the shared part (573 MiB) loads in 13 s before the prompt, the experts when a token needs one and in the background while you type; it answers at 2.7 tokens per second

The firmware loads only the small file, which unpacks itself and then reads the model straight from a fixed block on the card, with no file system code. Everything is polled, with no interrupts, and one level of page table maps the whole memory twice, once cached for the weights and once uncached for the screen and the USB and SD controllers.

Looking back

Good

Not so good

Versions

ThingVersion
ComputerRaspberry Pi 4 Model B, 8 GB, 1,800 MHz (arm_boost=1), in a Toshiba T1200 case
Screen and keyboardWaveshare 10.4HP-CAPQLED, 1600 x 720 over HDMI; the T1200 keyboard on a Teensy 4.1
Program10KILOMIND, 9,972 bytes packed (1,016 of them the unpacker), AArch64 assembly; a Pi 5 build of 10,607 bytes runs in the emulator
ModelQwen3-30B-A3B-Instruct-2507, ByteShape GGUF at 2.70 bits per weight, 80 of 128 experts per layer, 92,579 tokens, context 2,048
FontSpleen 8 x 16
TestingQEMU (virt with Cortex-A76 and A72, raspi4b), a NumPy reference
Tried and droppedgzip, an LZ packer, separate packer models, shared exit code, the 8 x 8 font, six experts per token, overclocking

raspberry-pibare-metalaarch64assemblyllmllm-inferenceqwen3mixture-of-expertsllama.cppdemoscenesize-codingcontext-mixingcyberdeck

Comments

Comments are GitHub Discussions; you need a GitHub account to write one.