Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions configs/endpoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ghcr": {
"registry": "ghcr.io"
},
"opensandbox_kata": {
"domain": "opensandbox-kata.breithorn.svc.cscs.ch"
},
"opensandbox_proxy": {
"domain": "osb-gw-ka.swissai.svc.cscs.ch"
},
"swissai_gateway": {
"base_url": "https://api.swissai.svc.cscs.ch/v1"
}
}
18 changes: 18 additions & 0 deletions scripts/common/endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""The service endpoints the runners call, from configs/endpoints.json.
Hosts and URLs only; keys stay in scripts/secrets.env.
"""

import json
from pathlib import Path
from typing import Dict

ENDPOINTS_FILE = Path(__file__).resolve().parents[2] / "configs" / "endpoints.json"


def endpoint(name: str) -> Dict[str, str]:
"""The entry `name` of the endpoints file."""
endpoints = json.loads(ENDPOINTS_FILE.read_text())
if name not in endpoints:
raise KeyError(f"no endpoint {name!r} in {ENDPOINTS_FILE} (has: {', '.join(endpoints)})")
return endpoints[name]
5 changes: 3 additions & 2 deletions scripts/common/opensandbox_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Union

from scripts.common.endpoints import endpoint
from scripts.common.k8s_sandbox import (
_HOSTS_LOCALHOST_IPV4_ONLY,
_TIMEOUT_EXIT_CODES,
Expand All @@ -59,8 +60,8 @@
untar_bytes,
)

# Breithorn's Kata endpoint; the default (gVisor) one cannot enforce network policies.
DEFAULT_DOMAIN = "opensandbox-kata.breithorn.svc.cscs.ch"
# Breithorn's Kata endpoint (configs/endpoints.json); the default (gVisor) one cannot enforce network policies.
DEFAULT_DOMAIN = endpoint("opensandbox_kata")["domain"]
RUN_LABEL_ENV = "OPENSANDBOX_RUN_LABEL"
RUN_LABEL_KEY = "sandbox-run"
# Set by install(agent_allowed_hosts=...): what an agent's sandbox may reach (None: everything).
Expand Down
10 changes: 6 additions & 4 deletions scripts/direct_serving/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from swiss_ai_model_launch.launchers.topology import Topology

from scripts.common import suites
from scripts.common.endpoints import endpoint

HEALTH_URL = f"http://127.0.0.1:{FRAMEWORK_PORT}/health"
API_BASE_URL = f"http://127.0.0.1:{FRAMEWORK_PORT}/v1"
Expand All @@ -65,6 +66,7 @@

REPO_ROOT = Path(__file__).resolve().parents[2]
IMAGE_REPOSITORY = "swiss-ai/evals-post-train-eval"
REGISTRY = endpoint("ghcr")["registry"] # configs/endpoints.json
# What the image is built from: the paths of .github/workflows/eval-image.yml. A commit
# that changes none of them runs in the image of the last one that did.
IMAGE_INPUTS = ("containers/Dockerfile.eval", "requirements", ".github/workflows/eval-image.yml")
Expand Down Expand Up @@ -156,11 +158,11 @@ def image_published(commit: str) -> bool | None:
when ghcr could not be asked."""
try:
with urllib.request.urlopen(
f"https://ghcr.io/token?service=ghcr.io&scope=repository:{IMAGE_REPOSITORY}:pull", timeout=15
f"https://{REGISTRY}/token?service={REGISTRY}&scope=repository:{IMAGE_REPOSITORY}:pull", timeout=15
) as response:
token = json.load(response)["token"]
request = urllib.request.Request(
f"https://ghcr.io/v2/{IMAGE_REPOSITORY}/manifests/{commit}",
f"https://{REGISTRY}/v2/{IMAGE_REPOSITORY}/manifests/{commit}",
method="HEAD",
headers={
"Authorization": f"Bearer {token}",
Expand All @@ -181,7 +183,7 @@ def check_eval_image(commit: str) -> None:
published = image_published(commit)
if published is False:
raise RuntimeError(
f"ghcr.io/{IMAGE_REPOSITORY}:{commit} does not exist: push the commit that changed the "
f"{REGISTRY}/{IMAGE_REPOSITORY}:{commit} does not exist: push the commit that changed the "
"image's inputs (CI builds it), or name another with --eval-image-commit."
)
if published is None:
Expand All @@ -192,7 +194,7 @@ def eval_edf(image_commit: str, mounts: list[str]) -> str:
"""The EDF that starts the eval image of `image_commit`."""
listed = ",\n".join(f' "{mount}"' for mount in dict.fromkeys(mounts))
return (
f'image = "ghcr.io#{IMAGE_REPOSITORY}:{image_commit}"\n\n'
f'image = "{REGISTRY}#{IMAGE_REPOSITORY}:{image_commit}"\n\n'
f"mounts = [\n{listed}\n]\n\n"
"writable = true\n\n"
'[env]\nPMIX_MCA_psec = "native"\n\n'
Expand Down
5 changes: 3 additions & 2 deletions scripts/harbor/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

from urllib.parse import urlsplit

from scripts.common.endpoints import endpoint
from scripts.harbor.model_tunnel import (
CHISEL_DIR_ENV,
DEFAULT_POD_PORT,
Expand All @@ -54,8 +55,8 @@
DOCKER_ENVIRONMENT = "scripts.harbor.docker_environment:PlatformDockerEnvironment"
OPENSANDBOX_ENVIRONMENT = "scripts.harbor.opensandbox_environment:KataSandboxEnvironment"
ENVIRONMENTS = {"docker": DOCKER_ENVIRONMENT, "k8s": K8S_ENVIRONMENT, "opensandbox": OPENSANDBOX_ENVIRONMENT}
# Breithorn's Kata endpoint; the default (gVisor) one cannot enforce network policies.
OPENSANDBOX_KATA_DOMAIN = "opensandbox-kata.breithorn.svc.cscs.ch" # = opensandbox_sandbox.DEFAULT_DOMAIN
# Breithorn's Kata endpoint (configs/endpoints.json); the default (gVisor) one cannot enforce network policies.
OPENSANDBOX_KATA_DOMAIN = endpoint("opensandbox_kata")["domain"]

# Our benchmark names -> the Harbor dataset. Registry datasets are pinned: legacy-registry
# ones by version, Harbor Hub packages by content digest (what @latest resolved to when pinned).
Expand Down
7 changes: 5 additions & 2 deletions scripts/inspect_ai/tasks/simpleqa_verified_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- The grader is a task argument instead of a `--model-role grader=...`, so it can live on
the gateway while the model under test is launched locally:
--task-arg judge_model=openai-api/gateway/<served model name>
`gateway` defaults to https://api.swissai.svc.cscs.ch/v1 with the job's CSCS_SERVING_API
`gateway` defaults to the swissai_gateway of configs/endpoints.json with the job's CSCS_SERVING_API
key; GATEWAY_BASE_URL / GATEWAY_API_KEY override them. A model on the same gateway as
the model under test can use `openai-api/swissai/<served model name>` instead.
- Reasoning left inline in the answer (`<|inner_prefix|>...<|inner_suffix|>`, Apertus 1.5
Expand All @@ -17,14 +17,17 @@
`scorer` and `grade_parse` are passed through. "original" is the paper's A/B/C grader.
"""

import json
import os
import re
from pathlib import Path

from inspect_ai import Task, task
from inspect_ai.model import get_model
from inspect_ai.solver import Generate, Solver, TaskState, solver

GATEWAY_BASE_URL = "https://api.swissai.svc.cscs.ch/v1"
ENDPOINTS_FILE = Path(__file__).resolve().parents[3] / "configs" / "endpoints.json"
GATEWAY_BASE_URL = json.loads(ENDPOINTS_FILE.read_text())["swissai_gateway"]["base_url"]
THINK_START = "<|inner_prefix|>"
THINK_END = "<|inner_suffix|>"
_THINK_BLOCK = re.compile(
Expand Down
3 changes: 2 additions & 1 deletion scripts/lm_eval_harness/launch_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@

# ── Health check ──────────────────────────────────────────────────────

HEALTH_CHECK_URL = "https://api.swissai.svc.cscs.ch/v1/models"
ENDPOINTS_FILE = Path(__file__).resolve().parents[2] / "configs" / "endpoints.json"
HEALTH_CHECK_URL = json.loads(ENDPOINTS_FILE.read_text())["swissai_gateway"]["base_url"] + "/models"
TERMINAL_JOB_STATUSES = {
JobStatus.COMPLETED,
JobStatus.CANCELLED,
Expand Down