Find your next open-source project

Search by name, purpose, or keyword — or paste a GitHub repository URL

alesha-pro/llm.asm

Machine Learning

Pure x86-64 assembly Qwen3-0.6B inference, a bootable bare-metal LLM OS, and a Mini-GPT trainer.

172
29
Assembly
MIT
new today

Overview

llm.asm is a set of three small, dependency-free LLM programs written entirely in x86-64 NASM assembly. There is no C, C++, Rust, libc, or libm: each binary is assembled with nasm, linked with ld, and runs as a static Linux ELF or a bare-metal image. The project is aimed at people interested in low-level SIMD optimization, transformer implementation details, and OS development rather than at users who just want a familiar Python LLM stack.

The three parts are:

  • Qwen3-0.6B inference (01-qwen3-inference): a 14 KB static Linux binary that loads a Q8_0 .asmbin export of Qwen3-0.6B and supports single-shot prompts plus a multi-turn --chat KV-cache REPL. It includes a hand-written BPE tokenizer, RMSNorm, RoPE, SwiGLU, softmax, and an AVX2+FMA+F16C GEMV/GEMM engine.
  • Bare-metal OS (02-baremetal-os): a 24 KB bootable Multiboot kernel that brings up long mode, AVX2/FMA/F16C, ACPI/APIC SMP, VGA text output, PS/2 keyboard, and COM1, then chats with the same model without Linux or Windows.
  • Mini-GPT trainer (03-minigpt-train): a 32 KB FP32 trainer and sampler with a register-blocked AVX2+FMA SGEMM, analytical backward pass, AdamW, and a live 80x24 Unicode Braille TUI.

The shared shared/ directory holds the assembly math, matmul, tokenizer, thread pool, and transformer core reused across phases; the bare-metal build swaps Linux syscalls for Multiboot memory and APIC barriers. Numerical parity is checked against PyTorch and NumPy references through the scripts/ verification harnesses.

Quick Start

Prerequisites: an x86-64 CPU with AVX2, FMA, and F16C (Haswell / Excavator or newer), nasm, GNU binutils, and make. Install the build tools on Debian/Ubuntu with sudo apt install nasm binutils.

Build all three parts:

git clone https://github.com/alesha-pro/llm.asm.git
cd llm.asm
make all

For inference, first export the Qwen3-0.6B weights into the compact .asmbin format. This offline step needs Python and the original model directory:

python3 scripts/export_weights.py --model-dir models/qwen3-0.6b-bf16 --out models/qwen3-0.6b-q8_0.asmbin --scale-dtype fp16
make inference FAST_Q8=1
./build/asm-llm -m models/qwen3-0.6b-q8_0.asmbin -p "Explain how a CPU cache works in 3 concise sentences." -n 128 -t 16

For a multi-turn session, replace the prompt flags with --chat -t 16. The FAST_Q8=1 build uses INT8xINT8 AVX2 kernels and parallel GQA attention; FAST_Q8=0 keeps FP32 activations. Full model download and CLI flag details are in the inference README.

For the bare-metal OS, build and launch it under QEMU with KVM:

make os FAST_Q8=1
make os-run MODEL=models/qwen3-0.6b-q8_0.asmbin SMP=16

make os-iso MODEL=... produces a bootable BIOS+UEFI ISO for QEMU or Proxmox VE; the bare-metal README covers deployment.

For training, download TinyShakespeare, then train the Mini-GPT and save a checkpoint:

mkdir -p data checkpoints && curl -fsSL https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt -o data/tinyshakespeare.txt
make train
./build/asm-gpt-train --data data/tinyshakespeare.txt --steps 400 --seq 128 -t 16 --save checkpoints/shakespeare.ckpt

The training README documents the checkpoint chat loop and the PyTorch gradient check. Python is only needed for the one-time weight export and reference verification, not for training or running the assembly binaries.

Constraints

  • The hardware baseline is strict: AVX2+FMA+F16C is required. Older x86-64 CPUs and non-x86 platforms are not supported.
  • The inference and training binaries are Linux static ELFs; the bare-metal image needs QEMU with KVM, another x86-64 hypervisor, or a real machine. The optional ISO path adds grub-mkrescue, grub-pc-bin, grub-efi-amd64-bin, mtools, and xorriso.
  • Qwen3-0.6B weights are not bundled in the repository. You must obtain the source model and run the Python export script yourself, so the included assembly footprint does not include the model file.
  • Numerical parity is documented against PyTorch FP32 and NumPy references, but the performance numbers in the README come from specific machines (EPYC 7642 for the head-to-head, Xeon E5-2670 v3 for the Proxmox run) and specific model exports; reproducing them depends on your CPU and environment.
  • The project is MIT-licensed. Treat the benchmarks as author-reported measurements rather than independently certified results.

HotRepo's take

The repository was first recorded on HotRepo's new-project board on 2026-11-25 and gained 151 stars and 26 forks during that opening observation window; no all-language daily rank is recorded for it. That volume of early attention is notable for deep systems content, where the usual appeal is a runnable layer rather than a tutorial. The distinguishing claim is concrete: one shared pure-assembly core powers both a Linux ELF and a bootable bare-metal image, and the repository ships verification scripts for math kernels, token-exact OS parity, and per-tensor training gradients. Those checks make the performance and parity claims inspectable; they do not substitute for independent benchmarking on your own hardware.

Written by AI from the project's public information and HotRepo's records, updated . The project's own docs are the source of truth.

Hacker News

Bare Metal Qwen
▲ 3 · 0 comments · November 25, 2026

You might also like

  1. stubbi/asmA package registry and CLI for building, sharing, and verifying assembly projects across x86-64, ARM64, and RISC-V targets.Assembly179
  2. dsx-ai-factory/nvkeA management plane for platform teams to build and run managed Kubernetes clusters on their own NVIDIA GPU bare-metal infrastructure.Go73