diff --git a/cascade/validator/eval_offload.py b/cascade/validator/eval_offload.py index 9cf23185..6a9aae1b 100644 --- a/cascade/validator/eval_offload.py +++ b/cascade/validator/eval_offload.py @@ -38,6 +38,9 @@ # uv on the pod (runs the benchmarks/ sidecar's own locked env), matching # cascade.trainer.bench_hook.BenchPlan.uv_bin. DEFAULT_UV_BIN = "~/.local/bin/uv" +# #903: the default is resolved ON the host (the Lium template has /usr/local/bin/uv, +# the worker image /bin/uv): PATH first, the bootstrap-era path as the fallback. +UV_RESOLVE = '"$(command -v uv 2>/dev/null || echo ~/.local/bin/uv)"' class PrivateEvalUnavailable(RuntimeError): @@ -652,7 +655,7 @@ def build_bench_remote_command( return ( prefix + (f"timeout --signal=TERM --kill-after=15s {max(1, timeout_s)}s " if timeout_s else "") - + f"{uv_bin} run --project {shlex.quote(f'{host.workdir}/benchmarks')} " + + f"{UV_RESOLVE if uv_bin == DEFAULT_UV_BIN else uv_bin} run --project {shlex.quote(f'{host.workdir}/benchmarks')} " + " ".join(bench_uv_args(suites)) + " " + quoted ) diff --git a/tests/accept/w3b6a/PATHS b/tests/accept/w3b6a/PATHS index f512017f..421013ac 100644 --- a/tests/accept/w3b6a/PATHS +++ b/tests/accept/w3b6a/PATHS @@ -12,3 +12,5 @@ cascade/validator/lane_d_bench_host.py # The optional `bench_hosts` key of the --lane-d-inputs TOML, and the # source handing the bench host each digest's effective context. cascade/validator/lane_d_inputs.py +# #903: the offloaded sweep's remote command resolves uv on the host. +cascade/validator/eval_offload.py diff --git a/tests/accept/w3b6a/test_w3b6a_offload_uv_resolve.py b/tests/accept/w3b6a/test_w3b6a_offload_uv_resolve.py new file mode 100644 index 00000000..59e88c92 --- /dev/null +++ b/tests/accept/w3b6a/test_w3b6a_offload_uv_resolve.py @@ -0,0 +1,74 @@ +"""#903 (W3b6a): the offloaded bench sweep finds uv wherever the sweep host has +it. The default used to be the hard-coded ``~/.local/bin/uv``; a host whose +image puts uv elsewhere (the Lium template: ``/usr/local/bin/uv``) failed +every offloaded lane A sweep as ``infra_failed``. The default is now resolved +ON the host (PATH first, ``~/.local/bin/uv`` as the fallback); an explicit +``uv_bin`` is used as given. The command still runs the sidecar's checked-in +lock (``--frozen``), so the report is unchanged.""" +from __future__ import annotations + +import shlex +import subprocess +from types import SimpleNamespace + +from cascade.validator import eval_offload as EO + + +def _host(): + return SimpleNamespace(workdir="/root/cascade", cuda_device=None) + + +def _uv_token(cmd: str) -> str: + """The shell word that names uv in the remote command.""" + head, sep, _ = cmd.partition(" run --project ") + assert sep, cmd + return head + + +def _on_host(word: str, *, home, path) -> str: + """What ``word`` expands to in the host's bash (HOME / PATH as given).""" + out = subprocess.run(["/bin/bash", "-c", f"echo {word}"], env={"HOME": str(home), + "PATH": str(path)}, capture_output=True, text=True, check=True) + return out.stdout.strip() + + +def _fake_uv(tmp_path): + fake = tmp_path / "usr-local-bin" / "uv" + fake.parent.mkdir() + fake.write_text("#!/bin/sh\n", encoding="utf-8") + fake.chmod(0o755) + return fake + + +def test_w3b6a_default_uv_resolves_from_path_then_falls_back(tmp_path): + fake = _fake_uv(tmp_path) + empty = tmp_path / "empty-bin" + empty.mkdir() + word = _uv_token(EO.build_bench_remote_command(_host(), "/w/c", "/w/r", suites="gift-eval")) + assert _on_host(word, home=tmp_path, path=fake.parent) == str(fake), ( + "#903: the default uv is not resolved from the host's PATH") + assert _on_host(word, home=tmp_path, path=empty) == str(tmp_path / ".local/bin/uv") + + +def test_w3b6a_explicit_uv_bin_is_used_as_given(tmp_path): + fake = _fake_uv(tmp_path) + cmd = EO.build_bench_remote_command(_host(), "/w/c", "/w/r", suites="gift-eval", + uv_bin="/opt/uv/bin/uv") + assert shlex.split(cmd)[0] == "/opt/uv/bin/uv" + assert _on_host(_uv_token(cmd), home=tmp_path, path=fake.parent) == "/opt/uv/bin/uv" + default = EO.build_bench_remote_command(_host(), "/w/c", "/w/r", suites="gift-eval") + assert _on_host(_uv_token(default), home=tmp_path, path=fake.parent) == str(fake), ( + "#903: the default uv is not resolved from the host's PATH") + + +def test_w3b6a_resolved_uv_still_runs_the_frozen_lock_with_a_timeout(tmp_path): + fake = _fake_uv(tmp_path) + cmd = EO.build_bench_remote_command( + SimpleNamespace(workdir="/root/cascade", cuda_device="1"), "/w/c", "/w/r", + suites="gift-eval,time", timeout_s=600) + assert cmd.startswith("CUDA_VISIBLE_DEVICES=1 timeout --signal=TERM --kill-after=15s 600s ") + word = _uv_token(cmd).split("600s ", 1)[1] + assert _on_host(word, home=tmp_path, path=fake.parent) == str(fake), ( + "#903: the default uv is not resolved from the host's PATH") + tail = cmd.partition(" run --project ")[2] + assert tail.startswith("/root/cascade/benchmarks --frozen --extra time cascade-benchmark ")