DEV Community

Cover image for Run AI in Pure Assembly - llm.asm Open Source
GitHubOpenSource
GitHubOpenSource

Posted on Edited on

Run AI in Pure Assembly - llm.asm Open Source

TL;DR: This repository implements complete machine learning workflows directly in x86-64 assembly language using NASM. It bypasses conventional runtimes, C libraries, and interpreters by implementing custom AVX2 kernels, tokenizers, thread pools, and training logic from scratch.
Best for: Systems programmers and low-level engineers interested in bare-metal architecture and custom assembly optimization.
Repository snapshot: ⭐ 2 225 stars · 🍴 338 forks · Assembly · MIT
Daily picks: Follow GitHub Open Source on Telegram


What it is

llm.asm is an open-source repository written entirely in 100% pure x86-64 NASM assembly. It implements complete machine learning workflows—including Qwen3-0.6B inference, a bare-metal bootable OS, and a Mini-GPT training loop—without relying on C, libc, or any external dependencies.

How it works

Traditional machine learning stacks rely on heavy runtimes, Python, and C/C++ libraries. This project bypasses all conventional layers by implementing custom AVX2, FMA, and F16C accelerated GEMM/GEMV math kernels, tokenizers, thread pools, and training logic directly from scratch. The code compiles down to tiny static binaries that run on Linux or boot straight onto bare metal.

Key features

  • Assemble a Qwen3-0.6B inference engine in a 14 KB static Linux ELF binary
  • Boot a 24 KB bare-metal OS running Qwen3-0.6B with zero disk requirements
  • Train a Mini-GPT model from scratch with a live 80x24 Braille TUI in a 32 KB binary
  • Execute hardware-accelerated math kernels without external libraries
  • Run multi-turn chat sessions utilizing a custom contiguous head-major KV cache

Getting started

Clone the repository and use NASM to assemble the binaries:

git clone https://github.com/alesha-pro/llm.asm.git
cd llm.asm
# Follow Makefile instructions for your target binary
Enter fullscreen mode Exit fullscreen mode

When not to use it

This project is an extraordinary tour de force for systems hackers and assembly enthusiasts, but it is obviously impractical for standard production application development.


Discuss

Would you ever drop down to assembly to optimize model inference speed?

Curated from the repository README and metadata. No hands-on test is claimed; evaluate it in a sandbox before production use.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

A 14 KB static binary running Qwen3-0.6B inference is the number that stops me — but the weights for a 0.6B model are hundreds of megabytes, so the 14 KB has to be the engine alone, with weights loaded separately. What the post doesn't give is the one measurement that decides whether this is a stunt or a tool: tokens per second, on what CPU. Do you have a throughput figure for the 24 KB bare-metal OS version, and how does that custom contiguous head-major KV cache hold up as context grows?