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 / bench_fast.sh

50 lines · 1395 bytes Raw Blame History
1#!/bin/bash
2# Fast benchmark: thread × batch sweep
3set -e
4
5SRC="tinyllama_gen_q8.mojo"
6cd "$(dirname "$0")"
7
8MOJO_LIB="$HOME/.local/share/uv/tools/mojo/lib/python3.11/site-packages/modular/lib"
9NW_VALUES=(1 2 4 8 12 16 24 32)
10B_VALUES=(2 4 8)
11RPW=8
12
13echo "=== Thread × Batch Sweep (Q8_0, RPW=$RPW) ==="
14printf "%-4s %-4s %s\n" "B" "nw" "tok/s"
15printf "%-4s %-4s %s\n" "--" "---" "-----"
16
17for b in "${B_VALUES[@]}"; do
18 # Build for this B
19 cp "$SRC" "${SRC}.bak"
20 sed -i "s/comptime B: Int = [0-9]*/comptime B: Int = $b/" "$SRC"
21 sed -i "s/comptime RPW: Int = [0-9]*/comptime RPW: Int = $RPW/" "$SRC"
22
23 OBJ="${SRC%.mojo}_B${b}.o"
24 BIN="${SRC%.mojo}_B${b}"
25
26 echo "Building B=$b..."
27 mojo build "$SRC" --emit object -o "$OBJ" 2>/dev/null
28 gcc -o "$BIN" "$OBJ" \
29 -L"$MOJO_LIB" \
30 -lKGENCompilerRTShared \
31 -lAsyncRTRuntimeGlobals \
32 -lMSupportGlobals \
33 -lAsyncRTMojoBindings \
34 -lm -lpthread -ldl -lstdc++ 2>/dev/null
35
36 for nw in "${NW_VALUES[@]}"; do
37 out=$(LD_LIBRARY_PATH="$MOJO_LIB" timeout 120 "./$BIN" "$nw" 2>&1 | grep "tok/s" | tail -1)
38 tok_s=$(echo "$out" | grep -oP '\(\s*[\d.]+' | tail -1 | sed 's/(//')
39 printf "%-4s %-4s %s\n" "$b" "$nw" "${tok_s:-ERR}"
40 done
41
42 rm -f "$OBJ" "$BIN"
43 mv "${SRC}.bak" "$SRC"
44done
45
46echo ""
47echo "=== Sequential Baseline (nw=1) ==="
48echo "B=2 nw=1 provides single-stream throughput"
49echo ""
50echo "=== Done ==="