Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/mojo_engine/bench_full.sh # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / mojo_engine / bench_full.sh` 92 lines · 2785 bytes Raw Blame History 1 #!/bin/bash 2 # Full benchmark: thread × batch sweep + concurrency test 3 set -e 4 5 SRC="tinyllama_gen_q8.mojo" 6 BASE_DIR="$(dirname "$0")" 7 cd "$BASE_DIR" 8 9 MOJO_LIB="$HOME/.local/share/uv/tools/mojo/lib/python3.11/site-packages/modular/lib" 10 LD_LIBRARY_PATH="$MOJO_LIB" 11 12 NW_VALUES=(1 2 4 8 16 32) 13 B_VALUES=(1 2 4 8) 14 RPW_VALUES=(4 8 16) 15 16 echo "=== Thread × Batch × UBATCH Sweep ===" 17 echo "B,RPW,nw,tok_s" 18 printf "%-4s %-5s %-4s %s\n" "B" "RPW" "nw" "tok/s" 19 echo "---- ---- ---- ------" 20 21 for rpw in "${RPW_VALUES[@]}"; do 22 for b in "${B_VALUES[@]}"; do 23 # Build for this B, RPW 24 cp "$SRC" "${SRC}.bak" 25 sed -i "s/comptime B: Int = [0-9]*/comptime B: Int = $b/" "$SRC" 26 sed -i "s/comptime RPW: Int = [0-9]*/comptime RPW: Int = $rpw/" "$SRC" 27 28 OBJ="${SRC%.mojo}_B${b}_R${rpw}.o" 29 BIN="${SRC%.mojo}_B${b}_R${rpw}" 30 31 mojo build "$SRC" --emit object -o "$OBJ" 2>/dev/null 32 gcc -o "$BIN" "$OBJ" \ 33 -L"$MOJO_LIB" \ 34 -lKGENCompilerRTShared \ 35 -lAsyncRTRuntimeGlobals \ 36 -lMSupportGlobals \ 37 -lAsyncRTMojoBindings \ 38 -lm -lpthread -ldl -lstdc++ 2>/dev/null 39 40 for nw in "${NW_VALUES[@]}"; do 41 # Run 3 times, take median 42 results=() 43 for trial in 1 2 3; do 44 out=$(LD_LIBRARY_PATH="$MOJO_LIB" timeout 90 "./$BIN" "$nw" 2>&1 | grep "tok/s" | tail -1) 45 tok_s=$(echo "$out" | grep -oP '\(\s*[\d.]+' | tail -1 | sed 's/(//') 46 if [ -n "$tok_s" ]; then 47 results+=("$tok_s") 48 fi 49 done 50 if [ ${#results[@]} -ge 1 ]; then 51 IFS=$'\n' sorted=($(sort -n <<< "${results[*]}")); unset IFS 52 mid=$(( ${#sorted[@]} / 2 )) 53 median="${sorted[$mid]}" 54 printf "%-4s %-5s %-4s %s\n" "$b" "$rpw" "$nw" "$median" 55 fi 56 done 57 58 rm -f "$OBJ" "$BIN" 59 mv "${SRC}.bak" "$SRC" 60 done 61 done 62 63 echo "" 64 echo "=== Concurrency Test (B=4, nw=16, 2 instances) ===" 65 echo "Building baseline..." 66 cp "$SRC" "${SRC}.bak" 67 sed -i "s/comptime B: Int = [0-9]*/comptime B: Int = 4/" "$SRC" 68 sed -i "s/comptime RPW: Int = [0-9]*/comptime RPW: Int = 8/" "$SRC" 69 mojo build "$SRC" --emit object -o tinyllama_q8_conc.o 2>/dev/null 70 gcc -o tinyllama_q8_conc tinyllama_q8_conc.o \ 71 -L"$MOJO_LIB" \ 72 -lKGENCompilerRTShared \ 73 -lAsyncRTRuntimeGlobals \ 74 -lMSupportGlobals \ 75 -lAsyncRTMojoBindings \ 76 -lm -lpthread -ldl -lstdc++ 2>/dev/null 77 78 echo "Single instance (baseline):" 79 LD_LIBRARY_PATH="$MOJO_LIB" timeout 90 ./tinyllama_q8_conc 16 2>&1 | grep "tok/s" 80 81 echo "Two concurrent instances:" 82 LD_LIBRARY_PATH="$MOJO_LIB" timeout 90 ./tinyllama_q8_conc 8 & 83 PID1=$! 84 LD_LIBRARY_PATH="$MOJO_LIB" timeout 90 ./tinyllama_q8_conc 8 & 85 PID2=$! 86 wait $PID1 $PID2 87 # Print results 88 echo "Concurrent results:" 89 90 mv "${SRC}.bak" "$SRC" 91 rm -f tinyllama_q8_conc.o tinyllama_q8_conc 92 echo "=== Done ==="