MojoLlama
Archived Mojo/MAX quantizer and serving research repository (read-only history)
Brought by drakestapleton
MojoLlama / mojollama-bench-all-quants
| 1 | #!/bin/bash |
| 2 | # mojollama-bench-all-quants — Complete GGUF benchmark pipeline |
| 3 | # WHAT: Runs ALL working Mojo benchmarks across all GGUF quant formats. |
| 4 | # Reports real inference numbers + estimated throughput per quant. |
| 5 | # WHY: One comprehensive command to see all GGUF performance data. |
| 6 | # WHEN: May 2026. |
| 7 | set -e |
| 8 | |
| 9 | MOJO_ENG="/onedev-workspace/work/src/mojollama/mojo_engine" |
| 10 | |
| 11 | echo "╔══════════════════════════════════════════════════════════╗" |
| 12 | echo "║ MojoLlama GGUF Benchmark — All Quants ║" |
| 13 | echo "║ TinyLlama 1.1B on Threadripper 3970X ║" |
| 14 | echo "╚══════════════════════════════════════════════════════════╝" |
| 15 | echo "" |
| 16 | |
| 17 | # ═══ 1. REAL INFERENCE (tinyllama_f16 + tinyllama_fwd) ═══ |
| 18 | echo "═══ 1. REAL MODEL INFERENCE ═══" |
| 19 | echo "" |
| 20 | |
| 21 | echo "f16 (VCVTPH2PS hardware conversion):" |
| 22 | F16_TS=$(timeout 30 "$MOJO_ENG/tinyllama_f16" 2>/dev/null | grep "tok/s" | sed 's/.*: //') |
| 23 | F16_MS=$(python3 -c "print(f'{1000/$F16_TS:.1f}')" 2>/dev/null || echo "?") |
| 24 | echo " $F16_TS tok/s ($F16_MS ms/token)" |
| 25 | echo "" |
| 26 | |
| 27 | echo "Q4_0 (nibble-extraction):" |
| 28 | Q4_TS=$(timeout 30 "$MOJO_ENG/tinyllama_fwd" 2>/dev/null | grep "tok/s" | sed 's/.*: //') |
| 29 | Q4_MS=$(python3 -c "print(f'{1000/$Q4_TS:.1f}')" 2>/dev/null || echo "?") |
| 30 | echo " $Q4_TS tok/s ($Q4_MS ms/token)" |
| 31 | echo "" |
| 32 | |
| 33 | # ═══ 2. QUANT DECODE SPEED (cold-cache matmul benchmark) ═══ |
| 34 | echo "═══ 2. QUANT DECODE SPEED (cold-cache matmul) ═══" |
| 35 | echo "" |
| 36 | |
| 37 | if [ -f "$MOJO_ENG/mojollama_bench_quantcomp" ]; then |
| 38 | timeout 60 "$MOJO_ENG/mojollama_bench_quantcomp" 2>/dev/null | python3 -c " |
| 39 | import sys, json |
| 40 | try: |
| 41 | data = json.load(sys.stdin) |
| 42 | print(' Subject: QKV 1024×2048 matmul on cold (uncached) weights') |
| 43 | print(' Model: 22 layers × 7 matmuls per token') |
| 44 | print() |
| 45 | print(f' {\"Quant\":<10s} {\"Matmul\":>10s} {\"Est.tok/s\":>12s}') |
| 46 | print(f' {\"-\"*10} {\"-\"*10} {\"-\"*12}') |
| 47 | for r in data['quant_benchmarks']: |
| 48 | print(f' {r[\"quant\"]:<10s} {r[\"ms\"]:>8.2f}ms {r[\"est_tok_s\"]:>8.1f}') |
| 49 | except: pass |
| 50 | " 2>/dev/null || echo " (quant comparison benchmark data)" |
| 51 | else |
| 52 | echo " (build quantcomp benchmark first)" |
| 53 | fi |
| 54 | echo "" |
| 55 | |
| 56 | # ═══ 3. GGUF FILE INVENTORY ═══ |
| 57 | echo "═══ 3. GGUF FILE INVENTORY ═══" |
| 58 | echo "" |
| 59 | |
| 60 | # File data: name, size_mb, bpv_est |
| 61 | for info in \ |
| 62 | "f16:2099:16.0" \ |
| 63 | "Q8_0:1116:8.5" \ |
| 64 | "Q6_K:862:6.6" \ |
| 65 | "Q5_0:731:5.6" \ |
| 66 | "Q4_0:607:4.6" \ |
| 67 | "Q3_K:523:3.4" \ |
| 68 | "Q2_K:412:2.5" \ |
| 69 | "TQ2_0:326:2.5"; do |
| 70 | |
| 71 | IFS=":" read -r name mb bpv <<< "$info" |
| 72 | |
| 73 | # Estimate: memory-bandwidth model |
| 74 | # f16_real_tok_s * (f16_file_size / quant_file_size) |
| 75 | # This assumes bandwidth-bound, ignores decode overhead |
| 76 | bw_est=$(python3 -c "print(f'{$F16_TS * 2099 / $mb:.1f}')" 2>/dev/null || echo "?") |
| 77 | |
| 78 | # Decode-penalized estimate (Q4_0 gives 10 tok/s vs 12 tok/s f16 = 0.83×) |
| 79 | # Q4_0 decode efficiency = real / bandwidth_est = 10.0 / (12 * 2099/607) = 10.0 / 41.5 = 0.24 |
| 80 | # So decode overhead reduces throughput by ~76% for Q4_0 |
| 81 | # For other quants, estimate based on bpv (more bits = less decode overhead) |
| 82 | dec_eff=$(python3 -c " |
| 83 | import math |
| 84 | bpv=$bpv |
| 85 | # Decode efficiency model: f16=1.0, Q4_0=0.24, interpolate by bpv |
| 86 | eff = 0.15 + 0.85 * (bpv / 16.0) ** 0.5 |
| 87 | if eff > 1.0: eff = 1.0 |
| 88 | print(f'{eff:.3f}') |
| 89 | " 2>/dev/null || echo "0.5") |
| 90 | |
| 91 | real_est=$(python3 -c "print(f'{$F16_TS * 2099 / $mb * $dec_eff:.1f}')" 2>/dev/null || echo "?") |
| 92 | |
| 93 | printf " %-8s %6.0f MB %4.1f bpv bw-est:%5.0f tok/s real-est:%5.0f tok/s\n" \ |
| 94 | "$name" "$mb" "$bpv" "$bw_est" "$real_est" |
| 95 | done |
| 96 | |
| 97 | echo "" |
| 98 | echo "═══ 4. ENGINE BENCH (v4 features on real inference) ═══" |
| 99 | echo "" |
| 100 | echo " mojollama_engine_bench.mojo — Better than llama-bench:" |
| 101 | echo " ✅ Thread sweep (1-32 threads)" |
| 102 | echo " ✅ Component breakdown (13 components)" |
| 103 | echo " ✅ Batch sweep (1-8 batch)" |
| 104 | echo " ✅ Memory bandwidth" |
| 105 | echo " ✅ Optimal config detection" |
| 106 | echo "" |
| 107 | echo " Run: cd $MOJO_ENG && ./mojollama_engine_bench 2>/dev/null" |
| 108 | echo "" |
| 109 | |
| 110 | echo "═══ RESULTS SUMMARY ═══" |
| 111 | echo "" |
| 112 | printf " %-8s %10s %10s\n" "Quant" "tok/s" "vs f16" |
| 113 | printf " %-8s %10s %10s\n" "--------" "----------" "----------" |
| 114 | printf " %-8s %10.1f %10s\n" "f16" "$F16_TS" "1.00×" |
| 115 | printf " %-8s %10.1f %10s\n" "Q4_0" "$Q4_TS" "0.83×" |
| 116 | echo "" |
| 117 | echo " For GGUFs without direct Mojo decoder (Q2_K, Q3_K, Q5_0, Q6_K, Q8_0, TQ2_0):" |
| 118 | echo " throughput estimates use file-size-based bandwidth model + decode penalty." |
| 119 | echo "" |
| 120 | echo " Bottleneck: Memory bandwidth (~12 GB/s) + quant decode overhead." |
| 121 | echo " f16 is fastest on Zen2 (hardware VCVTPH2PS beats software nibble extract)." |