Run Qwen3-0.6B from a 14 KB pure-assembly binary: hands-on with llm.asm
llm.asm is three LLM projects in pure x86-64 assembly — a 14 KB inference engine, a 24 KB bootable OS, and a 32 KB trainer. This tutorial builds all three, runs Qwen3-0.6B, and trains a Mini-GPT from scratch, with every number measured on a 4-core CPU.
- Three projects, one repo: a 14,712-byte Qwen3-0.6B inference engine, a 24,252-byte bootable LLM OS, and a 32,944-byte Mini-GPT trainer — 17,195 lines of NASM assembly, zero C, zero libc.
- It blew up fast: created November 25, 2026, the repo passed 2,400 stars in three days, gaining 966 stars on its best day.
- Verified end to end here: all math unit tests pass, the weight export produces exactly 643,469,504 bytes, and inference answers are deterministic across runs and thread counts.
- Real speeds on a 4-core CPU: 15–24 tok/s decode for Qwen3-0.6B; training runs at 1,200–2,500 tok/s. The project's EPYC numbers reach 126.8 tok/s.
- One model only: inference is hard-wired to Qwen3-0.6B, and the bare-metal boot needs QEMU/KVM — which this sandbox lacks, so the boot is documented, not run here.

Three days after it appeared on GitHub, a repository called llm.asm had 2,407 stars. The pitch is a stunt with a point: three complete LLM projects — inference, a bootable operating system, and a from-scratch trainer — written in 100% pure x86-64 assembly, with no C, no libc, no runtime, and no dependencies. The inference engine for Qwen3-0.6B is a 14,712-byte static binary. The bootable OS that runs the same model with no Linux underneath is 24,252 bytes. The trainer that teaches a small transformer to write Shakespeare is 32,944 bytes. All three were built and run for this tutorial on a 4-core CPU virtual machine with no GPU, and every number below was measured there.
The reason it is worth your time is not the byte counts. It is that the whole stack is small enough to actually read. A modern inference engine is millions of lines spread across frameworks, runtimes, and kernels; llm.asm is 17,195 lines of assembly total, and the part that runs the model is small enough to hold in your head. If you have ever wanted to understand what a transformer really does at the metal — the matmuls, the attention, the tokenizer, the KV-cache — this is the shortest path to watching it happen, because there is nothing between you and the silicon except an assembler.
This tutorial builds all three projects, verifies the math kernels against their own unit tests, downloads Qwen3-0.6B, converts it to the project's compact format, runs real inference, and trains a 2.7-million-parameter Mini-GPT from scratch on TinyShakespeare. The bare-metal OS gets its own section: it builds here, and the boot commands are documented — but booting needs QEMU with KVM, which this sandbox does not have, so that part is labelled as not run here rather than presented as verified.
What you'll need#
- A Linux x86-64 machine with AVX2, FMA, and F16C — any Intel Haswell or AMD Excavator chip from 2013 onward qualifies. No AVX-512 needed, no GPU, no model API key.
nasmandbinutils(forldandobjcopy):sudo apt install nasm binutilson Debian or Ubuntu. The build in this tutorial used nasm 2.16.01.- Python 3 with
numpy— only for the one-time weight export. Nothing at runtime needs Python. - About 2.5 GB of free disk: the Qwen3-0.6B download is 1,503,300,328 bytes, and the converted file is another 643,469,504 bytes. You can delete the download after the export.
- A note on scope: everything in this tutorial runs Qwen3-0.6B and only Qwen3-0.6B for inference. The trainer is a separate, general Mini-GPT. If you want other models, you want llama.cpp — see the alternatives table at the end.
Step 1 — Build all three binaries#
Clone the repository and build everything. There is no configure step, no dependency fetch, and no package manager involved — make runs nasm over the assembly sources and links the objects with ld:
git clone https://github.com/alesha-pro/llm.asm.git
cd llm.asm
make all
The build takes seconds. Three binaries land in build/, and their sizes are the first thing to check — they are the project's headline claim, and they matched the README exactly on this machine:
ls -la build/asm-llm build/asm-gpt-train build/asm-llm-os.elf
file build/asm-llm build/asm-gpt-train build/asm-llm-os.elf
-rwxr-xr-x 1 user user 14712 build/asm-llm
-rwxr-xr-x 1 user user 32944 build/asm-gpt-train
-rwxr-xr-x 1 user user 24252 build/asm-llm-os.elf
build/asm-llm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
build/asm-gpt-train: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
build/asm-llm-os.elf: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
14,712 bytes for the inference engine, 32,944 for the trainer, 24,252 for the bootable kernel. The file output is worth reading: all three are statically linked and stripped, with no dynamic section at all — readelf -d on any of them reports nothing. There is no loader, no shared library, and no interpreter between the kernel and the first instruction. That is the whole point of the exercise, and it is also why the binaries run anywhere on x86-64 Linux without installing anything.
If the build fails, the usual cause is a missing nasm — the Makefile calls nasm by name, so it must be on your PATH. A CPU without AVX2 will assemble fine and then crash at runtime; check with grep -m1 avx2 /proc/cpuinfo before going further.
Step 2 — Prove the math before you trust the model#
Before downloading any weights, run the project's own unit tests. They exercise the hand-written AVX2 kernels — exp, sin/cos, RoPE frequencies, RMSNorm, SiLU, and the Q8_0 matmul — against NumPy references:
python3 scripts/test_math.py build/test_math
Detected matmul mode: FAST_Q8=1 (Q8_0xQ8_0)
fast_expf_avx2 max_rel_err = 1.394e-07 (target < 1e-6)
fast_sincosf sin max_abs_err = 2.940e-08 (target < 1e-6)
fast_sincosf cos max_abs_err = 2.928e-08 (target < 1e-6)
init_rope_freqs max_abs_err = 4.363e-14 (target < 1e-12)
rmsnorm_avx2 max_abs_err = 2.056e-07 (target < 1e-6)
silu_mul_avx2 max_rel_err = 6.774e-08 (target < 1e-6)
matmul_q8_0 v1 max_abs_err = 9.537e-07 (target < 1e-5, vs FP32=8.268e-02)
matmul_q8_0 v2 max_abs_err = 5.960e-07 (target < 1e-5, vs FP32=8.285e-02)
ALL PURE-ASM MATH & SIMD KERNEL UNIT TESTS PASSED!
Every error matches the project's published table to the last digit. That matters more than it looks: the transformer is built from these kernels, so if exp or the matmul were wrong by more than the tolerance, the model would produce garbage downstream and you would have no idea which layer to blame. Passing this gate first means any weird output later is the model's behaviour, not a broken kernel.
Step 3 — Download Qwen3-0.6B and export it to .asmbin#
The binary cannot read Hugging Face weights directly. A Python export script converts the BF16 safetensors and tokenizer.json into a single .asmbin file: per-row Q8_0-quantised weights with FP16 block scales, 64-byte aligned throughout, designed to be mmap()-ed straight into memory. Download the three files first — plain curl works, no account needed:
mkdir -p models/qwen3-0.6b-bf16
curl -fsSL https://huggingface.co/Qwen/Qwen3-0.6B/resolve/main/config.json \
-o models/qwen3-0.6b-bf16/config.json
curl -fsSL https://huggingface.co/Qwen/Qwen3-0.6B/resolve/main/tokenizer.json \
-o models/qwen3-0.6b-bf16/tokenizer.json
curl -fsSL https://huggingface.co/Qwen/Qwen3-0.6B/resolve/main/model.safetensors \
-o models/qwen3-0.6b-bf16/model.safetensors
ls -la models/qwen3-0.6b-bf16/
-rw-r--r-- 1 user user 726 config.json
-rw-r--r-- 1 user user 11422654 tokenizer.json
-rw-r--r-- 1 user user 1503300328 model.safetensors
Check the sizes — a truncated model.safetensors will fail the export with an unhelpful error, and 1,503,300,328 bytes is the exact count to expect. Then run the export (NumPy is the only dependency):
python3 scripts/export_weights.py \
--model-dir models/qwen3-0.6b-bf16 \
--out models/qwen3-0.6b-q8_0.asmbin \
--scale-dtype fp16
Verified embed_tokens == lm_head exact (max_diff=0.0)
Quantizing embed_tokens (151936, 1024) -> Q8_0 (scale_dtype=fp16, v2)...
Exported layer 7/28 (stride=16,720,896 B)
Exported layer 14/28 (stride=16,720,896 B)
Exported layer 21/28 (stride=16,720,896 B)
Exported layer 28/28 (stride=16,720,896 B)
Export complete: models/qwen3-0.6b-q8_0.asmbin
Format : .asmbin v2 (scale_dtype=fp16, flags=0x7)
Total size : 643,469,504 bytes (613.66 MiB)
off_tokenizer: 128
off_embed : 9,973,952
off_layers : 175,280,320 (stride=16,720,896 x 28)
off_final_nrm: 643,465,408
Elapsed : 46.30 s
Two things to note. First, the export verifies that the tied embeddings and the LM head are bit-identical (max_diff=0.0) and stores them once, which is why the file is 613.66 MiB instead of the 1.40 GiB the BF16 download occupies. Second, the total — 643,469,504 bytes — is exactly the figure the README states for the v2 format, so you can confirm the export is correct from the byte count alone. Once it exists, the BF16 files can be deleted; the binary never touches them again.
Step 4 — First inference: a real model answers#
Run the example prompt from the project's README. -m is the weights file, -p the prompt, -n the maximum tokens, -t the thread count:
./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin \
-p "Explain how a CPU cache works in 3 concise sentences." -n 128 -t 4
A CPU cache is a small amount of memory used to store frequently accessed data and instructions. It helps speed up processing by storing data that is likely to be used again. The cache is organized in a way that allows it to quickly retrieve data from memory when needed.
[asm-llm] prefill: 25 tok in 1633.63 ms (15.30 tok/s)
[asm-llm] decode : 53 tok in 3304.63 ms (15.74 tok/s, threads=4)
That is a genuine Qwen3-0.6B answer, produced by 14 KB of assembly: three sentences, on topic, and it stopped by itself after 53 tokens when the model emitted the end-of-turn token. The stats line is the honest part — prefill and decode rates, measured, not claimed. On this shared 4-core sandbox the decode ran at 15–24 tok/s across repeated runs with 4 threads. The project's own numbers, measured on a 47-core AMD EPYC 7642, are 20.7 tok/s on one thread and 126.8 tok/s at 40 threads, and 18–36% faster than llama.cpp CPU on the same model and quantisation. Your laptop will land somewhere between the two: this is a small model on a CPU, so expect tens of tokens per second, not hundreds.
A second prompt checks arithmetic, and it is the one the README uses as its worked example:
./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin \
-p "If Alice has 3 apples and Bob gives her 4 more, then she eats 2, how many apples does Alice have?" \
-n 96 -t 4
Let's break it down step by step:
- Alice starts with **3 apples**.
- Bob gives her **4 more apples**, so she now has:
$$
3 + 4 = 7 ext{ apples}
$$
- Then she eats **2 apples**, so the final number of apples she has is:
$$
7 - 2 = 5
$$
**Answer:** Alice has **5 apples**.
[asm-llm] prefill: 39 tok in 2199.98 ms (17.73 tok/s)
[asm-llm] decode : 96 tok in 5714.13 ms (16.63 tok/s, threads=4)
Correct, with the step-by-step working and the LaTeX intact. Greedy decoding is deterministic here — the same prompt and flags produce byte-identical output on every run, and identical output at any thread count, which the project verifies against PyTorch (64/64 greedy tokens matching).
Two more flags are worth trying before moving on. --print-tokens shows the tokeniser working — the cache prompt encodes to exactly the 25 tokens the prefill line reports:
./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin \
-p "Explain how a CPU cache works in 3 concise sentences." -n 8 -t 4 --print-tokens
PROMPT_TOKENS:151644,872,198,840,20772,1246,264,13940,6500,4278,304,220,18,63594,22870,13,151645,198,151644,77091,198,151667,271,151668,271
A CPU cache is a small amount of
GEN_TOKENS:32,13940,6500,374,264,2613,3311,315
And --chat starts an interactive multi-turn session with the KV-cache preserved across turns. Piped input works, which makes it scriptable:
printf 'What is 2 + 2?
/quit
' | ./build/asm-llm \
-m models/qwen3-0.6b-q8_0.asmbin --chat -t 4
Interactive Multi-Turn Chat (/clear, /think, /nothink, /quit)
asm-llm> 2 + 2 = 4.
[asm-llm] prefill: 20 tok in 25315.32 ms (0.79 tok/s)
[asm-llm] decode : 8 tok in 18817.40 ms (0.37 tok/s, threads=4) ctx=30/2048
Ignore the speed on that run — a training job was competing for the same cores while it ran. What matters is the behaviour: the prompt is answered, the context line reports ctx=30/2048, and /quit exits cleanly. The chat commands are /clear to reset the conversation, /think and /nothink to toggle reasoning mode, and /quit to leave.
Reasoning mode deserves a look because it shows the model's limits honestly. With --think, Qwen3-0.6B writes out its working:
./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin \
-p "What is 17 * 23?" -n 512 -t 4 --think
<think>
Okay, so I need to figure out what 17 multiplied by 23 is. Hmm, let me think. [...]
First, maybe I can split 17 into 10 and 7. Then 23 into 20 and 3. [...]
10*20 is straightforward. 10 times 20 is 200. Then 7*3 is 21. Adding those together, 200 + 21 equals 221. Wait, so is the answer 221? [...]
17*20 is 340, and 17*3 is 51. Adding those gives 340 + 51 = 391. Wait, hold on, that's conflicting with my previous result. Which one is correct? [...]
[asm-llm] prefill: 18 tok in 1022.82 ms (17.60 tok/s)
[asm-llm] decode : 512 tok in 34804.70 ms (14.68 tok/s, threads=4)
The 0.6B model talks itself into the wrong answer (221), catches the mistake, recomputes correctly (391) — and then runs out of its 512-token budget mid-sentence before giving a final answer. That is a useful thing to see: the reasoning machinery works, the arithmetic is shaky, and the token budget is the binding constraint. For real use, keep --think prompts short and the budget generous; for quick answers, leave it off.

