#!/bin/bash
# Frozen bounded auxiliary experiments. These are NOT 3x256K profiles.
set -euo pipefail
export CUDA_VISIBLE_DEVICES=GPU-f4a988cb-c310-b618-5a9c-4462d4d33add
export CUDA_DEVICE_ORDER=PCI_BUS_ID OMP_NUM_THREADS=8 TOKENIZERS_PARALLELISM=false
export HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1
unset SGLANG_FORCE_FP8_MARLIN SGLANG_FP8_IGNORED_LAYERS
ARGS=(--model-path /home/lab/models/ornith-modular/full-int8-text
 --tokenizer-path /home/lab/models/Ornith-1.5-9B-original
 --served-model-name ornith-sglang --host 127.0.0.1 --port "${ORNITH_PORT:-8130}"
 --quantization compressed-tensors --dtype bfloat16 --context-length 8192
 --max-total-tokens 65536 --mem-fraction-static 0.85 --max-running-requests 3
 --max-mamba-cache-size 18 --chunked-prefill-size 2048
 --attention-backend triton --mamba-backend triton
 --tool-call-parser qwen3_coder --reasoning-parser qwen3
 --cuda-graph-max-bs-decode 3 --cuda-graph-backend-prefill disabled)
case "${1:?profile required}" in
  baseline) ;;
  kv4) ARGS+=(--kv-cache-dtype fp4_mx_block16);;
  mtp4) ARGS+=(--speculative-algorithm NEXTN
    --speculative-draft-model-path /home/lab/models/ornith-modular/original-text
    --speculative-draft-model-quantization unquant --speculative-num-steps 4
    --speculative-eagle-topk 1 --speculative-num-draft-tokens 5);;
  dflash16-bf16|dflash16-int8|dflash16-int4)
    DRAFT=/home/lab/models/ornith-modular/dflash-bf16; DRAFT_QUANT=unquant
    if [[ "$1" == dflash16-int8 ]]; then DRAFT=/home/lab/models/ornith-modular/dflash-mlp-int8; DRAFT_QUANT=compressed-tensors; fi
    if [[ "$1" == dflash16-int4 ]]; then DRAFT=/home/lab/models/ornith-modular/dflash-mlp-int4; DRAFT_QUANT=compressed-tensors; fi
    ARGS+=(--speculative-algorithm DFLASH --speculative-draft-model-path "$DRAFT"
      --speculative-draft-model-quantization "$DRAFT_QUANT" --speculative-dflash-block-size 16
      --speculative-draft-attention-backend triton --speculative-draft-window-size 4096);;
  *) echo 'Unknown frozen auxiliary profile' >&2; exit 2;;
esac
exec /home/lab/venvs/sglang/bin/python -m sglang.launch_server "${ARGS[@]}"
