llm.asm brings large language model inference into pure x86-64 NASM assembly, achieving tens-of-kilobinary size while maintaining competitive throughput. The project abandons C, libc, and runtime dependencies entirely, delivering Qwen3-0.6B inference in 14.7 KB, a bare-metal bootable OS in 24.3 KB, and a from-scratch Mini-GPT trainer with live Braille TUI in 32.9 KB. All components run on real hardware without an operating system substrate, positioned "AI where it doesn't belong — bare metal, Ring-1 hypervisors, and Linux kernel eBPF."
Phase 1: Qwen3-0.6B static ELF inference
The first phase delivers a 14.7 KB static ELF binary that decodes and generates tokens from the Qwen3-0.6B model. Benchmarks on an AMD EPYC 7642 CPU show 7.18 tokens per second with a single thread using FAST_Q8=0, scaling to 98.50 tok/s at 40 threads. Compared against llama.cpp's Q8_0 implementation, llm.asm achieves 1.24x speedup at one thread and 1.19x at 24 threads. The implementation uses pure x86-64 NASM with no external dependencies, producing deterministic output across 1 to 40 threads. Two quantization modes exist: FAST_Q8=0 hits 1.000000000 cosine similarity vs Python Q8_0 across 64/64 exact greedy tokens, while FAST_Q8=1 employs an INT8xINT8 AVX2+F16C kernel using vpmaddubsw/vpmaddwd instructions with contiguous head-major KV-cache and parallel GQA.
Phase 2: Bootable bare-metal OS
A 24.3 KB bootable bare-metal operating system demonstrates LLMs running without an OS kernel. Boot times range from 74 to 94 milliseconds. Under QEMU KVM with 16 vCPUs, the system sustains 134.9 tokens per second. On real Proxmox VE hardware with 0 GB disk, throughput reaches 55.4 tok/s. The OS builds using grub-mkrescue for BIOS+UEFI ISOs and qemu-system-x86_64 with KVM enabled. Requires an x86-64 CPU with AVX2 + FMA + F16C, nasm, and GNU binutils.
Phase 3: Mini-GPT Trainer with Braille TUI
The third phase presents a 32.9 KB from-scratch Mini-GPT trainer that includes an 80x24 Braille user interface built entirely in pure assembly. Trained on tinyshakespeare.txt for 400 steps with sequence length 128, the trainer achieves a final validation loss of 1.51 after starting from 4.19. Gradient cosine similarity versus PyTorch registers at 1.0000000000 minimum (3.35e-8 worst maximum difference) across all 21 gradient tensors. The system uses 10-step AdamW with maximum loss difference of 4.77e-7. Live sampling at step 400 generates Shakespearean-style text: "ROMEO: Nay, to lond, in if as my kears, some with death." and "DUKE VINCENTIO: ..." The training loop runs at 25,470 tokens per second.
Phase 4: Ring-1 SVM hypervisor
A 75.4 KB Ring-1 SVM hypervisor serves as a live kernel crash patcher for MiniCPM5-2B, achieving 97.54% pass@1 across 122 unseen scenarios (119/122) versus a 16.39% base rate. The system continues operating with 0% dangerous interventions, performing live Ring-1 #PF /#DE /#UD patching over 24 LAPIC cores. Implementation combines NASM with zero-libc C for the hypervisor layer.
Phase 5: Linux 6.12 eBPF LSM
A 21.3 KB Linux 6.12 eBPF LSM (Loadable Security Module) passes the kernel verifier with 74 instructions out of 5,775/6,035/21,457 insns within the 1M limit, using 0 floats, 0 tail calls. The implementation maintains 500/5000-LSB parity, records 0 false denies across 1,000 tested workflows, and achieves 75% strict-gate recall with 0.947 evasion F1. Live atomic hot-swap functionality enables runtime replacement without service disruption. Targets Linux 6.12 with CONFIG_BPF_LSM=y.
System requirements and repository structure
Requires an x86-64 CPU with AVX2 + FMA + F16C, nasm, and GNU binutils (ld, objcopy). Phase 2 ISOs use grub-mkrescue (grub-pc-bin, grub-efi-amd64-bin, mtools, xorriso) and qemu-system-x86_64 (KVM). Phase 4 requires AMD SVM + NPT (nested=1) and kernel headers; Phase 5 targets Linux 6.12 (CONFIG_BPF_LSM=y). Python with numpy is optional, used only for offline weight export and reference harnesses.
The repository maps a 3,857-line shared NASM core reused across Phases 1–3, with dedicated directories for each phase: 01-qwen3-inference, 02-baremetal-os, 03-minigpt-train, 04-ring1-kernel-surgeon, 05-ebpf-jev, plus scripts, assets, and a Makefile. The project releases under the MIT license, deliberately keeping main focus on zero-bloat x86-64 assembly, bare-metal OSes, hypervisors, and in-kernel ML with hard numerical verification.
git clone https://github.com/alesha-pro/llm.asm.git && cd llm.asm
make all # Builds Phase 1 (asm-llm, test_math), Phase 2 (asm-llm-os.elf), Phase 3 (asm-gpt-train)
- 01 · Qwen3 Inference (14.7 KB): python3 scripts/export_weights.py --model-dir models/qwen3-0.6b-bf16 --out models/qwen3-0.6b-q8_0.asmbin --scale-dtype fp16 && ./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin --chat -t 16
- 02 · Bare-Metal OS (24.3 KB): make os-run MODEL=models/qwen3-0.6b-q8_0.asmbin SMP=16 (or make os-iso for BIOS+UEFI ISO)
- 03 · Mini-GPT Trainer (32.9 KB): ./build/asm-gpt-train --data data/tinyshakespeare.txt --steps 400 --seq 128 -t 16 --save checkpoints/shakespeare.ckpt
- 04 · Ring-1 Kernel Surgeon (75.4 KB): cd 04-ring1-kernel-surgeon && make hv && python3 verifier/kvm_verifier.py --selftest
- 05 · Linux 6.12 eBPF LSM (21.3 KB): cd 05-ebpf-jev && bash testbed/build.sh && testbed/run_vm.sh verify