mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 02:24:12 +01:00
fix(tests): use static rendezvous for local TP2 and allow torchrun keys
On torch 2.13 the c10d backend gives workers MASTER_ADDR=getfqdn() and a fresh MASTER_PORT from the shared TCPStore (launcher.api returns no master endpoint for non-static backends), which the launcher contract rejects. local_tp2 now uses --rdzv-backend=static with the profiled --master-addr/--master-port and --node-rank=0; the is_host approach is dropped. two_host_tp2 keeps c10d. Allow ROLE_NAME and TORCHELASTIC_SIGNALS_TO_HANDLE (set by torchrun 2.13) and LC_CTYPE (PEP 538 locale coercion) in the worker environment. Verified on 2x A100. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eaca7f9177
commit
e3ab98da38
2 files changed
+80
-11
No files matched your search
@@ -34,11 +34,19 @@ def _torchrun_command(
|
||||
) -> list[str]:
|
||||
if shape == "local_tp2":
|
||||
topology = ["--nnodes=1", "--nproc-per-node=2"]
|
||||
# The single local agent must host even when its hostname resolves elsewhere.
|
||||
rendezvous = ["--rdzv-conf=is_host=1"]
|
||||
# Static rendezvous preserves the profiled worker MASTER_ADDR and MASTER_PORT.
|
||||
rendezvous = [
|
||||
"--rdzv-backend=static",
|
||||
f"--master-addr={master_addr}",
|
||||
f"--master-port={master_port}",
|
||||
"--node-rank=0",
|
||||
]
|
||||
elif shape == "two_host_tp2":
|
||||
topology = ["--nnodes=2", "--nproc-per-node=1"]
|
||||
rendezvous = []
|
||||
rendezvous = [
|
||||
"--rdzv-backend=c10d",
|
||||
f"--rdzv-endpoint={master_addr}:{master_port}",
|
||||
]
|
||||
else:
|
||||
raise ValueError(f"unknown TP qualification shape: {shape}")
|
||||
return [
|
||||
@@ -46,10 +54,8 @@ def _torchrun_command(
|
||||
"-m",
|
||||
"torch.distributed.run",
|
||||
*topology,
|
||||
"--rdzv-backend=c10d",
|
||||
f"--rdzv-endpoint={master_addr}:{master_port}",
|
||||
f"--rdzv-id={rendezvous_id}",
|
||||
*rendezvous,
|
||||
f"--rdzv-id={rendezvous_id}",
|
||||
"--max-restarts=0",
|
||||
str(worker_path),
|
||||
"--obliteratus-tp-worker",
|
||||
@@ -108,6 +114,7 @@ def _worker_environment(
|
||||
"HOME",
|
||||
"LANG",
|
||||
"LC_ALL",
|
||||
"LC_CTYPE", # Python may add this during PEP 538 locale coercion.
|
||||
"LD_LIBRARY_PATH",
|
||||
"NVIDIA_VISIBLE_DEVICES",
|
||||
"OMP_NUM_THREADS",
|
||||
@@ -116,8 +123,10 @@ def _worker_environment(
|
||||
"PYTHONNOUSERSITE",
|
||||
"PYTHONPATH",
|
||||
"PYTHONUNBUFFERED",
|
||||
"ROLE_NAME", # torchrun 2.13 sets each worker's role name.
|
||||
"TMPDIR",
|
||||
"TORCHELASTIC_ERROR_FILE",
|
||||
"TORCHELASTIC_SIGNALS_TO_HANDLE", # torchrun 2.13 sets each worker's handled signals.
|
||||
"TORCHELASTIC_USE_AGENT_STORE",
|
||||
"TORCH_NCCL_ASYNC_ERROR_HANDLING",
|
||||
"VIRTUAL_ENV",
|
||||
|
||||
@@ -15,6 +15,7 @@ from unittest.mock import MagicMock, Mock, call
|
||||
import psutil
|
||||
import pytest
|
||||
|
||||
from obliteratus.distributed.launcher import _REQUIRED_ENV
|
||||
from tests.conditional import _llama_tp_harness as harness
|
||||
|
||||
|
||||
@@ -24,11 +25,20 @@ pytestmark = pytest.mark.cpu
|
||||
@pytest.mark.parametrize(
|
||||
("shape", "topology", "rendezvous"),
|
||||
[
|
||||
("local_tp2", ["--nnodes=1", "--nproc-per-node=2"], ["--rdzv-conf=is_host=1"]),
|
||||
("two_host_tp2", ["--nnodes=2", "--nproc-per-node=1"], []),
|
||||
(
|
||||
"local_tp2", ["--nnodes=1", "--nproc-per-node=2"],
|
||||
[
|
||||
"--rdzv-backend=static", "--master-addr=10.1.2.3",
|
||||
"--master-port=23456", "--node-rank=0",
|
||||
],
|
||||
),
|
||||
(
|
||||
"two_host_tp2", ["--nnodes=2", "--nproc-per-node=1"],
|
||||
["--rdzv-backend=c10d", "--rdzv-endpoint=10.1.2.3:23456"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_torchrun_command_hosts_rendezvous_only_for_local_tp2(shape, topology, rendezvous):
|
||||
def test_torchrun_command_uses_shape_specific_rendezvous(shape, topology, rendezvous):
|
||||
command = harness._torchrun_command(
|
||||
shape=shape,
|
||||
master_addr="10.1.2.3",
|
||||
@@ -39,8 +49,7 @@ def test_torchrun_command_hosts_rendezvous_only_for_local_tp2(shape, topology, r
|
||||
)
|
||||
assert command == [
|
||||
sys.executable, "-m", "torch.distributed.run", *topology,
|
||||
"--rdzv-backend=c10d", "--rdzv-endpoint=10.1.2.3:23456",
|
||||
"--rdzv-id=test-attempt", *rendezvous, "--max-restarts=0",
|
||||
*rendezvous, "--rdzv-id=test-attempt", "--max-restarts=0",
|
||||
"worker.py", "--obliteratus-tp-worker", "job.json",
|
||||
]
|
||||
|
||||
@@ -172,6 +181,57 @@ def test_worker_environment_keeps_parent_harness_controls_out(monkeypatch, tmp_p
|
||||
assert environment["OBLITERATUS_RUN_ID"] == "attempt"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("name", "value"),
|
||||
[
|
||||
("LC_CTYPE", "C.UTF-8"),
|
||||
("ROLE_NAME", "default"),
|
||||
("TORCHELASTIC_SIGNALS_TO_HANDLE", "SIGTERM,SIGINT,SIGHUP,SIGQUIT"),
|
||||
],
|
||||
)
|
||||
def test_worker_environment_allows_torchrun_and_locale_keys(monkeypatch, tmp_path, name, value):
|
||||
monkeypatch.setenv(name, value)
|
||||
environment, allowed = harness._worker_environment(
|
||||
repository_root=tmp_path, run_id="attempt", interface="enp1s0",
|
||||
)
|
||||
assert name in allowed
|
||||
assert environment[name] == value
|
||||
|
||||
|
||||
def test_worker_environment_allows_documented_torchrun_213_worker_keys(tmp_path):
|
||||
_, allowed = harness._worker_environment(
|
||||
repository_root=tmp_path, run_id="attempt", interface="enp1s0",
|
||||
)
|
||||
worker_keys = {
|
||||
"CUDA_VISIBLE_DEVICES",
|
||||
"GROUP_RANK",
|
||||
"GROUP_WORLD_SIZE",
|
||||
"HOME",
|
||||
"LANG",
|
||||
"LC_CTYPE",
|
||||
"LOCAL_RANK",
|
||||
"LOCAL_WORLD_SIZE",
|
||||
"MASTER_ADDR",
|
||||
"MASTER_PORT",
|
||||
"OMP_NUM_THREADS",
|
||||
"PATH",
|
||||
"PYTHONNOUSERSITE",
|
||||
"RANK",
|
||||
"ROLE_NAME",
|
||||
"ROLE_RANK",
|
||||
"ROLE_WORLD_SIZE",
|
||||
"TORCHELASTIC_ERROR_FILE",
|
||||
"TORCHELASTIC_MAX_RESTARTS",
|
||||
"TORCHELASTIC_RESTART_COUNT",
|
||||
"TORCHELASTIC_RUN_ID",
|
||||
"TORCHELASTIC_SIGNALS_TO_HANDLE",
|
||||
"TORCHELASTIC_USE_AGENT_STORE",
|
||||
"TORCH_NCCL_ASYNC_ERROR_HANDLING",
|
||||
"WORLD_SIZE",
|
||||
}
|
||||
assert worker_keys <= _REQUIRED_ENV | set(allowed)
|
||||
|
||||
|
||||
def test_process_group_discards_output_by_default(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("OBLITERATUS_TP_WORKER_LOG_DIR", raising=False)
|
||||
process = Mock(returncode=7)
|
||||
|
||||
Reference in new issue
Block a user