Tiny assembly LLM runs without Linux or libraries

A translucent circuit board shaped like a brain, floating inside a vintage steel vault with no power cables, lit by faint green pulses moving along hand-etched pathways

A single developer has released a suite of three fully functional large language model (LLM) implementations — inference, training, and a bootable OS — all written in 100% pure x86-64 NASM assembly. The project, hosted at alesha-pro/llm.asm, contains no C, C++, Rust, or runtime libraries. Total binary sizes range from 14.7 KB to 32.9 KB. Each component runs with zero dependencies: no libc, no libm, no Python, and no operating system beyond raw Linux syscalls or bare-metal firmware.

The work includes Qwen3-0.6B inference (14.7 KB), a bootable bare-metal OS embedding that model (24.3 KB), and a full Mini-GPT trainer with live Braille interface (32.9 KB). All are built using only nasm and ld. The entire codebase spans 17,252 lines of assembly, with shared modules for math kernels, tokenization, and transformer logic reused across components.

Inference beats llama.cpp on CPU

The inference engine (01-qwen3-inference) runs Qwen3-0.6B with quantized weights (Q8_0) and achieves between 20.7 tokens/s (1 thread) and 126.8 tokens/s (40 threads) on an AMD EPYC 7642. This is 18% to 36% faster than llama.cpp under the same CPU-only conditions (-ngl 0), despite llama.cpp using batched GEMM while llm.asm uses token-by-token GEMV. The speed comes from hand-tuned AVX2+FMA+F16C kernels, INT8xINT8 multiplication via vpmaddubsw, FP16 block scaling, and a parallel grouped-query attention (GQA) implementation. Outputs are bit-exact across thread counts, verified against PyTorch FP32 with 0.99965 cosine similarity and 64/64 exact greedy tokens.

Bare-metal OS boots in 74 ms, runs without disk

The second project (02-baremetal-os) is a bootable OS that loads directly via Multiboot 1, transitions to long mode, enables AVX2, and initializes SMP using ACPI/APIC. It supports VGA text output, PS/2 keyboard input, and COM1 serial — all in 24.3 KB. It boots in 74–94 ms, runs on KVM or Proxmox VE, and operates with 0 GB disk. On real hardware (Xeon E5-2670 v3), it delivers 55.4 tokens/s. Performance gains over Linux come from 2 MiB huge-page identity mapping, eliminating page table overhead. The system runs an interactive chat with KV-cache persistence, commands like /clear and /bench, and is byte-for-byte identical to the Linux version.

Training from scratch in 32 KB

The third component (03-minigpt-train) is a full FP32 Mini-GPT trainer with analytical backward pass and decoupled AdamW optimisation. It achieves 27,662 training tokens per second and matches PyTorch gradients exactly (cosine 1.0000000000 across all 21 gradient tensors). Training on TinyShakespeare, it reduces val_loss from 4.19 to 1.51 in under four minutes. A live 80×24 Braille TUI displays loss curves and samples in real time, using ANSI escape sequences and Unicode Braille patterns for smooth updates without flicker.

What it means

This project demonstrates that extreme efficiency and full control are possible even in AI workloads, traditionally dominated by heavy frameworks. For businesses, it underscores the value of minimising software stack depth — reducing attack surface, latency, and dependency risk. While not scalable to billion-parameter models on consumer hardware, it sets a benchmark for low-level optimisation in latency-sensitive or air-gapped environments. UK and UAE firms operating in high-assurance sectors (defence, finance) could benefit from such minimalism. Kazakhstani developers, building sovereign AI tools, may find inspiration in the full transparency and auditability of pure assembly.

The reliance on x86-64 with AVX2/FMA/F16C limits deployment to Haswell-era Intel or Excavator-era AMD and newer. No GPU support exists. Still, the work proves that deterministic, library-free LLM execution is viable today — a rare example of engineering purity meeting practical performance.

Sources

Leave a Reply

Your email address will not be published. Required fields are marked *