interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / README.md

185 lines · 10357 bytes Raw Blame History Source

MojoLlama

Archived 2026-10-15: AIEN dropped Mojo/MAX. Read-only history; the eval runners live on in aien-dev/aien-yardsticks (yardsticks/mojollama-eval-runners).

<p align="center"> <img src="www/logo.png" alt="MojoLlama Logo" width="200"> </p>

High‑throughput CPU LLM inference engine: GGUF native, MoE-optimized, with a pure Mojo inference pipeline and full Studio suite.

Mojo Python C GGUF License


✨ Overview

MojoLlama is a CPU-first inference engine that provides two engines for different needs:

1. Pure Mojo Engine (NEW)

A zero-C, zero-Python inference pipeline written entirely in Mojo. Uses Mojo's SIMD + parallelize for all compute kernels with C libc imports only for I/O (malloc, open, read). Features:

2. C Engine (Performance)

The C engine (src/mojollama/kernels/cengine_batch_instr.c) provides AVX2+OMP-accelerated operations. The numbers below were measured through the Python TurboEngine, which calls these C kernels:


🚀 Pure Mojo Quick Start

cd src/mojollama/mojo_engine

# Build and run ZAYA1-8B Q8_0 (28.6 tok/s); the argument is the worker thread count (default 32)
bash build_zaya.sh
LD_LIBRARY_PATH="$HOME/.local/share/uv/tools/mojo/lib/python3.11/site-packages/modular/lib" ./zaya_gen_q8 32

# Build TinyLlama-1.1B Q8_0 with a batch of 4 (88.1 tok/s)
bash build_q8.sh

Requirements, from the scripts in src/mojollama/mojo_engine/:

The matmul kernels are pure Mojo (no C bridge); zaya_gen_q8.mojo imports malloc, open, read, lseek and close from libc. See zaya_gen_q8.mojo (~700 lines) for the complete reference implementation. The model-extraction steps are Python scripts.


🏆 Performance Benchmarks

ModelEngineConfigtok/svs llama.cpp
TinyLlama 1.1B f16Pure Mojo1 sequence × 32 thr27.2-
TinyLlama 1.1B f16Pure MojoB=4 × 32 thr77.8-
TinyLlama 1.1B Q8_0Pure MojoB=4 × 32 thr88.1-
ZAYA1-8B Q8_0Pure Mojo80L, 16 experts, top-128.6 🏆-
GPT-OSS-20B Q4_K_MPython TurboEngine1 user25.50.94×
Qwen3.6-35B MXFP4Python TurboEngine1 user25.51.57×
Qwen3.6-35B MXFP4C batch_forwardB=10 × 128 prompt17.01.06×
Qwen3.6-35B MXFP4Concurrent server (spawn)10 workers × 3 thr47.0 agg-
TinyLlama 1.1B Q4_0Python TurboEngine1 user79.20.89×
Qwen3-30B-A3B Q4_K_MPython TurboEngine1 user22.50.89×

Notes on these numbers. Hardware is an AMD Threadripper 3970X (32 cores, 251 GB DDR4), 32 threads unless noted (src/mojollama/README.md). The 27.2 tok/s TinyLlama f16 row is the aggregate over 7 prompts of 10 generated tokens each. The Pure Mojo rows are recorded in SUMMARY.md, src/mojollama/mojo_engine/TINYLLAMA_QUANT_BENCHMARK.md and src/mojollama/mojo_engine/REAL_BENCHMARK_RESULTS.md. The TinyLlama Q4_0, GPT-OSS, Qwen3.6 TurboEngine and 47 aggregate concurrent figures match src/mojollama/README.md. No other file in the repository supports the Qwen3.6 C batch_forward row (17.0), the Qwen3-30B-A3B row (22.5, 0.89×), or the 10 × 1 and 8 × 4 concurrent rows; treat those as unverified. Later records disagree with some rows. FINAL_STATUS.md and .hermes/debug-logs/2026-05-22_mojollama-opt-session.md (22 May 2026) give GPT-OSS-20B Q4_K_M at 23.6 tok/s (0.86× llama.cpp) and Qwen3-30B Q4_K_M at 22.6 tok/s (0.81×), and list the C batch forward as not working (segfault on Qwen3.6, and a first-token mismatch with the Python path). Re-measure before relying on the TurboEngine and C batch_forward figures.

Pure Mojo Details

FileModelFormattok/sLines
tinyllama_benchmark.mojoTinyLlama-1.1Bf1627.2488
tinyllama_gen_q8.mojoTinyLlama-1.1BQ8_0 B=488.1552
zaya_gen_q8.mojoZAYA1-8BQ8_028.6~700

Architecture support (pure Mojo):


🧠 C Engine (src/mojollama/kernels/cengine_batch_instr.c)

The C engine is the core performance layer: a single .c file (~1,900 lines) with AVX2+OMP-accelerated operations:

Quantized Matmul Types: | Type | Block Size | Operations | |------|-----------|------------| | Q4_0 | 32 elems | 4-bit, 18B/block, symmetric | | Q4_K | 256 elems | K-quant 4-bit, 144B/block | | Q5_K | 256 elems | K-quant 5-bit, 176B/block | | Q6_K | 256 elems | K-quant 6-bit, 210B/block | | Q8_0 | 32 elems | 8-bit, 34B/block | | MXFP4 | 32 elems | 4-bit two's complement + E8M0 scale |

Key Components:


🔧 TurboEngine v7-MoE (src/mojollama/kernels/turbo_engine_v7_moe.py)

Zero-allocation Python engine with C-accelerated MoE support:

Architecture Support:


🔄 Concurrent Server

Two approaches for multi-user throughput:

Multiprocessing spawn (best)

src/mojollama/benchmarks/server_concurrent_qwen36.py: workers share weight pages via OS page cache:

Workers × OMP thrPer-workerAggregateCPU util
10 × 13.6 t/s36 t/s10/32 cores
10 × 34.7 t/s47 t/s 🏆30/32 threads
8 × 45.7 t/s46 t/s32/32 threads

🗺️ Future Plans

Status below is from the code in this repository.

Near-term

Medium-term

Long-term


📚 Project Structure

src/mojollama/
├── mojo_engine/             # Pure Mojo inference engines
│   ├── zaya_gen_q8.mojo     ZAYA1-8B Q8_0 (28.6 tok/s)
│   ├── tinyllama_benchmark.mojo  TinyLlama-1.1B f16
│   ├── tinyllama_gen_q8.mojo     TinyLlama-1.1B Q8_0 B=4
│   ├── extract_zaya_q8.py        GGUF→raw Q8_0 .bin
│   ├── extract_zaya_vocab.py     262K vocab extraction
│   └── build_zaya.sh             Build script
├── kernels/                 # C + Python engines
│   ├── cengine_batch_instr.c     C engine (~1,900 lines)
│   ├── turbo_engine_v7_moe.py    Python MoE engine
│   └── zaya_batch_forward.c      ZAYA C reference
├── server.py                API server
├── benchmarks/server_moe.py       MoE server used by the benchmarks
├── studio.py                CLI Studio (27 commands)
└── model/architectures.py   50+ arch detection

📄 License

Apache 2.0