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 / mojollama-bench-engine

48 lines · 1871 bytes Raw Blame History
1#!/bin/bash
2# mojollama-bench-engine — Real model inference benchmark
3# WHAT: Builds and runs mojollama_engine_bench.mojo with configurable
4# architecture params for any dense LLaMA-style model.
5# Reports thread sweep, component breakdown, batch sweep, memory BW.
6# WHY: Find optimal deployment config for any model on any hardware.
7# WHEN: May 2026 — v1 engine benchmark.
8set -e
9
10MOJO_ENGINE="/onedev-workspace/work/src/mojollama/mojo_engine"
11MODEL_DIR="${MODEL_DIR:-/tmp/tinyllama}"
12
13# Architecture config (override via env for different models)
14NE="${NE:-2048}"; NH="${NH:-32}"; NK="${NK:-4}"
15HD="${HD:-64}"; NL="${NL:-22}"; FF="${FF:-5632}"
16NV="${NV:-32000}"
17
18echo '[DOC] Building engine bench with:'
19echo " NE=$NE NH=$NH NK=$NK HD=$HD NL=$NL FF=$FF NV=$NV"
20echo " Model: $MODEL_DIR"
21
22# Generate Mojo source with overridden comptime constants
23SRC="$MOJO_ENGINE/mojollama_engine_bench.mojo"
24TMP=$(mktemp)
25cp "$SRC" "$TMP"
26
27# Replace comptime constants
28sed -i "s/comptime NE: Int = [0-9]*/comptime NE: Int = $NE/" "$TMP"
29sed -i "s/comptime NH: Int = [0-9]*/comptime NH: Int = $NH/" "$TMP"
30sed -i "s/comptime NK: Int = [0-9]*/comptime NK: Int = $NK/" "$TMP"
31sed -i "s/comptime HD: Int = [0-9]*/comptime HD: Int = $HD/" "$TMP"
32sed -i "s/comptime NL: Int = [0-9]*/comptime NL: Int = $NL/" "$TMP"
33sed -i "s/comptime FF: Int = [0-9]*/comptime FF: Int = $FF/" "$TMP"
34sed -i "s/comptime NV: Int = [0-9]*/comptime NV: Int = $NV/" "$TMP"
35
36# Build
37cp "$TMP" "$MOJO_ENGINE/_bench_custom.mojo"
38cd "$MOJO_ENGINE"
39if mojo build _bench_custom.mojo -o mojollama_engine_bench_custom 2>/dev/null; then
40 echo '[DONE] Build OK. Running benchmark...'
41 timeout 120 ./mojollama_engine_bench_custom 2>/dev/null
42 rm -f _bench_custom.mojo mojollama_engine_bench_custom
43else
44 echo '[ERR] Build failed'
45 rm -f _bench_custom.mojo
46 exit 1
47fi
48rm -f "$TMP"