File size: 1,748 Bytes
10979b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""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