Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,24 @@ def pytest_runtest_protocol(self, item, nextitem):


def _report_yeto_home(session) -> None:
"""End of the outermost session: a refused write to the real ~/.yeto fails it; an entry
there that is new or changed since the start (a child process, or another process on
this machine) is a warning."""
"""End of the outermost session: a refused write to the real ~/.yeto or ~/yeto-output
(in this process, or a child named it) fails it; an entry there that is new or changed
since the start (a child process, or another process on this machine) is a warning."""
errors, warnings = _home_guard.session_report()
tr = session.config.pluginmanager.get_plugin("terminalreporter")
write = (lambda line: tr.write_line(line)) if tr is not None else print
if tr is not None and (errors or warnings):
tr.ensure_newline()
if warnings:
write(f"WARNING real ~/.yeto changed during the session ({len(warnings)} entries; not from this "
"process: a child process, or another run / test session on this machine):")
write(f"WARNING real ~/.yeto or ~/yeto-output changed during the session ({len(warnings)} entries; "
"not from this process: a child process, or another run / test session on this machine):")
for line in warnings[:_home_guard.WARN_LIST_MAX]:
write(f" {line}")
if len(warnings) > _home_guard.WARN_LIST_MAX:
write(f" ... {len(warnings) - _home_guard.WARN_LIST_MAX} more")
if errors:
write(f"ERROR tests tried to write the real ~/.yeto ({len(errors)} refused; tests/yeto_home_guard.py):")
write(f"ERROR tests tried to write the real ~/.yeto or ~/yeto-output ({len(errors)} refused; "
"tests/yeto_home_guard.py):")
for line in errors[:_home_guard.WARN_LIST_MAX]:
write(f" {line}")
if len(errors) > _home_guard.WARN_LIST_MAX:
Expand Down
15 changes: 9 additions & 6 deletions tests/test_prod_defaults_argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ def _entry_argv(run: str, env: dict, module: str = MILES_ENTRY) -> list[str]:
return [env.get(t[1:], t) if t.startswith("$") and t[1:].isidentifier() else t for t in tokens]


