#!/bin/zsh
set -eu

# 2026-07-24: back on the MTP-preserved uncensored gguf — HauhauCS-Aggressive
# has NO MTP layers (checked: no MTP variant on its HF repo) and cost us
# speculative decoding (24 tok/s flat vs ~30 tok/s on tool-call/JSON output at
# 0.9+ draft acceptance). HauhauCS file kept beside it for rollback.
MODEL=/Users/Shared/models/candidates/qwen3.6-35b-uncensored-1M-MTP-Q4_K_M.gguf
SERVER=/Users/admin/llama.cpp/build/bin/llama-server

/usr/sbin/sysctl iogpu.wired_limit_mb=13312

for _ in {1..120}; do
  [[ -f "$MODEL" ]] && break
  sleep 5
done
[[ -f "$MODEL" ]] || { echo "model missing: $MODEL" >&2; exit 1; }

until /sbin/ifconfig bridge0 | /usr/bin/grep -q 'inet 10.0.0.1'; do sleep 5; done
until /sbin/ping -c 1 -t 2 10.0.0.2 >/dev/null 2>&1; do sleep 5; done
until /usr/bin/nc -z -G 2 10.0.0.2 50052 >/dev/null 2>&1; do sleep 5; done

# Sampler defaults = official Qwen3.6-A3B instruct preset (HF model card);
# presence-penalty 1.5 is the MoE-specific anti-repetition value.
exec "$SERVER" \
  -m $MODEL \
  --rpc 10.0.0.2:50052 \
  -ngl 99 \
  --no-mmap \
  --fit off \
  --tensor-split 40,60 \
  -np 1 \
  -c 32768 \
  -b 2048 \
  -ub 1024 \
  -fa on \
  -ctk q8_0 \
  -ctv q8_0 \
  --metrics \
  --host 0.0.0.0 \
  --port 8080 \
  --jinja \
  --spec-type draft-mtp \
  --spec-draft-n-max 2 \
  --reasoning off \
  --temp 0.7 \
  --top-p 0.8 \
  --top-k 20 \
  --min-p 0.0 \
  --presence-penalty 1.5 \
  --alias qwen3.6-35b-hauhau-aggressive-mtp-q4
# 2026-07-24: alias renamed with the model swap (-mtp suffix) together with the
# chat default, agent route table, and docs — the coordinated rename the
# pool-model contract test requires.
