| #!/usr/bin/env bash |
| |
| |
| set -euo pipefail |
| DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| source "$DIR/common.sh" |
|
|
| MODEL="${MODEL:-ibm-granite/granite-4.1-8b}" |
| PORT="${PORT:-8000}" |
| |
| MEM_FRACTION="${MEM_FRACTION:-0.68}" |
| MAX_REQ="${MAX_REQ:-24}" |
| LOG_DIR="${LOG_DIR:-$HOME/agent-logs}" |
| mkdir -p "$LOG_DIR" |
|
|
| ensure_toolchain |
| |
| ensure_sglang_omni |
|
|
| export CUDA_VISIBLE_DEVICES=0 |
|
|
| if ! python3 -c "import sglang" 2>/dev/null; then |
| echo "[llm] FATAL: sglang failed to install/import." |
| exit 1 |
| fi |
|
|
| echo "[llm] launching $MODEL on :$PORT [GPU0 w/ STT, mem $MEM_FRACTION]" |
| |
| |
| |
| python3 -m sglang.launch_server \ |
| --model-path "$MODEL" \ |
| --host 0.0.0.0 \ |
| --port "$PORT" \ |
| --attention-backend flashinfer \ |
| --mem-fraction-static "$MEM_FRACTION" \ |
| --chunked-prefill-size 512 \ |
| --max-running-requests "$MAX_REQ" \ |
| --schedule-policy lpm \ |
| > "$LOG_DIR/llm.log" 2>&1 & |
| LLM_PID=$! |
|
|
| waited=0; max_wait=600 |
| until curl -sf "http://localhost:${PORT}/health" > /dev/null 2>&1; do |
| if [ "$waited" -ge "$max_wait" ]; then |
| echo "[llm] TIMEOUT"; tail -n 30 "$LOG_DIR/llm.log"; exit 1 |
| fi |
| if ! kill -0 "$LLM_PID" 2>/dev/null; then |
| echo "[llm] process died"; tail -n 40 "$LOG_DIR/llm.log"; exit 1 |
| fi |
| sleep 2; waited=$((waited + 2)) |
| done |
|
|
| echo "$LLM_PID" > /tmp/llm.pid |
| echo "[llm] up. pid=$LLM_PID" |
|
|