Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
ReleaseInsight · On RadarX: @superalesha→ original

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
Qwen3-0.6B inference engine fits in 12 KB of assembly: 105 tokens/s on CPU
Source: X: @superalesha. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceX: @superalesha ↗
Editor-in-Chief
Key metric #1On one thread, 8 tokens/s; on 40 threads, 100 tokens/s
Key metric #23,688 lines of NASM assembled into a static ELF without gcc or libc
Key metric #3Prefill (prompt processing) reaches 154 tokens/s on 32 threads

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.

Story

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.

ZK
Zhemal Khamidun — Head of AI at Alpina Digital · MIPT (academic supervisor of the Tech Entrepreneurship department). Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

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.

Try Nomad AI →Launch Nomad Agent
Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Qwen3-0.6B inference engine fits in 12 KB of assembly: 105 tokens/s on CPU https://news.hamidun.com/en/news/18232/qwen3-0-6b-inference-engine-fits-in-12-kb-of-assembly-105-to

What do you think?
Loading comments…