A 7B-parameter model doesn't need a 2 GB Python environment to emit one token — it needs a matrix-vector product, a softmax, and somewhere to park the KV cache. alesha-pro/llm.asm implements exactly that in hand-written x86-64 NASM, and pulled 4,175 stars in under seven days.

TL;DR: llm.asm is a from-scratch transformer inference engine in pure x86-64 assembly: no Python, no C++ runtime, no BLAS, no libc dependency — just Linux syscalls, mmap'd weights, and AVX2/FMA kernels for attention and FFN. You get a tiny static binary and near-zero cold start. You give up GPU execution, tuned prefill throughput, and portability. Read it as a reference implementation of what inference actually requires, not as a llama.cpp replacement.

The Problem With Current AI Workflows

The pain isn't model quality, it's the dependency substrate. A minimal "just run inference" stack today is Python 3.11 + torch (CUDA-tagged wheel, ~2.5 GB) + transformers + safetensors + tokenizers, and the failure modes are almost never mathematical. They're libcudnn version drift, ABI mismatches between a Rust tokenizer wheel and your glibc, or a container image that takes six minutes to pull before the first token appears.

For edge boxes, CI smoke tests, air-gapped hosts, and serverless cold paths, that overhead dominates. Decode-phase inference for a single sequence is memory-bandwidth bound, not compute bound — you're streaming weights through the memory hierarchy and doing a GEMV per layer. The orchestration layer contributes nothing to that loop, yet it's most of your artifact size and all of your supply-chain surface.

How the Architecture Actually Works

Strip inference to its syscall-level reality and the graph is short:

 argv / stdin (prompt bytes) | v +---------------------------+ | tokenizer: BPE merges | flat sorted tables, binary search | (mmap'd vocab + merges) | -> token id array in .bss buffer +---------------------------+ | v +---------------------------+ weights: one mmap, MAP_PRIVATE | embedding lookup | <-- page-aligned, no malloc, no copy +---------------------------+ | v +==========================================+ | N x transformer block (loop in asm) | | | | RMSNorm -> rsqrt + vfmadd reduction | | | | | Q/K/V GEMV -> AVX2 int8 dot products | | | | | RoPE -> sincos pairs, in-register | | | | | attention: Q.K^T / sqrt(d), mask, | | softmax, .V (KV cache read) | | | | | O proj GEMV | | | | | residual add | | | | | RMSNorm -> SwiGLU FFN (up/gate/down) | | | | | residual add | +==========================================+ | ^ | | KV cache: contiguous per-layer v | [layer][head][pos][dim] arena +---------------------------+ | final norm + lm_head GEMV | +---------------------------+ | v logits -> argmax / temp+top-p -> token id -> write(1, ...) | +---> loop back into block stack until EOS or max_tokens 

Component notes worth stealing:

  • No allocator. Weights are one mmap of the model file; activations and KV cache live in fixed .bss/mmap'd arenas sized at startup from the header. Zero malloc, zero fragmentation, deterministic memory footprint.
  • No libc. open, mmap, write, exit are raw syscall instructions with SysV register conventions. That removes the dynamic linker entirely — the ELF has no INTERP segment.
  • GEMV is the whole game. The inner loop keeps 8–12 ymm accumulators live to hide FMA latency, and does the horizontal reduction once at the end rather than per iteration. For int8 weights the pattern is vpmaddubsw → vpmaddwd → vpaddd, with per-block scales applied on dequant:
; illustrative int8 GEMV inner loop (unrolled x4 in the real kernel) .loop: vmovdqu ymm0, [rsi] ; activations (broadcast/quantized) vpmaddubsw ymm1, ymm0, [rdi] ; int8 * uint8 -> int16 pairs vpmaddwd ymm1, ymm1, [ones] ; int16 pairs -> int32 vpaddd ymm8, ymm8, ymm1 ; accumulate, no horizontal op here add rsi, 32 add rdi, 32 sub rcx, 32 jnz .loop 
  • KV cache layout is a correctness and speed decision. Contiguous [layer][head][pos][dim] means attention scores read sequential memory; a naive [pos][layer] layout thrashes TLB entries at long context.
  • Softmax uses max-subtraction for stability and a polynomial exp approximation — no libm call, no denormal surprises.

Quick Start (Copy-Paste Setup)

Requires Linux x86-64 with AVX2 + FMA (grep -o 'avx2\|fma' /proc/cpuinfo | sort -u). Check the repo README for exact target names — the shape is:

sudo apt-get install -y nasm binutils make git clone https://github.com/alesha-pro/llm.asm.git cd llm.asm make # nasm -f elf64 ... && ld -static -o llm file llm # ELF 64-bit, statically linked, no interpreter ldd ./llm # "not a dynamic executable" <- the point ls -lh llm # tens of KB, not GB # fetch/convert weights per repo docs, then: ./llm --model ./models/model.bin --prompt "Explain KV caching:" --tokens 128 

Sanity-check that the hot loop is what you think it is:

objdump -d llm | grep -c vfmadd # FMA density perf stat -e cycles,instructions,cache-misses ./llm --model ... --tokens 64 

If cache-misses is low and IPC is modest, you're bandwidth-bound — expected for batch-1 decode.

Real-World Use Cases & Honest Trade-Offs

Three concrete wins

  1. Cold start measured in milliseconds. No interpreter init, no CUDA context, no wheel imports. Ideal for per-request serverless inference or CLI tools that must feel instant.
  2. Auditable, reproducible artifact. A static binary with zero shared-library dependencies is trivially diffable across builds and drops into scratch containers or air-gapped hosts without a package manager.
  3. The best teaching artifact for inference internals I've seen this month. You can read the exact instruction sequence for RoPE, RMSNorm, and masked softmax. Nothing is hidden behind a dispatcher or a fused kernel library.

Two honest limitations

  1. Prefill and batching will lose to tuned libraries. Prompt processing is compute-bound GEMM, where cache-blocked, multi-threaded BLAS or GPU kernels win by a wide margin. Hand-written single-thread AVX2 doesn't close that gap, and there's no continuous batching or paged KV management for concurrent serving.
  2. Narrow hardware and model coverage. AVX2-capable x86-64 only — no ARM/NEON, no CUDA, no Metal. Supported architectures and quantization formats are whatever the author hand-implemented; adding a new model family means writing assembly, not editing a config. Maintenance cost per feature is roughly an order of magnitude above C.

Use it to learn, to embed, and to benchmark the floor. Don't migrate your production serving fleet to it.

📡 Daily open-source AI drops
I curate finds like this one in VibeNode AI on Telegram: t.me/vibenode_ai — one repo per day, plus Claude Code hooks and ready-to-import n8n JSON workflows. Search #Drop06 inside the channel for this write-up's companion notes.

Direct Links & Daily Open-Source Drops

Discussion: if batch-1 decode is bandwidth-bound anyway, how much of the modern inference stack is genuinely earning its complexity — and what would you keep if you had to rebuild it from syscalls up?