Jerry999's picture
Add files using upload-large-folder tool
22decf5 verified
Raw History Blame Contribute Delete
3.63 kB
"""Paths and settings. Everything machine-specific comes from the environment or `.env`."""
import os
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
UPSTREAM = REPO_ROOT / "third_party" / "PostTrainBench"
ENV_FILE = REPO_ROOT / ".env"
def load_env_file() -> None:
"""Export KEY=VALUE lines from `.env`; variables already set in the shell win."""
if not ENV_FILE.is_file():
return
for line in ENV_FILE.read_text().splitlines():
key, sep, value = line.strip().partition("=")
if sep and not key.startswith("#"):
os.environ.setdefault(key.strip(), value.strip().strip("\"'"))
load_env_file()
DATA_DIR = Path(os.environ.get("PTB_DATA_DIR") or REPO_ROOT / "data").resolve()
CONTAINERS = DATA_DIR / "containers"
HF_CACHE = DATA_DIR / "hf_cache"
# A sweep can opt into a wholly separate result root. This is stronger than relying only on the
# agent/model prefix below `results/`, and is useful when comparing agents without any possibility
# of touching another agent's artifacts.
RESULTS_DIR = Path(os.environ.get("PTB_RESULTS_DIR") or DATA_DIR / "results").resolve()
# Upstream picks a container per cell with POST_TRAIN_BENCH_CONTAINER_NAME in its `.sub` files:
# `opus_5` for the claude-opus-5 cells, `vllm_debug` for evaluation. Both pin the agent CLIs and
# add the inspect_ai fork that streams vLLM output to the log; plain `standard` does neither.
# `opus_5_local` is upstream's `opus_5` minus two CLI installs whose CDNs the aws cluster cannot
# reach; see the header of containers/opus_5_local.def.
AGENT_CONTAINER = "opus_5_local"
EVAL_CONTAINER = "vllm_debug"
LOCAL_CONTAINERS = REPO_ROOT / "containers"
LOCAL_AGENTS = REPO_ROOT / "agents"
def image(container: str) -> Path:
return CONTAINERS / f"{container}.sif"
def definition(container: str) -> Path:
"""Local definitions shadow upstream's, so machine-specific variants stay out of the submodule."""
local = LOCAL_CONTAINERS / f"{container}.def"
return local if local.is_file() else UPSTREAM / "containers" / f"{container}.def"
def agent_dir(agent: str) -> Path:
"""Return a local agent scaffold when present, otherwise the upstream scaffold."""
local = LOCAL_AGENTS / agent
return local if (local / "solve.sh").is_file() else UPSTREAM / "agents" / agent
TASKS = sorted(p.parent.name for p in (UPSTREAM / "src/eval/tasks").glob("*/evaluate.py"))
AGENTS = sorted({p.parent.name for p in (UPSTREAM / "agents").glob("*/solve.sh")}
| {p.parent.name for p in LOCAL_AGENTS.glob("*/solve.sh")})
DEFINITIONS = sorted({p.stem for p in (UPSTREAM / "containers").glob("*.def")}
| {p.stem for p in LOCAL_CONTAINERS.glob("*.def")})
def judge_pool_targets() -> list[str]:
"""`host:port` of every ready replica of the local vLLM judge pool, or an empty list.
Stands in for OpenAI's `gpt-5-mini` on the two LLM-graded benchmarks, because `.env` has no
`OPENAI_API_KEY` and api.openai.com is not routable from the aws cluster. Either name the
replicas with `PTB_JUDGE_POOL`, or point `PTB_JUDGE_POOL_DIR` at the pool directory that
`scripts/ptb_judge_pool.sbatch` fills with one `task_<i>.addr` per replica -- it writes each
file only after that endpoint answers, so a reader never sees a half-started server.
"""
if explicit := os.environ.get("PTB_JUDGE_POOL", "").replace(",", " ").split():
return explicit
pool_dir = os.environ.get("PTB_JUDGE_POOL_DIR", "")
if not pool_dir:
return []
return sorted(path.read_text().strip() for path in Path(pool_dir).glob("task_*.addr"))