Quick Answer: An LLM in assembly means writing the inference math (matrix multiplies, attention, normalization, tokenization) directly in CPU instructions instead of C or Python. The llm.asm project does this in pure x86-64 NASM for Qwen3-0.6B, producing a 14,712-byte static Linux binary with no libc. On a 40-thread AMD EPYC 7642, it decoded at 126.8 tokens per second at peak, ahead of llama.cpp's Q8_0 CPU path.

Most people assume that running a language model at usable speed requires PyTorch, a GPU stack, or at least a C++ runtime. The llm.asm repository argues otherwise. It ships three projects: a Qwen3-0.6B inference engine, a bootable bare-metal OS that runs the same model with no operating system underneath, and a from-scratch Mini-GPT trainer. All of it is hand-written NASM, 17,252 lines in total, with zero C and zero runtime dependencies.

What the Build Actually Contains

The project assembles with nasm and links with ld. The math kernels are hand-written too: expf, sincosf, RMSNorm, RoPE, SiLU, and softmax. Threading doesn't use pthreads. It calls Linux clone() and futex() directly to build a hybrid spin/futex pool, and the tokenizer is a Fibonacci-hashed BPE encoder.

You can verify the dependency claim yourself. Run file build/asm-llm and look for "statically linked," then run ldd build/asm-llm, which should report "not a dynamic executable." Nothing is hiding underneath the binary. The Phase 1 engine is 1,251 lines, and the shared core it reuses is another 3,857.

That's the easy part. The speed question is harder.

Why Decode Speed Is the Number That Matters

Generation is autoregressive. Each new token needs a full pass over the model weights. For Qwen3-0.6B in Q8_0, the .asmbin file is 613.66 MiB. If every token streams roughly 600 MiB from memory, you're bandwidth-bound long before you're compute-bound. The fastest path is the one that moves fewer bytes and keeps the SIMD units fed.

Prefill behaves differently. Many prompt tokens share a single weight read, which is why llama.cpp's batched GEMM is so effective on prompts. The llm.asm README is explicit about this: llama.cpp uses batched GEMM for the pp34 prefill pass, while llm.asm runs token-by-token GEMV. That means the headline comparison covers decode (tg64) only, and you shouldn't read it as a prompt-processing win.

Here's where most benchmarks get misleading. A single tokens-per-second number hides which phase you measured.

The Counter-Intuitive Result: Assembly Alone Didn't Win

The popular advice is "rewrite it in assembly and it'll be fast." That's incomplete. The FP32-activation build (FAST_Q8=0) reached 98.50 tok/s at 40 threads, which is below llama.cpp's 105.08 on the same machine.

The winning build (FAST_Q8=1) changed the data path rather than the language. It uses INT8×INT8 AVX2 via vpmaddubsw and vpmaddwd, reads FP16 block scales through F16C's vcvtph2ps, prefetches the next weight row, keeps the KV cache contiguous and head-major, and parallelizes GQA attention. Those choices pushed decode to 125.86 tok/s, with a 126.81 tok/s peak.

Assembly's real contribution was control. It let the author pick the number format and memory layout precisely and then verify the result instruction by instruction. The same ideas could be written in C with intrinsics, so treat the language as secondary to the design.

There's a trade-off. FAST_Q8=1 isn't numerically identical to FP32. Its cosine similarity to PyTorch FP32 is 0.99965, and the repo reports 64 of 64 greedy tokens matching on its test. That's strong evidence, but it's one test, not a guarantee for every prompt.

Head-to-Head: llm.asm vs llama.cpp on Qwen3-0.6B Q8_0

The comparison ran on the same AMD EPYC 7642, with CPU-only inference (-ngl 0), 34 prompt tokens, 64 generated tokens, and a 3-run average.

Threadsllama.cpp (Q8_0)llm.asm (FAST_Q8=1)llm.asm advantage
116.63 tok/s20.70 tok/s+24.5%
880.79 tok/s103.64 tok/s+28.3%
16103.03 tok/s121.86 tok/s+18.3%
40105.08 tok/s125.86 tok/s+19.8%

The gap is largest at low thread counts and narrows when both engines hit a memory ceiling. llama.cpp stays flat near 104–105 tok/s from 16 to 40 threads, while llm.asm keeps climbing slowly to about 122–126. That pattern fits a bandwidth limit, not a compute limit. These are single-machine results, so expect different numbers on other CPUs.

Bare-Metal: Running Qwen3 With No Operating System

