diff --git a/docker/worker.Dockerfile b/docker/worker.Dockerfile index 4d4ee0e..b66109b 100644 --- a/docker/worker.Dockerfile +++ b/docker/worker.Dockerfile @@ -52,6 +52,9 @@ RUN git clone --filter=blob:none --no-checkout https://github.com/eust-w/DISCOVE git -C /opt/DISCOVERSE submodule update --init policies/act && \ test "$(git -C /opt/DISCOVERSE rev-parse HEAD)" = "${DISCOVERSE_COMMIT}" && \ test "$(git -C /opt/DISCOVERSE/policies/act rev-parse HEAD)" = "${ACT_COMMIT}" && \ + grep -Ev '^[[:space:]]*(torchvision|torch|opencv-python)([[:space:]]|$)' /opt/DISCOVERSE/policies/act/requirements/train_eval.txt > /tmp/discoverse-act-train-requirements.txt && \ + python -m pip install --no-cache-dir -c /tmp/worker-constraints.txt -r /tmp/discoverse-act-train-requirements.txt && \ + python /app/scripts/prepare_discoverse_act_runtime.py --act-root /opt/DISCOVERSE/policies/act --expected-commit "${ACT_COMMIT}" && \ python -m pip install --no-cache-dir --no-deps -e /opt/DISCOVERSE RUN git clone --filter=blob:none --no-checkout https://github.com/Motphys/motrixsim-docs.git /opt/motrixsim-docs && \ diff --git a/scripts/prepare_discoverse_act_runtime.py b/scripts/prepare_discoverse_act_runtime.py new file mode 100644 index 0000000..fa2c401 --- /dev/null +++ b/scripts/prepare_discoverse_act_runtime.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import argparse +import json +import subprocess +from pathlib import Path + + +OPTIONAL_IMPORT = "from airbot_data_collection.tools.av_coder import AvCoder" +OPTIONAL_REPLACEMENT = '''try: + from airbot_data_collection.tools.av_coder import AvCoder +except ModuleNotFoundError as exc: + _AIRBOT_DATA_COLLECTION_ERROR = str(exc) + + class AvCoder: + def __init__(self, *args, **kwargs): + raise RuntimeError( + "airbot_data_collection is required only for MCAP decoding or AIRBOT hardware evaluation; " + "it is not required for Real2Sim HDF5 ACT training" + ) from RuntimeError(_AIRBOT_DATA_COLLECTION_ERROR) +''' + + +def main() -> int: + parser = argparse.ArgumentParser(description="Prepare pinned DISCOVERSE ACT for server-side HDF5 training.") + parser.add_argument("--act-root", type=Path, required=True) + parser.add_argument("--expected-commit", required=True) + args = parser.parse_args() + root = args.act_root.resolve() + commit = subprocess.check_output(["git", "-C", str(root), "rev-parse", "HEAD"], text=True).strip() + if commit != args.expected_commit: + raise SystemExit(f"ACT revision mismatch: expected {args.expected_commit}, got {commit}") + target = root / "utils" / "utils.py" + changed = patch_optional_airbot_dependency(target) + print(json.dumps({"ok": True, "act_root": str(root), "commit": commit, "patched": changed}, indent=2)) + return 0 + + +def patch_optional_airbot_dependency(path: Path) -> bool: + source = path.read_text(encoding="utf-8") + if OPTIONAL_REPLACEMENT in source: + return False + if OPTIONAL_IMPORT not in source: + raise RuntimeError(f"expected AIRBOT dependency import was not found in {path}") + path.write_text(source.replace(OPTIONAL_IMPORT, OPTIONAL_REPLACEMENT, 1), encoding="utf-8") + return True + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/src/real2sim_platform/adapters.py b/src/real2sim_platform/adapters.py index 9507b7f..dcebfd3 100644 --- a/src/real2sim_platform/adapters.py +++ b/src/real2sim_platform/adapters.py @@ -1068,6 +1068,7 @@ def _run_discoverse_act_training(config: PlatformConfig, store: PlatformStore, t "state_dim": dataset_info["state_dim"], "action_dim": dataset_info["action_dim"], "config_path": str(config_path), + "runtime_compatibility": "HDF5 ACT training; AIRBOT MCAP/hardware codecs remain optional and fail explicitly when requested", }, "metrics": {"best_validation_loss": best_loss}, "artifacts": {"checkpoint": str(checkpoint), "dataset_stats": str(stats_path)}, diff --git a/src/real2sim_platform/runtime_gate.py b/src/real2sim_platform/runtime_gate.py index ce8e938..eea22ed 100644 --- a/src/real2sim_platform/runtime_gate.py +++ b/src/real2sim_platform/runtime_gate.py @@ -241,7 +241,12 @@ def _act_probe(config: PlatformConfig) -> dict[str, Any]: env = os.environ.copy() env["PYTHONPATH"] = os.pathsep.join([str(act_root), str(config.discoverse_root), env.get("PYTHONPATH", "")]).rstrip(os.pathsep) completed = subprocess.run( - [sys.executable, "-c", "import torch; from policies.act.act import ACTPolicy; print(torch.__version__); assert ACTPolicy is not None and torch.cuda.is_available()"], + [ + sys.executable, + "-c", + "import torch; import policy_train; import utils.utils; from policies.act.act import ACTPolicy; " + "print(torch.__version__); assert ACTPolicy is not None and torch.cuda.is_available()", + ], cwd=act_root, env=env, text=True, @@ -249,7 +254,7 @@ def _act_probe(config: PlatformConfig) -> dict[str, Any]: timeout=60, check=True, ) - return {"ok": True, "torch": completed.stdout.strip().splitlines()[-1]} + return {"ok": True, "torch": completed.stdout.strip().splitlines()[-1], "training_stack_imported": True} def _anysplat_probe(config: PlatformConfig) -> dict[str, Any]: diff --git a/tests/test_production_platform.py b/tests/test_production_platform.py index ddcb9ae..0bf9a52 100644 --- a/tests/test_production_platform.py +++ b/tests/test_production_platform.py @@ -276,6 +276,8 @@ def test_worker_image_materializes_motrixsim_lfs_assets() -> None: assert "git-lfs" in dockerfile assert "git -C /opt/motrixsim-docs lfs pull --include='examples/assets/**'" in dockerfile assert "git-lfs.github.com/spec" in dockerfile + assert "requirements/train_eval.txt" in dockerfile + assert "prepare_discoverse_act_runtime.py" in dockerfile manifest = (ROOT / "deploy/poc/app-template.yaml").read_text(encoding="utf-8") assert "REAL2SIM_MOTRIXSIM_PYTHON" in manifest assert "REAL2SIM_FFMPEG_BIN" in manifest @@ -290,6 +292,21 @@ def test_rollout_video_encoder_reports_the_selected_ffmpeg_failure(tmp_path: Pat _write_preview_video(tmp_path / "rollout.mp4", [np.zeros((16, 16, 3), dtype=np.uint8)]) +def test_discoverse_act_runtime_patch_keeps_airbot_dependency_explicit(tmp_path: Path) -> None: + script_path = ROOT / "scripts/prepare_discoverse_act_runtime.py" + spec = importlib.util.spec_from_file_location("real2sim_prepare_discoverse_act_runtime", script_path) + assert spec and spec.loader + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + target = tmp_path / "utils.py" + target.write_text("import torch\nfrom airbot_data_collection.tools.av_coder import AvCoder\n", encoding="utf-8") + assert module.patch_optional_airbot_dependency(target) is True + patched = target.read_text(encoding="utf-8") + assert "MCAP decoding or AIRBOT hardware evaluation" in patched + assert "except ModuleNotFoundError" in patched + assert module.patch_optional_airbot_dependency(target) is False + + def test_runtime_gate_rejects_unresolved_motrixsim_lfs_pointer(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: root = tmp_path / "motrixsim-docs" required = [