#!/bin/zsh # End-to-end: prompts -> model stats -> A (MLX dense) -> B (ollama GGUF) -> C (MLX MoE) -> D (optional) # -> results.json + plots. No network. ./run.sh --dry-run checks everything except the GPU runs. set -euo pipefail setopt NO_BG_NICE cd "${0:A:h}" START=$(date +%s) BUDGET=${BUDGET_S:-2340} # 39 min hard budget for the whole script PY=${PY:-$(command -v python3)} # MLX / mlx_lm (override: PY=/path/to/python ./run.sh) VPY=${VPY:-$PWD/.venv/bin/python} # same Python + gguf, matplotlib (venv w/ system site-packages) HF=$HOME/.cache/huggingface/hub GGUF=( $HF/models--unsloth--Qwen3.8-27B-GGUF/snapshots/*/Qwen3.8-27B-UD-Q4_K_XL.gguf(N) ) GGUF=${GGUF[1]:?GGUF not found in HF cache} DRY=0; [[ "${1:-}" == "--dry-run" ]] && DRY=1 export HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 MPLCONFIGDIR=$PWD/.mplconfig PYTHONDONTWRITEBYTECODE=1 export OLLAMA_HOST=127.0.0.1:11545 OLLAMA_MODELS=$PWD/ollama_models OLLAMA_FLASH_ATTENTION=1 \ OLLAMA_KV_CACHE_TYPE=f16 OLLAMA_NUM_PARALLEL=1 OLLAMA_MAX_LOADED_MODELS=1 \ OLLAMA_CONTEXT_LENGTH=20480 OLLAMA_KEEP_ALIVE=30m OLLAMA_NOPRUNE=1 mkdir -p raw logs outputs plots rm -f raw/A.json raw/B.json raw/C.json raw/D.json raw/failures.txt at() { echo $(( START + BUDGET * $1 / 100 )); } # deadline at N% of the budget fail() { echo "$1" | tee -a raw/failures.txt; } cooldown() { (( DRY )) || { echo "cooldown 30 s"; sleep 30; } } echo "== env, prompts, model stats" $VPY collect_env.py $VPY make_prompts.py --out prompts $VPY model_stats.py --out raw/model_stats.json if (( DRY )); then for c in A C D; do $PY bench_mlx.py --config $c --dry-run; done $VPY bench_ollama.py --config B --gguf "$GGUF" --dry-run $VPY analyze.py --selftest echo "dry run ok"; exit 0 fi echo "== A: MLX Qwen3.8-27B 4-bit" $PY -u bench_mlx.py --config A --repo mlx-community/Qwen3.8-27B-4bit --deadline $(at 36) \ 2>&1 | tee logs/A.log || fail "A failed (see logs/A.log)" cooldown echo "== B: ollama Qwen3.8-27B UD-Q4_K_XL" # Hard-link the GGUF into ollama's blob store under its sha256 (HF names blobs by sha256), # so registering the model copies nothing. If linking fails, ollama copies the file itself. REAL=${GGUF:A}; mkdir -p ollama_models/blobs ollama_home [[ -e ollama_models/blobs/sha256-${REAL:t} ]] || ln "$REAL" ollama_models/blobs/sha256-${REAL:t} \ || echo "hard link failed; ollama will copy the GGUF" HOME=$PWD/ollama_home ollama serve > logs/ollama_serve.log 2>&1 & OPID=$! trap 'kill $OPID 2>/dev/null || true' EXIT for i in {1..60}; do curl -sf --noproxy '*' http://$OLLAMA_HOST/api/version >/dev/null && break; sleep 1; done if curl -sf --noproxy '*' http://$OLLAMA_HOST/api/version >/dev/null; then $VPY -u bench_ollama.py --config B --gguf "$GGUF" --host $OLLAMA_HOST --deadline $(at 70) \ 2>&1 | tee logs/B.log || fail "B failed (see logs/B.log, logs/ollama_serve.log)" ollama ps > logs/ollama_ps_end.txt 2>&1 || true else fail "B failed: ollama serve did not come up (logs/ollama_serve.log)" fi kill $OPID 2>/dev/null || true; wait $OPID 2>/dev/null || true grep -iE "llama\.cpp|commit|version|flash|kv cache|offload|system info|runner|engine|architecture" logs/ollama_serve.log \ | head -40 > raw/ollama_build_lines.txt || true cooldown echo "== C: MLX Qwen3.6-35B-A3B 4-bit (MoE)" $PY -u bench_mlx.py --config C --repo mlx-community/Qwen3.6-35B-A3B-4bit --deadline $(at 86) \ 2>&1 | tee logs/C.log || fail "C failed (see logs/C.log)" if (( $(date +%s) < $(at 80) )); then cooldown echo "== D: MLX LFM2.5-24B-A2B 4-bit (MoE, optional)" $PY -u bench_mlx.py --config D --repo LiquidAI/LFM2.5-24B-A2B-MLX-4bit \ --deadline $(( START + BUDGET - 90 )) 2>&1 | tee logs/D.log || fail "D failed (see logs/D.log)" else echo "skipping D (time budget)" | tee -a raw/failures.txt fi echo "== analyze" $VPY analyze.py echo "total $(( $(date +%s) - START )) s -> results.json, plots/speed_vs_context.png"