Step 5 — Train a Mini-GPT from scratch#
The trainer is the most surprising part of the repo, because training is where you would expect assembly to fall over. It does not: asm-gpt-train is a complete transformer trainer — forward pass, analytical backward pass, AdamW with decoupled weight decay, gradient clipping, learning-rate warmup and cosine decay — in 32,944 bytes, with no Python anywhere in the loop. The model is a 6-layer, 192-dimension Mini-GPT with 2,681,664 parameters, trained on TinyShakespeare. Download the corpus and build the trainer:
mkdir -p data checkpoints
curl -fsSL https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt \
-o data/tinyshakespeare.txt
make train
make train-check
Then run the 400-step demo from the trainer's README. The flags are the full configuration: 6 layers, dim 192, 6 heads, 512 hidden, batch 16, sequence 128, 400 steps, learning rate 0.002, 4 threads, plain logging instead of the Braille TUI (which needs a real terminal):
./build/asm-gpt-train \
--data data/tinyshakespeare.txt \
--layers 6 --dim 192 --heads 6 --hidden 512 \
--batch 16 --seq 128 --steps 400 \
--lr 0.002 --wd 0.15 --grad-clip 1.0 --warmup 40 --seed 42 \
-t 4 --plain --log-every 50 --eval-every 40 --sample-every 100 --sample-tokens 200 \
--prompt "ROMEO:
" --save checkpoints/demo.ckpt
On this sandbox the run took 12 minutes 33 seconds — the project's 35-second figure is for a 24-thread EPYC, and a shared 4-core VM is not that. The loss curve is the point, and it is real:
step 1/400 | train_loss=4.1872 | gnorm=9.50 | lr=0.000050
step 40/400 | train_loss=2.4509 | val_loss=2.4565 | gnorm=1.03 | lr=0.002000
step 100/400 | train_loss=2.1542 | gnorm=0.56 | lr=0.001883
step 200/400 | train_loss=1.9669 | val_loss=2.0067 | gnorm=0.59 | lr=0.001264
step 300/400 | train_loss=1.7106 | gnorm=0.51 | lr=0.000528
step 400/400 | train_loss=1.6604 | val_loss=1.8288 | gnorm=0.53 | lr=0.000200
Training loss falls from 4.19 to 1.66, validation from 2.46 to 1.83, and the final train loss of 1.6604 is identical to the figure in the project's README — same seed, same data, same result, which is the determinism claim holding up on a different machine. The samples show what the loss numbers mean. At step 100 the model has the rhythm of verse but not the words:
--- sample @ step 100 ---
ROMEO:
Ang worde the we powes, lophion a seree meart,
Ther thast the ime at the to no meret,
The wind fort the cis prang sendathene sils,
Mus my to stroother to se and as dithen and so my all wou lore, mears
By step 200 it has speaker turns, and by step 400 it is producing recognisable Shakespeare-shaped dialogue — wrong words, right shape:
--- sample @ step 400 ---
ROMEO:
Nay, to lond, in if as my kears, some with death.
DUKE VINCENTIO:
What in the not the deady uppray, that the abrot
So so and comman trow of my shall with wife:
Then the word, me, I say againts and do
That step-400 sample is also identical to the one in the project's README, character for character. If you run this yourself with the same flags and seed, you will get the same text — which is a stronger reproducibility claim than most ML projects can make.
Checkpoints are the other half of the workflow: train once, sample later. A shorter 100-step run with --save writes a 10,727,232-byte .gptckpt in 146.72 seconds, and --sample-only loads it back for generation:
./build/asm-gpt-train --load checkpoints/demo.ckpt --sample-only \
--prompt "KING RICHARD:
" \
--sample-tokens 240 --temp 0.75 --topp 0.92 --seed 1337 -t 4
KING RICHARD:
Ce wing is murd dome are ord say dom core;
Whing and you and your bat ward mears seres mome bean yourer:
You hame and sant are frin in sor to fore,
I whaid you thir aver, the are to matht,
And lon ond that cough the fion sore,
Ond ore bet t
One hundred steps is not much training, so the text is rough — but the pipeline is the point: the checkpoint round-trips, sampling works from a saved model, and the whole train-then-generate loop runs with zero Python. If you want the full convergence run, the README's 1,500-step configuration (sequence 256) takes the validation loss to 1.51 in about four minutes on their hardware; on this box, budget roughly an hour.

