Qwen3-0.6B inference engine fits in 12 KB of assembly: 105 tokens/s on CPU
Developer @superalesha ran the Qwen3-0.6B model without PyTorch or gigabytes of libraries. The engine, written in x86-64 assembly, weighs 12,120 bytes, while the model weights live in a separate file. On 32 threads of an EPYC 7642 CPU, it produces up to 105 tokens per second, and all 64 tokens of greedy generation matched PyTorch FP32. The takeaway: the inference core itself is compact, and the main weight of the stack is generality.
AI-processed from X: @superalesha; edited by Hamidun News
To simply print a response from a language model, a typical stack pulls in Python, PyTorch, and a set of system libraries. Together they take up gigabytes. A developer under the handle @superalesha set out to measure how much code is actually needed.
They wrote an engine to run Qwen3-0.6B (a small model with 0.6 billion parameters) in pure x86-64 assembly.
The executable itself is 12,120 bytes, or about 12 KB. An important caveat: this is the size of the program, while the model weights are stored in a separate file. On an AMD EPYC 7642 CPU, the engine delivers up to 105 tokens per second.
A token is a chunk of text roughly the size of a syllable or a short word, so the speed is quite usable for chat. The answers matched the PyTorch reference.
What fits in 12 kilobytes
The author wrote 3,688 lines of NASM and linked them into a static ELF file with no gcc and no runtime. Running readelf -d prints "There is no dynamic section in this file." This means there are no linked libraries at all: neither libc (the standard C library) nor libm (the math library).
The entire forward pass of the 28-layer model fits in this footprint:
- weights in the 8-bit Q8_0 format, mapped via mmap, meaning they are read directly from the file without being copied into memory;
- GQA attention with 16 query heads and 8 key and value heads;
- QK-Norm normalization applied per head before rotary positional embeddings (RoPE), a SwiGLU block, and a KV cache that stores already computed values;
- greedy decoding (always taking the most probable token) and top-p sampling;
- a custom Q8_0 matrix multiplication using AVX2 and FMA instructions, with fused QKV projections and gate+up projections.
Without libm, the author had to hand-write polynomial approximations for expf and sincosf with an error below 1.4e-7. The BPE tokenizer, which splits text into tokens, is also written in assembly. It uses a 524,288-slot hash table with Fibonacci hashing. According to the author, it matches HuggingFace token for token, including Cyrillic in UTF-8 and the --think mode. Multithreading is implemented without pthreads, using raw Linux system calls clone() and futex().
Speed and accuracy
Speed depends heavily on thread count. On one thread, decoding yields 7.96 tokens per second; on 40 threads, 100.18. The peak is reached on 32 threads: 105.39 tokens per second for generation and 154.28 tokens per second for prompt processing (so-called prefill).
According to the author's claim, correctness is strict. Comparison with PyTorch in FP32 showed all 64 greedy-generation tokens matching. For any thread count from 1 to 47, the result is bit-identical. The logits (raw model scores before token selection) matched the Python Q8_0 reference implementation, with a cosine similarity of 1.000000000, meaning the vectors are practically identical.
For a 0.6-billion-parameter model, this speed on a CPU without a GPU is perfectly workable. However, all figures are reported by the author in the post and have not been independently reproduced.
Limitations and what's next
The 12 KB is the size of the executable, not of the entire system. The model weights are stored separately, and they are considerably larger. In addition, the code is written for one model architecture and for x86-64 with AVX2. It cannot run on a different processor or with a different model without being rewritten.
The practical takeaway for developers is this. The inference core boils down to quantized matrix multiplication, attention, normalization, and a tokenizer. Most of the familiar "weight" of the stack comes from generality and convenience. For embedded systems, bootloaders, and tasks requiring a minimal attack surface, this experiment shows a lower bound on what is actually needed to run a model.
This is the first of three parts in the llm.asm repository. In the second, the author dropped Linux entirely and ran Qwen3-0.6B on bare metal; in the third, they wrote a trainer for Mini-GPT in assembly. The author posted the repository link and build instructions in a reply to the post.
- Nov 25, 2026Tencent Compresses Three Models Into One: WePM-4B Takes Up 8 GB Instead of 21–43 GB
- Nov 25, 2026A 4.7 MB Skill Taught Qwen3.8-27B to Write 1C Queries: 98.7% Fully Correct Answers vs 23%
- Nov 25, 2026PrismML Squeezes 27B Coding Model to 5.9 GB, Keeps 75.6% on SWE-bench Verified
- Nov 25, 2026JetBrains Releases Mellum2.1 Instruct: Half the Tokens on Agentic Tasks
Key Questions Answered
What fits in 12 kilobytes?
The author wrote 3,688 lines of NASM and linked them into a static ELF file with no gcc and no runtime. Running readelf -d prints "There is no dynamic section in this file." This means there are no linked libraries at all: neither libc (the standard C library) nor libm (the math library).
What are the key details on Speed and accuracy?
Speed depends heavily on thread count. On one thread, decoding yields 7.96 tokens per second; on 40 threads, 100.18. The peak is reached on 32 threads: 105.39 tokens per second for generation and 154.28 tokens per second for prompt processing (so-called prefill). According to the author's claim, correctness is strict. Comparison with PyTorch in FP32 showed all 64 greedy-generation tokens matching. For any thread count from 1 to 47, the result is bit-identical.
What are the key details on Limitations and what's next?
The 12 KB is the size of the executable, not of the entire system. The model weights are stored separately, and they are considerably larger. In addition, the code is written for one model architecture and for x86-64 with AVX2. It cannot run on a different processor or with a different model without being rewritten. The practical takeaway for developers is this. The inference core boils down to quantized matrix multiplication, attention, normalization, and a tokenizer.
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
Daily 60-sec AI Voice Brief + Weekly Production AI Agent Playbook
Listen to a 60-second AI news brief every morning and get a weekly hands-on playbook for shipping AI agents to production — tools, MCP servers and patterns that work. Curated by Jemal Hamidun, Head of AI at Alpina Digital.
