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 / src / mojollama / mojo_engine / REAL_BENCHMARK_RESULTS.md

113 lines · 4166 bytes Raw Blame History Rendered
1# MojoLlama Real Inference Benchmark Results
2## Date: 2026-05-22
3
4### What Was Built
5
6**Pure Mojo inference pipeline:**
71. **Tokenizer** — vocab.bin loader + token ID → text decoder (strips `▁` space markers)
82. **Weight loader** — reads f16 .bin files via libc syscalls (`open`, `read`, `lseek`)
93. **Forward pass** — RMS Norm, RoPE, GQA attention with KV cache, FFN (SiLU gate + up + down)
104. **Generation loop** — autoregressive, feeds output token back as next input
115. **Benchmark harness** — multiple prompts, measures tok/s per prompt + aggregate
12
13**Files:**
14- `tinyllama_benchmark.mojo` — Universal benchmark harness
15- `tinyllama_gen.mojo` — Single-prompt generation
16- `tl_gen.c` — C reference implementation (for comparison)
17
18---
19
20### Real Benchmark Results (TinyLlama-1.1B f16)
21
22**Hardware:** Threadripper 3970X (32 cores, 4 CCDs)
23
24| Prompt | Tokens | Time (ms) | tok/s |
25|--------|--------|-----------|-------|
26| 2+2= | 10 | 383 | **26.1** |
27| 3*4= | 10 | 344 | **29.0** |
28| Hello, how are you? | 10 | 378 | **26.4** |
29| def fib(n): | 10 | 511 | **19.6** |
30| The capital of France is | 10 | 343 | **29.1** |
31| What is 5+7? | 10 | 343 | **29.2** |
32| 1. First / 2. Second | 10 | 345 | **28.9** |
33| **Aggregate** | **70** | **2650** | **26.4** |
34
35**Comparison: Real vs Synthetic**
36
37| Benchmark Type | tok/s | Notes |
38|----------------|-------|-------|
39| **Real generation (Mojo)** | **26.4** | Full forward pass + KV cache + decode |
40| Real generation (C + OpenMP) | 25.0 | Same algorithm in C |
41| Synthetic matmul only | 103 | Random pool, no forward pass logic |
42| Old `tinyllama_f16.mojo` | 12.2 | Q4_0 weights (buggy, reading packed nibbles as f16) |
43
44---
45
46### Architecture Support Status
47
48| Model | Real Weights | Architecture | Status |
49|-------|-------------|--------------|--------|
50| **TinyLlama-1.1B** | ✅ f16 .bin | Llama (GQA, RoPE, RMS) | **Benchmarked** |
51| Llama-3.2-1B | ❌ | Llama | Needs extraction |
52| Gemma-4-E2B/E4B | ❌ | Gemma (diff FFN) | Needs extraction |
53| GPT-OSS-20B | ❌ | GPT-OSS (MoE) | Needs extraction |
54| Qwen3.5-2B | ❌ | Qwen (SSM+attention) | Needs extraction |
55| ZAYA1-8B | ❌ | Custom | Needs extraction |
56| **ZAYA1-8B** (May 22) | ✅ | ZAYA (MoE+Attn, CCA, top-1 expert) | **Benchmarked: 28.6 tok/s Q8_0** |
57| Qwen3.6-35B | ❌ | Qwen (SSM) | Needs extraction |
58| Qwen3-30B-A3B | ❌ | Qwen (MoE) | Needs extraction |
59| ERNIE-4.5-21B | ❌ | ERNIE | Needs extraction |
60| GLM-4.7-Flash | ❌ | GLM | Needs extraction |
61| TinyStories-33M | ✅ pytorch.bin | GPT-2 (learned pos emb, LayerNorm) | Different arch |
62
63---
64
65### What "Real Numbers" Means
66
67**Real generation includes:**
681. Token embedding lookup (f16→f32 decode)
692. 22 layers of forward pass:
70 - RMS Norm (2× per layer)
71 - Q/K/V projection (3× f16 matmul)
72 - RoPE position encoding
73 - GQA attention with KV cache (stores K/V per position)
74 - Softmax over attention scores
75 - O projection
76 - FFN gate + up + SiLU + down
77 - Residual connections
783. Final RMS Norm + LM head (f16 matmul, 32000×2048)
794. Argmax sampling
805. Token decode (vocab lookup + UTF-8 output)
81
82**Synthetic benchmark was:**
83- Random f16 data in a 512MB pool
84- 7 matmuls per layer, no actual forward pass logic
85- No KV cache, no softmax, no decode
86- Measured only matmul throughput
87
88---
89
90### Next Steps for Other Models
91
92To benchmark other models with real numbers:
93
941. **Extract weights** from GGUF → .bin using `gguf_extract`
952. **Adapt forward pass** for each architecture:
96 - Llama models: same as TinyLlama (different dims)
97 - Gemma: uses GEGLU instead of SiLU gate
98 - GPT-OSS/Qwen MoE: add router + expert selection
99 - Qwen SSM: add Mamba state space layer
1003. **Add encode** — implement BPE tokenizer encode in Mojo (currently pre-computed)
101
102---
103
104### Key Files
105
106| File | Purpose |
107|------|---------|
108| `tinyllama_benchmark.mojo` | Multi-prompt benchmark harness |
109| `tinyllama_gen.mojo` | Single-prompt generation |
110| `zaya_gen_q8.mojo` | **ZAYA1-8B Q8_0 benchmark (NEW!)** |
111| `tl_gen.c` | C reference (verification) |
112| `/tmp/vocab.bin` | 32000-entry decode vocab |
113| `/tmp/vocab_zaya.bin` | 262147-entry ZAYA decode vocab |