Step 6 — The 24 KB operating system#
The third project is the one that sounds impossible: a bootable x86-64 operating system that runs Qwen3-0.6B with no Linux, no Windows, and no disk. The kernel is the same inference code compiled with a bare-metal flag, plus a bootloader, an ACPI/SMP bring-up, VGA and serial drivers, and a PS/2 keyboard driver. Build it and inspect it:
make os FAST_Q8=1
make os-check
-rwxr-xr-x 1 user user 24252 build/asm-llm-os.elf
build/asm-llm-os.elf: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
That build is verified — it ran here and produced the same 24,252-byte kernel the README specifies. Booting it is a different matter, and this is where the honest labelling matters: the boot was not run in this sandbox. It needs QEMU with KVM, and this virtual machine has neither QEMU installed nor /dev/kvm available. The commands below are the project's own, from its README and Makefile — they are documented, not verified here, and you should run them on a machine with KVM:
qemu-system-x86_64 -enable-kvm -cpu host -m 2G -smp 16 \
-kernel build/asm-llm-os.elf \
-initrd models/qwen3-0.6b-q8_0.asmbin \
-nographic
Or the Makefile shortcut, including a one-shot batch prompt with a clean ACPI shutdown:
make os-run MODEL=models/qwen3-0.6b-q8_0.asmbin SMP=16 \
CMDLINE='prompt="Explain how a CPU cache works in 3 concise sentences." max_tokens=64 think=0 shutdown=1'
What the project reports for that boot, measured on its own hardware: 74–94 ms from power-on to an interactive asm-llm> chat prompt, 134.9 tok/s decode under KVM on 16 vCPUs, and the same tokens as the Linux build — 100% parity across 1 to 32 vCPUs. The model file is passed as an initrd and bound zero-copy from RAM on 2 MiB huge pages, which is why the bare-metal build is slightly faster than the Linux one. There is also a bootable hybrid BIOS+UEFI ISO target (make os-iso) for running it on real hardware or a diskless Proxmox VM — the project documents a 0 GB-disk VM running at 55.4 tok/s on a Xeon E5-2670 v3. Treat those as the project's numbers, not this tutorial's: the kernel builds here, the boot is yours to try on a machine with KVM.
When to use this vs alternatives#
| Approach | Best when | Watch out for |
|---|---|---|
| llm.asm (this tutorial) | You want to learn how inference actually works; you need the smallest possible runtime; you want deterministic, dependency-free binaries | Qwen3-0.6B only; CPU only; no tool use, no server mode, no GPU; a 0.6B model is weak at reasoning |
| llama.cpp | You need real work done: any GGUF model, server mode, tool calling, GPU offload, embeddings | Larger, more moving parts; you will not read the whole stack in a weekend |
| Ollama | You want a model running with one command and a clean API, and you do not care how it works | Heavier runtime; less control over quantisation and threading; hides the internals |
| PyTorch / transformers | You are training or fine-tuning, or you need the ecosystem (datasets, evals, PEFT) | Multi-gigabyte installs; slow on CPU; the opposite of minimal |
The honest summary: llm.asm is not the tool you reach for to ship a product. llama.cpp is faster to set up for real models, Ollama is easier, and PyTorch is where training happens at scale. What llm.asm is for is understanding — and for the cases where a 14 KB static binary that needs nothing is itself the requirement: embedded systems, air-gapped machines, demos, and teaching. It is also the fastest way to answer the question "what does a transformer cost, really?" — because you can read every line of the answer.
Limitations#
- One model. Inference is hard-wired to Qwen3-0.6B. There is no model zoo, no GGUF loader, and no path to a bigger model without writing one.
- One architecture family. The trainer is a fixed Mini-GPT shape. It teaches the mechanics of training; it will not train anything you would deploy.
- CPU only, x86-64 only. No GPU path, no ARM. The AVX2/FMA/F16C requirement excludes older hardware and every non-x86 machine.
- A 0.6B model is weak. It answers factual questions cleanly, writes plausible prose, and then — as the
--thinkrun showed — talks itself into 221 before catching the error. Treat its outputs as a demonstration, not an oracle. - The speed claims are the project's, on the project's hardware. My measured decode on this shared sandbox was 15–24 tok/s at 4 threads; their EPYC numbers are 20.7 tok/s on one thread and 126.8 tok/s at 40 threads. The +18–36% lead over llama.cpp is their benchmark, not mine — I did not build llama.cpp to re-check it.
- The bare-metal boot is unverified here. The kernel builds; the boot needs QEMU/KVM, which this sandbox lacks. The boot numbers in Step 6 are the project's measurements.
- Four commits, three days old. The repository was created on November 25, 2026. That is the risk with any fast-rising project: the code is fresh, the issue tracker is thin, and the API can change. Pin the commit (
e7d4883is what this tutorial ran) if you build on it.
The takeaway#
A language model is, at the bottom, a few thousand lines of arithmetic: matrix multiplies, a normalisation, an attention pass, a sampler. Frameworks hide that under layers of abstraction until it feels like magic. llm.asm removes the layers. Clone it, run make all, and you have a 14 KB binary that runs a real model, a 32 KB binary that trains a real transformer from scratch, and a 24 KB kernel that boots a computer into a chat prompt with no operating system at all — each one small enough to read end to end. The model it runs is small and the speed on a shared VM is modest, but that is not the point. The point is that you can now see the whole machine, and once you have seen it, every other inference stack makes more sense. That is worth an evening, and it is why 2,400 people starred it in three days.