def _island_parses(run: str, env: dict, monkeypatch, capsys) -> types.SimpleNamespace:
def _island_parses(run: str, env: dict, monkeypatch, capsys, tmp_path) -> types.SimpleNamespace:
"""The island's parser and its compat group, with only ``env`` of what this process
has from conftest (the island runs elsewhere)."""
has from conftest (the island runs elsewhere). Its event tape (``~/yeto-output`` of
the island's node) is written under ``tmp_path``, not this host's home."""
from yeto.hw.catalog import COMPAT_GROUP_ENV
from yeto.rl.adapters.miles import island_entry

Expand All @@ -174,6 +175,8 @@ def _island_parses(run: str, env: dict, monkeypatch, capsys) -> types.SimpleName
args = island_entry.parse_args(argv)
except SystemExit as stop:
raise AssertionError(f"the island entry refused its argv: {capsys.readouterr().err[-2000:]}") from stop
if getattr(args, "event_tape", None):
args.event_tape = str(tmp_path / Path(args.event_tape).name)
group = island_entry._island_compat_group(args)
return types.SimpleNamespace(args=args, group=group, argv=argv)

Expand All @@ -199,7 +202,7 @@ def test_the_customer_modal_island_entry_parses_with_only_its_own_environment(tm
spec, task = _island_task(args)
assert spec.cloud == "modal"
cfg = build_modal_island_config(args, spec, 0, task, "10.0.0.1:29400")
island = _island_parses(cfg.run_script, {**cfg.envs, "LEARNER_ID": "0"}, monkeypatch, capsys)
island = _island_parses(cfg.run_script, {**cfg.envs, "LEARNER_ID": "0"}, monkeypatch, capsys, tmp_path)
assert island.group == "nvidia-b300"
assert island.args.rl_single_island_no_sync and island.args.inner_lr == float(args.inner_lr)

Expand All @@ -218,7 +221,7 @@ def test_the_customer_ssh_island_entry_parses_with_only_the_node_environment(cas
env = sti.node_env(ssh_spec, 0, {})
script = sti.start_script(ssh_spec, 0, env, sti.remote_paths("r", "island-0", 0), container="c0")
assert "export YETO_RL_COMPAT_GROUP=nvidia-b300" in script # the node's job gets it
island = _island_parses(ssh_spec.run_script, {**env, "LEARNER_ID": "0"}, monkeypatch, capsys)
island = _island_parses(ssh_spec.run_script, {**env, "LEARNER_ID": "0"}, monkeypatch, capsys, tmp_path)
assert island.group == "nvidia-b300"


Expand Down Expand Up @@ -343,7 +346,7 @@ def test_each_fleet_island_launch_passes_with_production_defaults(example, tmp_p
spec, task = _island_task(args)
modal = build_modal_island_config(args, spec, 0, task, "10.0.0.1:29400")
parsed = _island_parses(modal.run_script, {**modal.envs, "LEARNER_ID": str(island.learner)},
monkeypatch, capsys)
monkeypatch, capsys, tmp_path)
assert int(parsed.args.learner_id) == island.learner
assert parsed.group == "nvidia-h100"
assert asked["hub"]
Expand All @@ -368,7 +371,7 @@ def test_a_sky_island_entry_parses_with_only_the_task_environment(tmp_path, monk
assert spec.cloud == "aws"
envs = {**task.envs, **{k: str(v) for k, v in (getattr(task, "secrets", None) or {}).items()}}
parsed = _island_parses(task.run, {**envs, "LEARNER_ID": "0", "SYNCER_ADDR": "10.0.0.1:29400"},
monkeypatch, capsys)
monkeypatch, capsys, tmp_path)
assert parsed.group == "nvidia-h100"


Expand Down
3 changes: 3 additions & 0 deletions tests/test_rl_algorithm_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ def test_modal_two_islands_with_syncer_rebuild_tapes_and_fail_closed(monkeypatch
from yeto.rl import event_echo

monkeypatch.setattr(runs, "RUNS_DIR", tmp_path / "runs")
# the teardown copies the dispenser log of a syncer on this machine (~/yeto-output):
# this run's machine is the test's own home, not the developer's
monkeypatch.setenv("HOME", str(tmp_path / "home"))

def island_log(island, finalized):
lines = ["[x] startup noise"]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_rl_dense_sweep_real_syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from free_ports import free_port
from process_groups import group_popen, kill_group
from test_rl_algorithm_provenance import _fake_sky, _launcher_args, _no_modal_listing # noqa: F401
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.fragments import MERGE_RDA, Fragment, FragmentLayout
from yeto.protocol import (
DTYPE_F32,
Expand Down Expand Up @@ -74,7 +75,8 @@ def _start_syncer(binary: Path, tmp_path: Path, *extra: str,
command = (command
.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
assert "--policy-sweep-fragments 2" in command and "--require-profile-binding" in command
process = group_popen(["bash", "-c", command], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, text=True)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_rl_hetero_sim_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from process_groups import group_popen, kill_group
from test_rl_algorithm_provenance import _fake_sky, _no_modal_listing # noqa: F401
from test_rl_algorithm_provenance import _launcher_args as _provenance_launcher_args
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.rl.adapters.miles import buffer_rollout as br
from yeto.rl.adapters.sampler_engines.fake import (FAKE_IDENTITY, FakeEngine, _unit, fake_identity,
fake_sampler_fleet)
Expand Down Expand Up @@ -133,7 +134,8 @@ def _start_decoupled_syncer(binary, workdir, islands, total_steps, *options):
port = free_port()
command = (command.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(workdir / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(workdir / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(workdir / "tape.jsonl"))
.replace(DISPENSE_LOG, str(workdir / "task-dispense.jsonl")))
log = (workdir / "syncer.log").open("w")
process = group_popen(["bash", "-c", command], stdout=log, stderr=subprocess.STDOUT, text=True)
return process, port, layout, command
Expand Down
10 changes: 9 additions & 1 deletion tests/test_rl_hf_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ def write(rollout_id, directory):


# ---------------------------------------------------------------- Miles wiring
def test_miles_island_writes_with_every_rank_on_one_node_else_rank0(tmp_path):
def test_miles_island_writes_with_every_rank_on_one_node_else_rank0(tmp_path, monkeypatch):
import tempfile

from yeto.rl.adapters.miles.entry import hf_exports_for
from yeto.rl.adapters.miles.release_plugin import WRITE_FULL_CHECKPOINT

Expand All @@ -341,6 +343,9 @@ def test_miles_island_writes_with_every_rank_on_one_node_else_rank0(tmp_path):
export_hf=lambda rollout_id, path: calls.append(("export_hf", rollout_id, path)))
runner = SimpleNamespace(run=lambda value: value)
config = {"rounds": "2,final", "store": str(tmp_path / "hf")}
system_tmp = tmp_path / "system-tmp"
system_tmp.mkdir()
monkeypatch.setattr(tempfile, "tempdir", str(system_tmp))
assert hf_exports_for(SimpleNamespace(), actor_model=actor, runner=runner) is None
exports = hf_exports_for(SimpleNamespace(yeto_rl_hf_exports=config, actor_num_nodes=1, lora_rank=0),
actor_model=actor, runner=runner, environ={})
Expand All @@ -352,6 +357,9 @@ def test_miles_island_writes_with_every_rank_on_one_node_else_rank0(tmp_path):
actor_model=actor, runner=runner, environ={})
across.write(1, tmp_path / "d")
assert calls == [("export_hf", 1, str(tmp_path / "d"))]
# each island process stages in a directory of its own under the system temp dir
assert exports.staging != across.staging and {exports.staging.parent, across.staging.parent} == {system_tmp}
assert exports.staging.name.startswith("yeto-hf-export-") and exports.staging.is_dir()
with pytest.raises(ValueError, match="full weights"):
hf_exports_for(SimpleNamespace(yeto_rl_hf_exports=config, lora_rank=8), actor_model=actor, runner=runner)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_rl_k31_synced_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from process_groups import group_popen, kill_group
from test_rl_algorithm_provenance import _fake_sky, _launcher_args, _no_modal_listing # noqa: F401
from test_rl_k31_e2e_cpu import EP, MOE_LAYERS, NUM_EXPERTS, NUM_TRAINABLE, Bucket, _hf_config
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.rl.adapters.miles import island_entry, pins
from yeto.rl.adapters.miles.models.kimi_k31 import release as k31_release
from yeto.rl.adapters.miles.models.partial_experts import selection as sel
Expand Down Expand Up @@ -500,7 +501,8 @@ def _start_syncer(binary: Path, tmp_path: Path, learners: int):
port = free_port()
command = (command.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
assert f"--learners {learners} --quorum 1" in command and "--outer-lr 1.0 --outer-momentum 0.0" in command
log_file = tmp_path / "syncer.log"
with log_file.open("w") as out:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_rl_split_parameter_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)

from test_rl_algorithm_provenance import _fake_sky, _launcher_args, _no_modal_listing # noqa: F401
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.fragments import MERGE_AVG, MERGE_RDA
from yeto.protocol import DTYPE_F32, DTYPE_F32_PUSH_I8, DTYPE_FLAG_TENSOR_BLOCKS, SyncerClient
from yeto.rl.adapters.miles.models.chunked_full_parameter import (
Expand Down Expand Up @@ -233,7 +234,8 @@ def _start_syncer(binary: Path, tmp_path: Path, fragments: int, *extra: str):
command = (command
.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
process = group_popen(["bash", "-c", command], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, text=True)
return process, port, launcher.rl_syncer_profile(args, LEARNERS).sha256
Expand Down
4 changes: 3 additions & 1 deletion tests/test_rl_sync_route_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
syncer_binary, # noqa: F401
)
from test_rl_k31_synced_cpu import STORE, _island_hmac_key, _selection, _tis_spec # noqa: F401
from yeto.launch.dispense_evidence import DISPENSE_LOG

LAYOUT = "e" * 64
TWO = "modal:2xh100,modal:2xh100"
Expand Down Expand Up @@ -213,7 +214,8 @@ def _routed_syncer(binary, tmp_path, *, total_steps: int):
port = free_port()
command = (command.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
log = tmp_path / "syncer.log"
with log.open("w") as out:
process = group_popen(["bash", "-c", command], stdout=out, stderr=subprocess.STDOUT, text=True)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_rl_syncer_kill_resume_live_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SHAPES, _layout, _plan, _run_island, needs_cargo, syncer_binary,
)
from test_rl_algorithm_provenance import _launcher_args
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.final_marker import read_checkpoint_global_step
from yeto.rl.engine.full_parameter_stream import LAZY_CAPTURE_ENV

Expand All @@ -49,7 +50,8 @@ def _syncer_command(binary, tmp_path, *, fragments: int, rounds: int, port: int)
command = launcher.role_syncer_commands(args, 2, binary=str(binary))["actor"]
command = (command.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
assert "--resume" in command and "--checkpoint-every 1" in command
return command, launcher.rl_syncer_profile(args, 2).sha256

Expand Down
10 changes: 7 additions & 3 deletions tests/test_rl_verl_megatron.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,21 +715,25 @@ def save_hf_weights(self, module, path):

worker = SimpleNamespace(actor=SimpleNamespace(engine=SimpleNamespace(module=[object()], bridge=_Bridge())))
store = tmp_path / "store"
config = {"rounds": "1,final", "store": str(store)}
# the driver names the island's staging directory; every rank gets the name
drivers = [mp.MegatronHfExports(SimpleNamespace(), {"rounds": "1,final", "store": str(store)}) for _ in range(2)]
names = [driver.config["staging"] for driver in drivers]
assert names[0] != names[1] and all(name.startswith(f"{mp.HF_STAGING}-") for name in names)
config = drivers[0].config
record = mp.remote_hf_export(worker, config, 0, 1, True, str(model))
assert record["ok"] and record["round"] == 1 and record["files"] == 3, record
out = store / "round-1"
assert (out / ".complete").is_file() and (out / "config.json").is_file()
assert (out / "model-00001-of-00001.safetensors").read_bytes() == b"w" * 8
assert not (out / "model-00001-of-00013.safetensors").exists()
assert json.loads((store / "final.json").read_text())["path"] == "round-1"
assert not (staging_root / mp.HF_STAGING / "round-1").exists() # the staging copy is deleted
assert (staging_root / names[0]).is_dir() and not (staging_root / names[0] / "round-1").exists() # deleted

monkeypatch.setattr(torch.distributed, "is_initialized", lambda: True)
monkeypatch.setattr(torch.distributed, "get_rank", lambda: 3)
monkeypatch.setattr(torch.distributed, "barrier", lambda: None)
assert mp.remote_hf_export(worker, config, 1, 2, False, str(model)) is None
joined = staging_root / mp.HF_STAGING / "round-2"
joined = staging_root / names[0] / "round-2"
assert (joined / "model-00001-of-00001.safetensors").is_file()
assert not (joined / ".complete").exists() and not (joined / "config.json").exists()

Expand Down
4 changes: 3 additions & 1 deletion tests/test_verl_decoupled.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from test_rl_algorithm_provenance import _fake_sky, _launcher_args, _no_modal_listing # noqa: F401
from test_verl_full_parameter_sync import needs_cargo, syncer_binary # noqa: F401 - fixture
from verl_island_fakes import ISLAND_ARGV, drive_trainer, modules, run_island_entry, stub_verl_and_ray
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.rl.adapters.verl import decoupled_session as ds
from yeto.rl.adapters.verl import island_entry
from yeto.rl.adapters.verl.publish import lora_checksum
Expand Down Expand Up @@ -296,7 +297,8 @@ def test_two_launcher_built_verl_islands_run_decoupled_fragments_through_the_rea
command = (launcher.role_syncer_commands(args, 2, binary=str(syncer_binary))["actor"]
.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
plans = []
for learner_id in range(2):
parsed, _ignored = island_entry.parse_args(_island_argv(args, learner_id, f"127.0.0.1:{port}"))
Expand Down
4 changes: 3 additions & 1 deletion tests/test_verl_full_parameter_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from test_verl_full_parameter_sync import ( # noqa: F401 - syncer_binary is a fixture
MAX_FRAGMENT_BYTES, SHAPES, _run_dict, _run_island, needs_cargo, syncer_binary,
)
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.rl.adapters.verl import full_parameter as fp
from yeto.rl.adapters.verl import full_parameter_stream as vfs
from yeto.rl.adapters.verl import island_entry
Expand Down Expand Up @@ -226,7 +227,8 @@ def test_two_launcher_built_verl_islands_run_async_rounds_through_the_real_synce
command = (launcher.role_syncer_commands(args, 2, binary=str(syncer_binary))["actor"]
.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
assert "--final-cut-payload manifest" in command and "--quorum 1" in command
plans = []
for learner_id in range(2):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_verl_full_parameter_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from free_ports import free_port
from process_groups import group_popen, kill_group
from test_rl_algorithm_provenance import _fake_sky, _launcher_args, _no_modal_listing # noqa: F401
from yeto.launch.dispense_evidence import DISPENSE_LOG
from yeto.protocol import MSG_BCAST_FRAGMENT
from yeto.rl.adapters.verl import full_parameter as fp
from yeto.rl.adapters.verl import full_parameter_stream as vfs
Expand Down Expand Up @@ -377,7 +378,8 @@ def _start_syncer(binary: Path, tmp_path: Path, *, fragments: int, rounds: int,
port = free_port()
command = (command.replace(f"--port {launcher.SYNCER_PORT}", f"--port {port}")
.replace(launcher.RL_SYNCER_CHECKPOINT, str(tmp_path / "state.ckpt"))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl")))
.replace(launcher.RL_SYNCER_EVENT_TAPE, str(tmp_path / "tape.jsonl"))
.replace(DISPENSE_LOG, str(tmp_path / "task-dispense.jsonl")))
process = group_popen(["bash", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
return process, port, launcher.rl_syncer_profile(args, 2).sha256

Expand Down
Loading
Loading