Backup / gmnet /code /journal_exp /tests /test_launch_scripts.py
YFanwang's picture
Add files using upload-large-folder tool
10979b5 verified
Raw
History Blame Contribute Delete
1.75 kB
"""Regression tests for shell launchers."""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
LONGLIVE_INIT = Path("/nfs/ywang29/LongLive/scripts/init_run.sh")
def _export_lines(path: Path) -> list[str]:
return [
line
for line in path.read_text(encoding="utf-8").splitlines()
if line.startswith("export ") or line.startswith("# export ")
]
def test_init_run_preserves_longlive_export_lines() -> None:
assert _export_lines(ROOT / "scripts/init_run.sh") == _export_lines(LONGLIVE_INIT)
def test_init_run_uses_selected_python_for_distributed_workers(
tmp_path: Path,
) -> None:
data_root = tmp_path / "data"
data_root.mkdir()
output_dir = tmp_path / "output"
scratch_dir = tmp_path / "scratch"
environment = os.environ.copy()
environment.update(
{
"PYTHON_BIN": sys.executable,
"REPO_DIR": str(ROOT),
"CONFIG_PATH": "configs/e0_baseline/imagenet_gmnet_s3.yaml",
"DATA_ROOT": str(data_root),
"OUTPUT_DIR": str(output_dir),
"LOCAL_SCRATCH_DIR": str(scratch_dir),
"NPROC_PER_NODE": "8",
"DRY_RUN": "1",
"POST_EVAL": "0",
}
)
result = subprocess.run(
["bash", str(ROOT / "scripts/init_run.sh")],
check=True,
capture_output=True,
text=True,
env=environment,
)
launch_line = next(
line for line in result.stdout.splitlines() if line.startswith("Launching:")
)
assert sys.executable in launch_line
assert "-m torch.distributed.run" in launch_line
assert " torchrun " not in launch_line