The bare-metal build boots through Multiboot 1, enables 4-level paging, switches to long mode, turns on AVX2, FMA, and F16C, brings up SMP through ACPI and APIC, and then runs a chat REPL over VGA, PS/2, and COM1. Boot takes 74–94 ms.

The throughput is the surprising part. On KVM with an EPYC host, the OS reached 134.9 tok/s at 16 vCPUs, compared with 121.86 tok/s for the Linux binary at 16 threads. The README credits roughly 10% of that gain to 2 MiB huge-page identity mapping, which cuts TLB pressure on the weight stream. On a Proxmox VM running on a Xeon E5-2670 v3 with a 0 GB disk, it reached 55.4 tok/s.

The failure mode is different from Linux. There's no filesystem driver to fall back on, so the model bytes and memory map have to be in the right place when the kernel starts. When something is wrong at that layer, your first debugging step is checking the Multiboot memory map, not the model code.

That said, the OS build is the hardest to reproduce. Start with the Linux binary and move to bare metal once the math is verified.

Mini-GPT Training: Where the Numbers Need Context

The third project is a from-scratch FP32 Mini-GPT trainer. Its core is a register-blocked 6×16 AVX2+FMA SGEMM, a full analytical backward pass, and decoupled AdamW. The repo reports a cosine similarity of 1.0000000000 across all 21 gradient tensors against PyTorch CPU, and throughput of 27,662 training tokens per second.

Read the convergence claim carefully. The README reports val_loss falling from 4.19 to 1.51 on TinyShakespeare in about 4 minutes. The sample TUI capture is a different run: at step 400 it shows loss=1.6604 and best_val=1.8399, after 35.2 seconds. Those are separate measurements with different settings, so don't compare them directly.

The live Braille TUI is the most useful part for a practitioner watching a run. It shows:

  • A loss curve with separate training and validation markers
  • A progress bar with elapsed time, loss, validation loss, gradient norm, learning rate, and tokens per second
  • A live text sample, so you can see the model improve in real time

How to Try It Yourself

Here's the shortest path to a working run:

  1. Clone and build the project with git clone https://github.com/alesha-pro/llm.asm.git, then cd llm.asm and make all.
  2. Export the weights once with python3 scripts/export_weights.py --model-dir models/qwen3-0.6b-bf16 --out models/qwen3-0.6b-q8_0.asmbin --scale-dtype fp16. This is the only step that needs Python.
  3. Build the fast path with make inference FAST_Q8=1, then run ./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 16.

Keep these limits in mind before you trust the numbers:

  • The build needs a CPU with AVX2, FMA, and F16C, which means Intel Haswell or AMD Excavator and newer.
  • FAST_Q8=1 trades exact FP32 numerics for speed, so use FAST_Q8=0 when fidelity matters more.
  • The benchmarks cover one model and a small set of CPUs, so measure on your own hardware before you plan around them.

Frequently Asked Questions

what is an LLM in assembly?

An LLM in assembly means the model's inference math (matrix multiplies, attention, normalization, and tokenization) is written in CPU instructions rather than a high-level language. llm.asm does this in x86-64 NASM for Qwen3-0.6B, with no libc and no runtime. The result is a 14,712-byte static Linux binary.

how to run qwen3 inference without python?

Export the weights once with scripts/export_weights.py into a .asmbin file, then build with make inference FAST_Q8=1. Run ./build/asm-llm with -m pointing at the .asmbin, -p for your prompt, and -t for thread count. Python is needed only for the one-time export. Inference has no Python dependency.

why is decode slower than prefill?

Decode generates one token at a time, so each step streams the full set of model weights from memory. Prefill processes many prompt tokens together, so one weight read serves many tokens. That's why batched GEMM helps prompt processing far more than generation, and why the llm.asm benchmark measures decode (tg64).

when should I use FAST_Q8=0 instead of FAST_Q8=1?

Use FAST_Q8=0 when numerical fidelity matters more than throughput, such as debugging or comparing against a reference. It keeps FP32 activations and reached 98.50 tok/s at 40 threads on the benchmarked EPYC. FAST_Q8=1 reached 125.86 tok/s there, with a cosine similarity of 0.99965 to PyTorch FP32.

The most useful takeaway is that LLM in assembly is mostly about controlling data formats and memory layout, not about the language itself. Clone the repo, run make inference FAST_Q8=1, and record your tokens per second at -t 1 and -t 16 on your own CPU. Pass this to anyone wrestling with slow CPU inference and no GPU.