#!/usr/bin/env bash # Start (or check) local OpenAI-compatible inference servers for the LLM laboratory. # Models are small open-weight instruction models served by mlx_lm on MacLustr nodes. # No credentials involved. Usage: scripts/llm_serve.sh start|status|stop # Laptop access goes through SSH port-forwards (see scripts/llm_tunnel.sh). set -u declare -a SPECS=( "M3U96a 8081 mlx-community/Qwen2.5-7B-Instruct-4bit" "M3U96b 8082 mlx-community/Mistral-7B-Instruct-v0.3-4bit" "M3U96a 8083 mlx-community/Llama-3.2-3B-Instruct-4bit" ) cmd=${1:-status} for spec in "${SPECS[@]}"; do set -- $spec; node=$1; port=$2; model=$3; tag=$(echo "$model" | tr '/' '_') case $cmd in start) ssh -o ConnectTimeout=8 "$node" "mkdir -p ~/age-llm; if curl -s -m 2 localhost:$port/v1/models >/dev/null; then echo '$node:$port already up'; else nohup python3 -m mlx_lm.server --model '$model' --host 0.0.0.0 --port $port --max-tokens 1024 > ~/age-llm/server_$port.log 2>&1 & echo '$node:$port starting $model'; fi";; status) ssh -o ConnectTimeout=8 "$node" "curl -s -m 3 localhost:$port/v1/models | head -c 200; echo; tail -n 2 ~/age-llm/server_$port.log 2>/dev/null";; stop) ssh -o ConnectTimeout=8 "$node" "pkill -f 'mlx_lm.server.*--port $port' && echo '$node:$port stopped'";; esac done