# vllm stack tunables. Copy this to `.env` on the server before deploying.
#
#   cp .env.example .env
#   # edit .env with real values
#   docker compose up -d

# Image version — PINNED. Do not put `latest` here: every service in this file
# shares this one variable, so a bare `docker compose up -d` would silently
# upgrade the whole stack's vLLM at once. Pinned 2026-08-20 to the version all
# seats were already running (`latest` and `v0.24.0` were the same local image,
# 4091d5593f77, so the pin changed nothing at runtime). Bump deliberately.
VLLM_VERSION=v0.24.0

# Host ports (container always listens on 8000 internally)
EMBED_PORT=8001
# 8013 — the reranker moved here 2026-08-20 when bge-v2-m3 (the R43 winner, which
# had been running as a throwaway `docker run` on this port) was promoted into
# this stack and the Qwen incumbent on :8002 was retired.
RERANK_PORT=8013
REWARD_PORT=8003

# GPU assignment — all services share this GPU
# (ana-ml2 has 0 and 1; default 1 keeps 0 free for heavy LLM work in llama-swap)
GPU_ID=1

# Models — reference by full repo name in API requests
EMBED_MODEL=Qwen/Qwen3-Embedding-0.6B
# bge-reranker-v2-m3 — the R43 bake-off winner, replacing Qwen3-Reranker-0.6B
# (measured HARMING 80/90 fleet queries). Multilingual cross-encoder; needs no
# --hf-overrides, unlike the Qwen reranker it displaced.
RERANK_MODEL=BAAI/bge-reranker-v2-m3
# Skywork is a local-path AWQ output, not from HF Hub. Bind-mounted into the
# reward container at /local-models — see compose.yaml. No env var here for
# the model path itself since it's hard-coded in the compose command.

# GPU memory split — fractions are of TOTAL GPU memory, not free memory.
# vLLM profiles each service independently, so each slice must be large enough
# to fit that service's model + KV cache with no awareness of the others.
# Setting any one too low causes that container to OOM on KV cache allocation
# with `Available KV cache memory: -X.XX GiB`.
#
# Layout on a 48 GB Ada, RIGHT-SIZED 2026-06-05 to free room for the granite
# summarizer's CUDA graphs + a LoRA hedge. The trio was wildly over-provisioned:
# embed ran a 5.89x KV pool, reward 3.90x — pure waste for utility models that
# need ~1.5x. Trimmed to free ~10 GB. (Utilization = fraction of TOTAL GPU mem;
# each service profiles independently. Too low → that container OOMs on KV with
# `Available KV cache memory: -X.XX GiB`.)
#   EMBED  0.07  (~3.4 GB) — 0.6B Qwen3 embed @8k; 1.1GB weights + ~2GB KV (~3x)
#   RERANK 0.07  (~3.4 GB) — 0.6B Qwen3 rerank @8k; comfortable
#   REWARD 0.18  (~8.6 GB) — 8B Skywork AWQ @16k; 4.4GB weights + ~3.5GB KV (~1.5x)
#
# RETUNED 2026-06-12 for the Ada->Blackwell swap (cards are now 96 GB, so the
# Ada-era fractions reserved ~2x the bytes for the same models). Empirically
# re-floored: util climbed in 0.01 steps until each service was stable under
# 20x parallel inference.
#   embed/rerank 0.05 (~4.8 GB ea) — the load-floor for the 0.6B models (0.04
#     OOMs on engine init; their footprint is fixed weights+context, not KV).
#   reward 0.10 (~9.6 GB) — the real over-provision was here (0.18 -> 0.10).
# Net: ~11 GB freed on GPU 1. (Fractions are of TOTAL card VRAM — re-floor if
# the cards change again.)
# 0.03 each — REBALANCED 2026-06-14 (was 0.05): the 0.6B models sat at ~5.5 GB
# each at 0.05 (mostly util-reservation waste); 0.03 (~3.6 GB) fits weights +
# CUDA context with room, freeing ~4 GB back to granite. Recreate them ONE AT A
# TIME — concurrent recreate races the memory-profiling assertion.
EMBED_GPU_MEM_UTIL=0.03
RERANK_GPU_MEM_UTIL=0.03
REWARD_GPU_MEM_UTIL=0.10

# Context length caps — lower these if VRAM is tight.
# Qwen3-Embedding supports up to 32k; reranker up to 32k.
# Skywork capped at 16k server-side as defense-in-depth; JudgeClient also
# enforces the cap at dispatch time per spec.
EMBED_MAX_MODEL_LEN=8192
RERANK_MAX_MODEL_LEN=8192
REWARD_MAX_MODEL_LEN=16384

# Optional API key — leave blank for no auth (fine on the internal network).
# If set, all three services require `Authorization: Bearer <key>`.
API_KEY=

# HuggingFace token — only needed for gated models in the HF-Hub-loaded
# services (embed/rerank). Reward is local-path, ignores this.
HF_TOKEN=

# === granite-4.1-8b — RETIRED 2026-08-12, vars removed 2026-08-20 ===
# Was the production summarizer. The `summarizer` / `classifier` gateway aliases
# were repointed at the gen seat and the container stopped; the service block and
# these tunables are now gone. See the tombstone in compose.yaml for the lesson
# this cost us (nevermore stayed pinned to the dead `granite-4.1-8b` alias and
# failed silently for 8 days).

# Qwen2.5-Coder-1.5B (BASE) — FIM code-completion seat for Zed editor inline
# edit-predictions (deep-research pick 2026-07-27, Apache-2.0). GPU-1, alongside the
# small-model trio + (phasing-out) granite. Reached via LiteLLM `coder-fast` alias
# and the keyless zed-fim-proxy (stacks/zed-fim-proxy). util 0.06 (~5.7 GB) holds
# the 1.5B fp16 + fp8 KV; 8192 ctx is ample for FIM (KV = 13.75x concurrency).
CODER_PORT=8020
CODER_GPU_ID=1
CODER_MODEL=Qwen/Qwen2.5-Coder-1.5B
CODER_SERVED_NAME=qwen2.5-coder-1.5b
CODER_MAX_MODEL_LEN=8192
CODER_KV_CACHE_DTYPE=fp8
CODER_GPU_MEM_UTIL=0.06
CODER_MAX_NUM_SEQS=32

# === LFM2.5-2.6B — RETIRED PERMANENTLY 2026-08-20 (operator directive) ===
# Eval-only bake-off seat vs granite-4.1-8b that never got its production ruling;
# its comparator was retired first, and it logged 0 calls in the 4 days before it
# came down. Container removed, service block and tunables deleted, gateway alias
# dropped. Weights remain in the shared HF cache.
