From 4df906e528b617695e259d5b4c3459906d17b143 Mon Sep 17 00:00:00 2001 From: Michael Chung Date: Fri, 27 Nov 2026 04:38:54 +0800 Subject: [PATCH 1/2] fleet follow-ups: shape-free advice, unparsable running records, copy record checks - The shape check offers --rl-sync-layout shape-free only where it helps: for Miles full-parameter islands whose placements differ it names the same nodes x GPUs per node instead (shape-free keeps the placement in the contract). - yeto fleet island add/move: a running island whose recorded launch (written when its incarnation started) does not compile is refused by default, naming why and the ways out; --allow-unparsable-running makes it a WARN for that case only. The MOVING / STOPPING comparison is documented. - fleet.store.json: a record that does not parse is a WARN and counts as none (the next copy starts at the file's start, yeto down copies nothing); the store copy never fails a launch. The run identity names the run directory, so a copied run directory never copies into the original's store. - Docs: a relaunched island of a per-island fleet is a new run; a killed launcher may leave its last upload interval only in the local file. Co-Authored-By: Claude Opus 5.5 --- docs/DASHBOARD.md | 12 +++- docs/FLEET_TRAINER_ISLANDS.md | 12 +++- tests/test_fleet_islands_placement.py | 75 ++++++++++++++++++++++- tests/test_fleet_log_store.py | 88 +++++++++++++++++++++++++++ yeto/dashboard/fleet_store.py | 85 ++++++++++++++++++++------ yeto/launch/manifest.py | 25 ++++---- yeto/rl/fleet_islands.py | 21 +++++-- yeto/rl/fleet_session.py | 44 +++++++++++--- 8 files changed, 312 insertions(+), 50 deletions(-) diff --git a/docs/DASHBOARD.md b/docs/DASHBOARD.md index aed0f7601..b4f7ec0e2 100644 --- a/docs/DASHBOARD.md +++ b/docs/DASHBOARD.md @@ -225,7 +225,17 @@ store and the offset the copy starts at. A restarted launcher of the run goes on from that offset; a later run of the name starts at the file's end, and a launch that does not copy the file voids the record (no store from the file's end on). `yeto down` copies the `island_stop` lines it appends for islands a killed -launcher left open, only into the store the record of this run names. The copy is observation only: a failed upload is a +launcher left open, only into the store the record of this run names; the run is +named by its directory name and its registry start, so a copy of a run directory +under another name never copies into the original's store. A record that does not +parse (not JSON, a field missing, a start that is not a byte offset) is a `WARN` +line and counts as none: the next copy starts at the file's start (the readers +fold each record once) and `yeto down` copies nothing for it; it never fails a +launch. An island launch of a per-island fleet that its trainer worker starts +again is a new run (the new incarnation's cluster prefix and registry entry), so +its copy starts afresh. A launcher killed outright (`kill -9`) may leave the lines +of its last upload interval (under 30 s) only in the local file: they are +observation data, and nothing else depends on them. The copy is observation only: a failed upload is a `WARN` line, retried with the next chunk, and the launcher's end (and `yeto down`) waits at most 15 s for the last one. A launch of one trainer island uploads nothing, as before. `--store` reads every folder next to the island tapes, and a diff --git a/docs/FLEET_TRAINER_ISLANDS.md b/docs/FLEET_TRAINER_ISLANDS.md index 6e0b842b6..0cc9490b4 100644 --- a/docs/FLEET_TRAINER_ISLANDS.md +++ b/docs/FLEET_TRAINER_ISLANDS.md @@ -165,9 +165,19 @@ yeto fleet show --config run.json | Exit | Meaning | |---|---| | 0 | Written (or, with `--dry-run`, the change is valid). | -| 2 | Refused, nothing written: a bad name or samplers file, no learner id left, no `--usd-per-h` while the run has a budget, a trainer shape that differs from the fleet's, an island's launch that fails its dry run. | +| 2 | Refused, nothing written: a bad name or samplers file, no learner id left, no `--usd-per-h` while the run has a budget, a trainer shape that differs from the fleet's, an island's launch that fails its dry run, a running island whose recorded launch does not compile (see below). | | 3 | The desired state changed under the command three times in a row. Run it again. | +`add` and `move` compare the island with the running ones as they were started: a +starting or running island's trainer worker record holds the launch it was started with. +That record is written when the island's incarnation starts, so changing the config does +not change it. When it no longer compiles (an option removed since, a file it read gone), +the change is refused: pass `--allow-unparsable-running` to check without that island (a +`WARN`), or stop or remove that island first (`yeto fleet island remove --name `). +The option covers only a recorded launch; an island whose desired launch does not compile +is refused until its config is fixed. A moving or stopping island is compared as the desired +state has it (for a move, its new target). + ### Adding an island 1. Write the island's samplers list to a file, for example `north.samplers.json`. Use the diff --git a/tests/test_fleet_islands_placement.py b/tests/test_fleet_islands_placement.py index 95d2bbcab..0a559ab4f 100644 --- a/tests/test_fleet_islands_placement.py +++ b/tests/test_fleet_islands_placement.py @@ -97,6 +97,30 @@ def test_islands_of_two_shapes_keep_the_shape_message_alone(): ["a", "b"]) assert len(problems) == 1 and SHAPE in problems[0] and PLACEMENT not in problems[0] assert "DP4, island a (learner 0) trains on TP1 PP1 EP1 CP1 DP8" in problems[0] + # their placements differ too: a shape-free layout would not help, so it is not offered + assert "or set --rl-sync-layout shape-free" not in problems[0] + assert "the same nodes x GPUs per node and parallel flags" in problems[0] and "does not help here" in problems[0] + + +@pytest.mark.parametrize("extra", [ + # one placement (per-island placement: TP2 on the same machines): shape-free takes the shape out + [*FLEET, "--rl-island-placement", "1:tensor-parallel=2", "--gpu", f"{ONE_BY_EIGHT},{ONE_BY_EIGHT}"], + # an island that binds no placement (verl): shape-free is the way out it was + [*FLEET, "--rl-backend", "verl", "--gpu", f"{ONE_BY_EIGHT},nebius:1x4xh100"], +], ids=["per-island-placement", "verl"]) +def test_shape_free_is_offered_where_it_helps(extra): + from yeto.rl.fleet_session import LaunchSession, shape_problems + from yeto.rl.up_consistency import trainer_args as parsed + + found = fleet_session.synced_shape_problems([*BASE, *extra], ["a", "b"]) + if not found: # a launch whose layout is not shape-bound: the shape check itself, with shapes given + args = parsed([*BASE, *extra]) + placements = fleet_session.launch_placements_of(args) or [None, None] + found = shape_problems([LaunchSession(name=n, learner_id=i, profile={}, profile_sha256="", learners=0, + hello="", syncer_epoch=0, max_learners=None, shape=shape, + placement=placements[i]) + for i, (n, shape) in enumerate(zip("ab", [(1, 1, 1, 1, 8), (1, 1, 1, 1, 4)]))]) + assert len(found) == 1 and "or set --rl-sync-layout shape-free for the whole fleet" in found[0] def test_each_island_is_compared_with_the_first_of_its_shape(): @@ -353,12 +377,59 @@ def test_a_move_is_compared_with_the_running_island_as_it_was_started(fleet_stor assert "compat_group nvidia-h100" in err and "nvidia-h200" in err and "island(s) mixed" in err -def test_a_stopped_island_s_record_is_not_its_running_launch(fleet_store): # noqa: F811 +@pytest.mark.parametrize("state", ["down", "moving", "stopping"]) +def test_a_record_that_is_not_a_running_launch_is_not_compared(fleet_store, state): # noqa: F811 + """DOWN, MOVING, STOPPING: the desired state's member is compared (for MOVING its new target).""" _cfg, objects, store, run_cli, _ = fleet_store - _started(objects, store, "mixed", "modal:1x2xh200", state="down") + _started(objects, store, "mixed", "modal:1x2xh200", state=state) assert run_cli("move", "--name", "sglang", "--gpu", "modal:1x2xh100", "--usd-per-h", "4", "--dry-run") == 0 +def _unparsable(objects, store, name="mixed"): + from yeto.launch.pool import desired as dz + from yeto.rl import trainer_worker + + member = dz.trainers(store.read())[name] + trainer_worker.save_record(objects, int(member["learner_id"]), { + "name": name, "prefix": member["prefix"], "state": "running", + "argv": ["--training-mode", "rl", "--no-such-flag"]}, 0.0) + + +@pytest.mark.parametrize("moved", ["sglang", "mixed"], ids=["another-island", "the-island-itself"]) +def test_an_unparsable_running_record_is_refused_unless_allowed(fleet_store, capsys, moved): # noqa: F811 + """mixed's recorded launch does not compile: a move of another island, or of mixed itself + (its old machines), is refused by default with the reason and both ways out; the narrow + --allow-unparsable-running makes it a WARN and the change goes on.""" + from yeto.rl import island_launches as il + + _cfg, objects, store, run_cli, _ = fleet_store + _unparsable(objects, store) + # a syncer holds the session: a moved island's old machines are compared too + il.write_syncer_record(objects, addr="SYNCER:29400", syncer_epoch=None, learners=2, max_learners=4, run="r") + before = store.read()["generation"] + move = ("move", "--name", moved, "--gpu", "modal:1x2xh100", "--usd-per-h", "4") + capsys.readouterr() + assert run_cli(*move) == 2 + err = capsys.readouterr().err + assert "island mixed" in err and "its launch as started does not compile" in err + assert "written when the incarnation started: a changed config does not change it" in err + assert "Pass --allow-unparsable-running" in err and "yeto fleet island remove --name mixed)" in err + assert store.read()["generation"] == before + assert run_cli(*move, "--allow-unparsable-running", "--dry-run") == 0 + err = capsys.readouterr().err + assert "fleet session: WARN:" in err and "the island is left out of the comparison" in err + + +def test_the_narrow_way_out_does_not_cover_an_island_whose_desired_launch_does_not_compile(tmp_path): + """--allow-unparsable-running is about a recorded launch only: a running member rebuilt + from the desired state that does not compile stays a refusal (its config is to be fixed).""" + cfg, members = _members(tmp_path) + with pytest.raises(ValueError, match="fix that island's configuration"): + fleet_session.check(cfg["trainer"]["argv"], [members[0]], + running=[{**members[0], "name": "broken", "gpu": "nowhere:9xq"}], + allow_unparsable_running=True) + + def test_a_running_island_whose_launch_does_not_compile_refuses_the_change(fleet_store, capsys): # noqa: F811 _cfg, objects, store, run_cli, _ = fleet_store from yeto.launch.pool import desired as dz diff --git a/tests/test_fleet_log_store.py b/tests/test_fleet_log_store.py index bb38e83d1..62d9c68e2 100644 --- a/tests/test_fleet_log_store.py +++ b/tests/test_fleet_log_store.py @@ -694,3 +694,91 @@ def test_the_store_status_is_ok_since_the_oldest_clean_poll(): status = failed.status() assert (status["last_error"], status["last_error_at"], status["errors"], status["failing"]) == ("new", 5.0, 3, 1) assert fleet_store.StoreReaders(_Status(), _Status(polled=False)).status()["polled"] is False + + +# -- a corrupt copy record ------------------------------------------------------------------------- + +CORRUPT = { + "start-not-int": json.dumps({"schema": fleet_store.COPY_SCHEMA, "store": "s3://x", "start": "12", "run": None}), + "start-bool": json.dumps({"schema": fleet_store.COPY_SCHEMA, "store": "s3://x", "start": True, "run": None}), + "start-negative": json.dumps({"schema": fleet_store.COPY_SCHEMA, "store": "s3://x", "start": -1, "run": None}), + "not-json": "{not json", + "not-an-object": "[1, 2]", + "no-start": json.dumps({"schema": fleet_store.COPY_SCHEMA, "store": "s3://x", "run": None}), + "no-run": json.dumps({"schema": fleet_store.COPY_SCHEMA, "store": "s3://x", "start": 0}), + "other-schema": json.dumps({"schema": "x/v9", "store": "s3://x", "start": 0, "run": None}), +} + + +@pytest.mark.parametrize("text", CORRUPT.values(), ids=CORRUPT.keys()) +def test_a_corrupt_record_is_no_record_and_the_copy_starts_at_the_file_s_start(tmp_path, text, capsys): + path = tmp_path / "r" / "fleet.jsonl" + path.parent.mkdir() + path.write_bytes(_text(A_ROWS)) + fleet_store.copy_record_path(path).write_text(text) + assert fleet_store.read_copy_record(path) is None + assert "fleet.store.json is corrupt" in capsys.readouterr().err + assert fleet_store.copy_start(path, "s3://x", run="r@1.0") == 0 + err = capsys.readouterr().err + assert err.count("WARN") == 1 and "the copy starts at the file's start" in err + assert fleet_store.read_copy_record(path)["start"] == 0 # a sound record from here on + + +def test_a_launch_with_a_corrupt_record_copies_the_whole_file(tmp_path, monkeypatch, capsys): + monkeypatch.setattr("yeto.runs.run_dir", lambda run: tmp_path / run) + store = tmp_path / "s" + path = tmp_path / "run-i1" / "fleet.jsonl" + path.parent.mkdir() + path.write_bytes(_text(A_ROWS)) # an earlier launch's lines + fleet_store.copy_record_path(path).write_text(CORRUPT["start-not-int"]) + _new_run() + log = _launch(tmp_path, store) + assert log.uploader is not None and log.close() is True + assert _uploaded(store) == log.path.read_bytes() # from 0: the readers fold each record once + assert "is corrupt" in capsys.readouterr().err + + +def test_a_failing_record_read_never_fails_the_launch(tmp_path, monkeypatch, capsys): + monkeypatch.setattr("yeto.runs.run_dir", lambda run: tmp_path / run) + + def broken(path): + raise RuntimeError("disk on fire") + + monkeypatch.setattr(fleet_store, "_load_copy_record", broken) + assert fleet_store.copy_start(tmp_path / "x" / "fleet.jsonl", "s3://x", run="r@1.0") == 0 + monkeypatch.setattr(fleet_store, "copy_start", lambda *a, **k: (_ for _ in ()).throw(RuntimeError("boom"))) + _new_run() + log = _launch(tmp_path, tmp_path / "s") # the launch goes on, its fleet.jsonl local + assert log is not None and log.uploader is None and _records(log.path)[-1]["event"] == "island_ready" + assert "store copy disabled: RuntimeError: boom" in capsys.readouterr().err + + +def test_yeto_down_with_a_corrupt_record_copies_nothing(tmp_path, monkeypatch, capsys): + cli, path, store = _down_run(tmp_path, monkeypatch) + fleet_store.copy_record_path(path).write_text(CORRUPT["not-json"]) + assert cli._close_fleet_islands("r") == [ISLAND] # noqa: SLF001 + assert not store.exists() and "is corrupt" in capsys.readouterr().err + + +# -- a copied run directory ------------------------------------------------------------------------ + +def test_yeto_down_of_a_copied_run_directory_leaves_the_original_s_store_alone(tmp_path, monkeypatch): + """The run directory copied under another name (meta.json, fleet.jsonl and its copy record + with it): the copy's yeto down copies nothing into the original run's store; the + original's does.""" + import shutil + + from yeto import cli + + monkeypatch.setattr("yeto.runs.run_dir", lambda run: tmp_path / run) + s1 = tmp_path / "s1" + _new_run() + log = _launch(tmp_path, s1) # the island stays open: its launcher is gone + assert log.close() is True + shutil.copytree(tmp_path / "run-i1", tmp_path / "run-copy") + assert fleet_store.run_identity("run-copy") != fleet_store.run_identity("run-i1") + before = _folders(s1) + assert cli._close_fleet_islands("run-copy") == [ISLAND] # noqa: SLF001 + assert _folders(s1) == before + assert cli._close_fleet_islands("run-i1") == [ISLAND] # noqa: SLF001 + assert len(_folders(s1)) == len(before) + 1 # the original's island_stop line diff --git a/yeto/dashboard/fleet_store.py b/yeto/dashboard/fleet_store.py index ace84e04d..94c0ecab3 100644 --- a/yeto/dashboard/fleet_store.py +++ b/yeto/dashboard/fleet_store.py @@ -88,22 +88,56 @@ def copy_record_path(path: str | os.PathLike) -> Path: return Path(path).with_name(COPY_RECORD) -def read_copy_record(path: str | os.PathLike) -> dict | None: +def _load_copy_record(path: str | os.PathLike) -> tuple[dict | None, str | None]: + """(the copy record, None), (None, None) without one, or (None, why) for a record that is + not one this module writes (not JSON, a field missing, a start that is no byte offset).""" try: - doc = json.loads(copy_record_path(path).read_text(encoding="utf-8")) - except (OSError, ValueError): - return None - return doc if isinstance(doc, dict) and doc.get("schema") == COPY_SCHEMA and doc.get("store") else None - - -def run_identity(name: str) -> float | None: - """The run of ``name`` the copy record names: its run registry ``started_at`` (set anew by - every run of the name, kept by its launcher restarts and its ``yeto down``), or None.""" + text = copy_record_path(path).read_text(encoding="utf-8") + except FileNotFoundError: + return None, None + except OSError as exc: + return None, f"not readable ({type(exc).__name__})" + try: + doc = json.loads(text) + except ValueError: + return None, "not JSON" + if not isinstance(doc, dict): + return None, "not a JSON object" + missing = [key for key in ("schema", "store", "start", "run") if key not in doc] + if missing: + return None, f"no {', '.join(missing)}" + if doc["schema"] != COPY_SCHEMA: + return None, f"schema {str(doc['schema'])[:40]!r}" + if type(doc["start"]) is not int or doc["start"] < 0: + return None, f"start {str(doc['start'])[:40]!r} is not a byte offset" + if doc["store"] is not None and not isinstance(doc["store"], str): + return None, "store is not a string" + return doc, None + + +def _corrupt(why: str, then: str, log: Callable[[str], None]) -> None: + log(f"WARN: fleet.jsonl store copy: {COPY_RECORD} is corrupt ({why}): taken as no record; {then}") + + +def read_copy_record(path: str | os.PathLike, *, log: Callable[[str], None] | None = None) -> dict | None: + """The copy record of ``path`` when it names a store; None without one, for a voided one + (:func:`copy_off`) and for a corrupt one (a WARN line).""" + doc, why = _load_copy_record(path) + if why is not None: + _corrupt(why, "nothing is copied for it", log or _stderr) + return doc if doc is not None and doc.get("store") else None + + +def run_identity(name: str) -> str | None: + """The run of ``name`` the copy record names: ``@``, the run registry's + ``started_at`` (set anew by every run of the name, kept by its launcher restarts and its + ``yeto down``) with the name, so a run directory copied under another name is not its + original; None without a registry entry.""" try: from yeto import runs # noqa: PLC0415 started = (runs.load_run(name) or {}).get("started_at") - return float(started) if started is not None else None + return f"{name}@{float(started)!r}" if started is not None else None except Exception: # noqa: BLE001 - telemetry never stops a launch or a down return None @@ -123,22 +157,33 @@ def _write_record(p: Path, doc: dict) -> None: _stderr(f"[launcher] WARN: fleet.jsonl store copy: {COPY_RECORD} not written ({type(exc).__name__})") -def copy_start(path: str | os.PathLike, store: str, *, learner_id: Any = None, run: float | None = None) -> int: +def copy_start(path: str | os.PathLike, store: str, *, learner_id: Any = None, run: str | None = None, + log: Callable[[str], None] | None = None) -> int: """The byte offset of ``path`` this launch's copy into ``store`` starts at (see above), recorded for the next launch and for ``yeto down``. ``run``: :func:`run_identity` (None: - the file's end). Never raises (a record that cannot be written: the offset still holds for - this launch).""" + the file's end). A corrupt record (a WARN) is taken as none, but the copy starts at the + file's start: where this run's lines begin is unknown, and the readers fold each record + once. Never raises (a record that cannot be written: the offset still holds for this launch).""" p = Path(path) size = _size(p) - known = read_copy_record(p) - same = known is not None and known.get("store") == str(store) and run is not None and known.get("run") == run - start = min(int(known.get("start") or 0), size) if same else size + try: + known, why = _load_copy_record(p) + if why is not None: + _corrupt(why, "the copy starts at the file's start", log or _stderr) + start = 0 + else: + same = (known is not None and known.get("store") == str(store) and run is not None + and known.get("run") == run) + start = min(known["start"], size) if same else size + except Exception as exc: # noqa: BLE001 - telemetry never stops a launch + _corrupt(type(exc).__name__, "the copy starts at the file's start", log or _stderr) + start = 0 _write_record(p, {"schema": COPY_SCHEMA, "store": str(store), "start": start, "run": run, "learner_id": learner_id if lane(learner_id) != FLEET_LANE else None}) return start -def copy_off(path: str | os.PathLike, *, run: float | None = None) -> None: +def copy_off(path: str | os.PathLike, *, run: str | None = None) -> None: """A launch that does not copy ``path`` (no store, no island records, the copy turned off): its record, if any, names no store from the file's end on, so neither ``yeto down`` nor a later launch of another run copies this launch's lines into an earlier run's @@ -190,7 +235,7 @@ def start_uploader(objects: Any, path: str | os.PathLike, *, learner_id: Any = N return None -def upload_appended(path: str | os.PathLike, offset: int, *, run: float | None = None, objects: Any = None, +def upload_appended(path: str | os.PathLike, offset: int, *, run: str | None = None, objects: Any = None, timeout_s: float | None = None, log: Callable[[str], None] = _stderr) -> bool: """``yeto down``: the lines appended to ``path`` from ``offset`` on (the ``island_stop`` of the islands a killed launcher left open) into the store its copy record names, in the @@ -199,7 +244,7 @@ def upload_appended(path: str | os.PathLike, offset: int, *, run: float | None = or without new lines. A failure is a WARN; never raises. Returns True when the store has every new line (or there is nothing to copy).""" try: - record = read_copy_record(path) + record = read_copy_record(path, log=log) if record is None or run is None or record.get("run") != run: return True size = Path(path).stat().st_size diff --git a/yeto/launch/manifest.py b/yeto/launch/manifest.py index aca6a1196..fe2499aab 100644 --- a/yeto/launch/manifest.py +++ b/yeto/launch/manifest.py @@ -119,17 +119,20 @@ def _dashboard_fleet_log(args, tasks, results, objects=None): except Exception as e: # noqa: BLE001 print(f"[launcher] fleet.jsonl disabled: {e}", file=sys.stderr) return None - from ..dashboard.fleet_store import copy_off, copy_start, run_identity, start_uploader - - store = getattr(args, "rl_checkpoint_store", None) - run = run_identity(args.cluster_prefix) - if objects is not None and store: - learner = None if member is None else member[0] - # a reused run directory: only this run's lines go to its store (fleet_store.copy_start) - log.uploader = start_uploader(objects, log.path, learner_id=learner, - offset=copy_start(log.path, str(store), learner_id=learner, run=run)) - if log.uploader is None: # no copy: a record an earlier launch left names no store from here on - copy_off(log.path, run=run) + try: # the store copy is observation only: it never fails the launch + from ..dashboard.fleet_store import copy_off, copy_start, run_identity, start_uploader + + store = getattr(args, "rl_checkpoint_store", None) + run = run_identity(args.cluster_prefix) + if objects is not None and store: + learner = None if member is None else member[0] + # a reused run directory: only this run's lines go to its store (fleet_store.copy_start) + log.uploader = start_uploader(objects, log.path, learner_id=learner, + offset=copy_start(log.path, str(store), learner_id=learner, run=run)) + if log.uploader is None: # no copy: a record an earlier launch left names no store from here on + copy_off(log.path, run=run) + except Exception as e: # noqa: BLE001 + print(f"[launcher] WARN: fleet.jsonl store copy disabled: {type(e).__name__}: {e}"[:300], file=sys.stderr) return log diff --git a/yeto/rl/fleet_islands.py b/yeto/rl/fleet_islands.py index 840c59182..de152e519 100644 --- a/yeto/rl/fleet_islands.py +++ b/yeto/rl/fleet_islands.py @@ -238,7 +238,10 @@ def _as_launched(objects: Any, member: dict[str, Any]) -> dict[str, Any]: names the launch argv and ``--gpu`` it was started with (``trainer_worker._start``), which ``fleet_session.check`` compiles (``launch_argv``) instead of the desired state's member (a move written while the old incarnation runs, an inventory or code changed since); - the member itself without such a record.""" + the member itself without such a record. In every other state, MOVING and STOPPING + included, the desired state's member is compared: for a MOVING island that is the new + target its move wrote, not the incarnation still on its old machines; for a STOPPING one + the member it is being stopped from.""" if objects is None: return member from yeto.rl import trainer_worker # noqa: PLC0415 @@ -256,7 +259,8 @@ def _as_launched(objects: Any, member: dict[str, Any]) -> dict[str, Any]: def session_check(run: Any, doc: dict[str, Any], member: dict[str, Any], - previous: dict[str, Any] | None = None, *, dry_run: bool = True) -> None: + previous: dict[str, Any] | None = None, *, dry_run: bool = True, + allow_unparsable_running: bool = False) -> None: """The island ``member`` (added or moved) against the syncer launch of the run (``yeto.rl.fleet_session``) with the term of the fleet's syncer record (the syncer launch's when there is none yet), and the desired state's other trainer islands' @@ -293,10 +297,12 @@ def session_check(run: Any, doc: dict[str, Any], member: dict[str, Any], epoch = (record or {}).get("syncer_epoch") running = [_as_launched(objects, m) for m in others] if previous is not None and (record is not None or unread is not None): - running.append(_as_launched(objects, {**previous, "name": f"{previous['name']} (its machines before the move)"})) + running.append(_as_launched(objects, {**previous, "name": f"{previous['name']} (its machines before the move)", + "island_name": previous["name"]})) try: fleet_session.check(run.trainer_argv() if hasattr(run, "trainer_argv") else run.cfg["trainer"]["argv"], - [member], syncer_epoch=epoch if isinstance(epoch, int) else None, running=running) + [member], syncer_epoch=epoch if isinstance(epoch, int) else None, running=running, + allow_unparsable_running=allow_unparsable_running) except ValueError as error: if unread is None: raise @@ -326,6 +332,10 @@ def add_parser(fsub: Any) -> None: m.add_argument("--name", required=True) m.add_argument("--gpu", required=True) m.add_argument("--usd-per-h", type=float, default=None) + for q in (a, m): + q.add_argument("--allow-unparsable-running", action="store_true", + help="a running island whose recorded launch (written when it started) does not compile: " + "check without it, with a WARN (default: refused)") for q in (a, r, m): q.add_argument("--config", required=True, help="the run config") q.add_argument("--dry-run", action="store_true", help="show the change and dry-run the launch; write nothing") @@ -371,7 +381,8 @@ def main(args: Any, *, prepare: Callable[[Any], None] | None = None) -> int: # a change that is written (not --dry-run) refuses a pinned verl layout hash it cannot plan with refuse_unverified_layout(not args.dry_run): launch_dry_run(launch_member, prepare=prepare) - session_check(run, doc, launch_member, previous, dry_run=args.dry_run) + session_check(run, doc, launch_member, previous, dry_run=args.dry_run, + allow_unparsable_running=bool(getattr(args, "allow_unparsable_running", False))) print(f"fleet island: launch of {launch_member['name']} (learner {launch_member['learner_id']}, " f"--gpu {launch_member['gpu']}) passes its dry run") except (IslandChangeError, ValueError, OSError) as error: diff --git a/yeto/rl/fleet_session.py b/yeto/rl/fleet_session.py index 6bea496ab..2f22cc2cf 100644 --- a/yeto/rl/fleet_session.py +++ b/yeto/rl/fleet_session.py @@ -38,6 +38,7 @@ import contextlib import io import re +import sys from collections.abc import Callable, Iterable from dataclasses import dataclass from typing import Any @@ -293,11 +294,18 @@ def shape_problems(islands: list[LaunchSession], running: Iterable[LaunchSession continue peer = next((p for p in peers if p.shape != island.shape), None) if peer is not None: + # a shape-free layout takes the parallel shape out of the contract, not the placement + # a Miles full-parameter island binds: on other machines it would not help + placed = island.placement is not None and peer.placement is not None and island.placement != peer.placement + way_out = ("Give every island the same nodes x GPUs per node and parallel flags (these full-parameter " + "islands also bind their placement, so --rl-sync-layout shape-free does not help here)" + if placed else + "Give every island the same shape (the same nodes x GPUs and parallel flags), or set " + "--rl-sync-layout shape-free for the whole fleet") out.append(f"{_where(island)}: trainer shape {_shape(island.shape)}, {_where(peer)} trains on " f"{_shape(peer.shape)}: the shape-bound full-parameter layout names every tensor by its " - "rank's TP/PP/EP/CP/DP position, so the syncer refuses this island's HELLO (layout " - "mismatch). Give every island the same shape (the same nodes x GPUs and parallel flags), " - "or set --rl-sync-layout shape-free for the whole fleet") + f"rank's TP/PP/EP/CP/DP position, so the syncer refuses this island's HELLO (layout " + f"mismatch). {way_out}") else: peers.append(island) return out @@ -416,15 +424,22 @@ def problems(syncer: LaunchSession, islands: Iterable[LaunchSession]) -> list[st return out +ALLOW_UNPARSABLE_RUNNING = "--allow-unparsable-running" + + def check(syncer_argv: list[str], members: Iterable[dict[str, Any]], *, syncer_epoch: int | None = None, - prepare: Callable[[Any], None] | None = None, running: Iterable[dict[str, Any]] = ()) -> None: + prepare: Callable[[Any], None] | None = None, running: Iterable[dict[str, Any]] = (), + allow_unparsable_running: bool = False) -> None: """Raise ValueError naming every disagreement between the syncer launch (``syncer_argv``) and the island launches of ``members`` (trainer members of the desired state), each compiled with the syncer record's term (``syncer_epoch``; None: the syncer launch's), and between the backend identities of ``members`` and ``running`` (the trainer members whose launches hold the fleet's running session, each with the argv it was - started with as ``launch_argv`` when known; compared with only: one whose launch does - not compile refuses the check, it cannot be compared).""" + started with as ``launch_argv`` when known; compared with only). A running launch that + does not compile cannot be compared with and refuses the check; for a recorded + ``launch_argv`` (written when that incarnation started, so a changed config does not + change it) ``allow_unparsable_running`` (:data:`ALLOW_UNPARSABLE_RUNNING`) makes that a + WARN and leaves the island out of the comparison.""" from yeto.rl import island_launches as il # noqa: PLC0415 try: @@ -446,10 +461,19 @@ def check(syncer_argv: list[str], members: Iterable[dict[str, Any]], *, syncer_e argv = member.get("launch_argv") or il.launch_argv(member, syncer=record) held.append(launch_session([str(a) for a in argv], str(member.get("name")), prepare=prepare)) except (OSError, ValueError) as error: - raise ValueError(f"island {member.get('name')} (learner {member.get('learner_id')}), which holds the " - f"running session: its launch{' as started' if member.get('launch_argv') else ''} " - f"does not compile ({type(error).__name__}: {error}), so the island cannot be " - "compared with it; fix that island's configuration (or remove it) first") from None + where = f"island {member.get('name')} (learner {member.get('learner_id')}), which holds the running session" + why = f"{type(error).__name__}: {error}" + if not member.get("launch_argv"): + raise ValueError(f"{where}: its launch does not compile ({why}), so the island cannot be compared " + "with it; fix that island's configuration (or remove it) first") from None + name = member.get("island_name") or member.get("name") + text = (f"{where}: its launch as started does not compile ({why}). That launch is its trainer worker " + "record, written when the incarnation started: a changed config does not change it") + if not allow_unparsable_running: + raise ValueError(f"{text}. Pass {ALLOW_UNPARSABLE_RUNNING} to check without it (a WARN), or stop or " + f"remove that island first (yeto fleet island remove --name {name})") from None + print(f"fleet session: WARN: {text}; {ALLOW_UNPARSABLE_RUNNING}: the island is left out of the " + "comparison", file=sys.stderr) found = (problems(syncer, islands) + identity_problems(syncer, islands, held) + shape_problems(islands, held) + placement_problems(islands, held)) if found: From 633d835b2c62ebd92909122e51476e4c4df893d7 Mon Sep 17 00:00:00 2001 From: Michael Chung Date: Fri, 27 Nov 2026 05:14:56 +0800 Subject: [PATCH 2/2] fleet follow-ups: a corrupt copy record never copies another run's lines Review fixes: - A corrupt fleet.store.json starts the copy at this run's first line (the first with time_unix at or after the run's registry start), or at the file's end when that start is unknown, instead of the file's start: an earlier run's lines never reach this run's store. Any other error also starts at the file's end. - The copy record is written whole (a temporary file renamed over it). - An add/move that skipped a running island (--allow-unparsable-running) says how many islands it checked and which it skipped instead of the agreement line. - Module header and docs follow the new rules; a run started before this rule loses the last interval and its yeto down lines after a restart. Co-Authored-By: Claude Opus 5.5 --- docs/DASHBOARD.md | 11 ++-- tests/test_fleet_islands_placement.py | 23 +++++++- tests/test_fleet_log_store.py | 73 +++++++++++++++++++++---- yeto/dashboard/fleet_store.py | 77 ++++++++++++++++++++++----- yeto/rl/fleet_islands.py | 13 +++-- yeto/rl/fleet_session.py | 9 ++-- 6 files changed, 173 insertions(+), 33 deletions(-) diff --git a/docs/DASHBOARD.md b/docs/DASHBOARD.md index b4f7ec0e2..c7869e1ff 100644 --- a/docs/DASHBOARD.md +++ b/docs/DASHBOARD.md @@ -229,13 +229,18 @@ launcher left open, only into the store the record of this run names; the run is named by its directory name and its registry start, so a copy of a run directory under another name never copies into the original's store. A record that does not parse (not JSON, a field missing, a start that is not a byte offset) is a `WARN` -line and counts as none: the next copy starts at the file's start (the readers -fold each record once) and `yeto down` copies nothing for it; it never fails a +line and counts as none: the next copy starts at this run's first line (the first +with a `time_unix` at or after the run's registry start), or at the file's end +when that start is unknown, so an earlier run's lines never reach this store, and +`yeto down` copies nothing for it; it never fails a launch. An island launch of a per-island fleet that its trainer worker starts again is a new run (the new incarnation's cluster prefix and registry entry), so its copy starts afresh. A launcher killed outright (`kill -9`) may leave the lines of its last upload interval (under 30 s) only in the local file: they are -observation data, and nothing else depends on them. The copy is observation only: a failed upload is a +observation data, and nothing else depends on them. A run that was already +running when yeto was upgraded to this rule has a record without its directory +name: after its launcher restarts, the lines of the last interval before it (under +30 s) and the `island_stop` lines of its `yeto down` stay in the local file only. The copy is observation only: a failed upload is a `WARN` line, retried with the next chunk, and the launcher's end (and `yeto down`) waits at most 15 s for the last one. A launch of one trainer island uploads nothing, as before. `--store` reads every folder next to the island tapes, and a diff --git a/tests/test_fleet_islands_placement.py b/tests/test_fleet_islands_placement.py index 0a559ab4f..346d0c383 100644 --- a/tests/test_fleet_islands_placement.py +++ b/tests/test_fleet_islands_placement.py @@ -102,6 +102,22 @@ def test_islands_of_two_shapes_keep_the_shape_message_alone(): assert "the same nodes x GPUs per node and parallel flags" in problems[0] and "does not help here" in problems[0] +def test_shape_free_is_offered_when_one_island_binds_no_placement(): + """Two shapes, one island binds its placement and the other none: the placements are not + two different ones, so the shape-free way out stays in the message.""" + from yeto.rl.fleet_session import LaunchSession, Placement, shape_problems + + bound = Placement(placement="colocated", nodes=1, gpus_per_node=8, trainer_nodes=1, trainer_gpus_per_node=8, + rollout_gpus=0, standby_gpus=0, bundle_map="") + sessions = [LaunchSession(name=n, learner_id=i, profile={}, profile_sha256="", learners=0, hello="", + syncer_epoch=0, max_learners=None, shape=shape, placement=placement) + for i, (n, shape, placement) in enumerate([("a", (1, 1, 1, 1, 8), bound), + ("b", (1, 1, 1, 1, 4), None)])] + for order in (sessions, sessions[::-1]): + (found,) = shape_problems(list(order)) + assert "or set --rl-sync-layout shape-free for the whole fleet" in found and "does not help" not in found + + @pytest.mark.parametrize("extra", [ # one placement (per-island placement: TP2 on the same machines): shape-free takes the shape out [*FLEET, "--rl-island-placement", "1:tensor-parallel=2", "--gpu", f"{ONE_BY_EIGHT},{ONE_BY_EIGHT}"], @@ -416,8 +432,11 @@ def test_an_unparsable_running_record_is_refused_unless_allowed(fleet_store, cap assert "Pass --allow-unparsable-running" in err and "yeto fleet island remove --name mixed)" in err assert store.read()["generation"] == before assert run_cli(*move, "--allow-unparsable-running", "--dry-run") == 0 - err = capsys.readouterr().err - assert "fleet session: WARN:" in err and "the island is left out of the comparison" in err + captured = capsys.readouterr() + assert "fleet session: WARN:" in captured.err and "the island is left out of the comparison" in captured.err + # not reported as agreeing: one of the two running launches was not compared + assert "agrees with the syncer launch" not in captured.out + assert "checked 1 of 2 islands; skipped mixed (unparsable record)" in captured.out def test_the_narrow_way_out_does_not_cover_an_island_whose_desired_launch_does_not_compile(tmp_path): diff --git a/tests/test_fleet_log_store.py b/tests/test_fleet_log_store.py index 62d9c68e2..54d3bbaeb 100644 --- a/tests/test_fleet_log_store.py +++ b/tests/test_fleet_log_store.py @@ -711,30 +711,82 @@ def test_the_store_status_is_ok_since_the_oldest_clean_poll(): @pytest.mark.parametrize("text", CORRUPT.values(), ids=CORRUPT.keys()) -def test_a_corrupt_record_is_no_record_and_the_copy_starts_at_the_file_s_start(tmp_path, text, capsys): +def test_a_corrupt_record_is_no_record_and_the_copy_starts_at_this_run_s_first_line(tmp_path, text, capsys): + """A_ROWS (time 100-160) are an earlier run's, B_ROWS (400-401) this run's (start 300).""" path = tmp_path / "r" / "fleet.jsonl" path.parent.mkdir() - path.write_bytes(_text(A_ROWS)) + path.write_bytes(_text(A_ROWS + B_ROWS)) fleet_store.copy_record_path(path).write_text(text) assert fleet_store.read_copy_record(path) is None assert "fleet.store.json is corrupt" in capsys.readouterr().err - assert fleet_store.copy_start(path, "s3://x", run="r@1.0") == 0 + first = len(_text(A_ROWS)) + assert fleet_store.copy_start(path, "s3://x", run="r@300.0") == first err = capsys.readouterr().err - assert err.count("WARN") == 1 and "the copy starts at the file's start" in err - assert fleet_store.read_copy_record(path)["start"] == 0 # a sound record from here on + assert err.count("WARN") == 1 and f"the copy starts at this run's first line (byte {first}" in err + assert fleet_store.read_copy_record(path)["start"] == first # a sound record from here on + + +@pytest.mark.parametrize("run", [None, "r", "r@not-a-time"]) +def test_a_corrupt_record_of_a_run_without_a_known_start_copies_from_the_end(tmp_path, run, capsys): + path = tmp_path / "r" / "fleet.jsonl" + path.parent.mkdir() + path.write_bytes(_text(A_ROWS + B_ROWS)) + fleet_store.copy_record_path(path).write_text(CORRUPT["not-json"]) + assert fleet_store.copy_start(path, "s3://x", run=run) == path.stat().st_size + assert "this run's start is unknown, so the copy starts at the file's end" in capsys.readouterr().err -def test_a_launch_with_a_corrupt_record_copies_the_whole_file(tmp_path, monkeypatch, capsys): +def test_a_corrupt_record_with_no_line_of_this_run_yet_copies_from_the_end(tmp_path): + path = tmp_path / "r" / "fleet.jsonl" + path.parent.mkdir() + path.write_bytes(_text(A_ROWS) + b'{"event": "island_ready", "time_unix": 999}') # its newline not written yet + fleet_store.copy_record_path(path).write_text(CORRUPT["not-json"]) + assert fleet_store.copy_start(path, "s3://x", run="r@300.0") == path.stat().st_size + + +def test_this_run_s_first_line_may_be_at_its_start_exactly(tmp_path): + path = tmp_path / "r" / "fleet.jsonl" + path.parent.mkdir() + path.write_bytes(_text(A_ROWS + B_ROWS)) + fleet_store.copy_record_path(path).write_text(CORRUPT["not-json"]) + assert fleet_store.copy_start(path, "s3://x", run="r@160.0") == len(_text(A_ROWS[:2])) # time_unix 160.0 + + +def test_the_record_is_written_whole(tmp_path, monkeypatch, capsys): + """A rename that fails leaves the previous record and no temporary file.""" + path = tmp_path / "r" / "fleet.jsonl" + path.parent.mkdir() + path.write_bytes(_text(A_ROWS)) + fleet_store.copy_start(path, "s3://a", run="r@1.0") + before = fleet_store.copy_record_path(path).read_text() + + def no_rename(src, dst): + raise OSError("disk full") + + monkeypatch.setattr(fleet_store.os, "replace", no_rename) + fleet_store.copy_start(path, "s3://b", run="r@2.0") + assert fleet_store.copy_record_path(path).read_text() == before + assert sorted(p.name for p in path.parent.iterdir()) == ["fleet.jsonl", fleet_store.COPY_RECORD] + assert "not written (OSError)" in capsys.readouterr().err + + +def test_a_launch_with_a_corrupt_record_copies_only_this_run_s_lines(tmp_path, monkeypatch, capsys): + """An earlier run of the name left lines and a corrupt record: the store gets every line + of this run and none of the earlier run's.""" monkeypatch.setattr("yeto.runs.run_dir", lambda run: tmp_path / run) store = tmp_path / "s" path = tmp_path / "run-i1" / "fleet.jsonl" path.parent.mkdir() - path.write_bytes(_text(A_ROWS)) # an earlier launch's lines + old = _text(A_ROWS) # the earlier run's lines (time 100-160) + path.write_bytes(old) fleet_store.copy_record_path(path).write_text(CORRUPT["start-not-int"]) _new_run() log = _launch(tmp_path, store) + log.event("island_stop", ISLAND) assert log.uploader is not None and log.close() is True - assert _uploaded(store) == log.path.read_bytes() # from 0: the readers fold each record once + uploaded = _uploaded(store) + assert uploaded == log.path.read_bytes()[len(old):] # every line of this run + assert b'"time_unix": 100.0' not in uploaded and b'"time_unix": 160.0' not in uploaded assert "is corrupt" in capsys.readouterr().err @@ -745,7 +797,10 @@ def broken(path): raise RuntimeError("disk on fire") monkeypatch.setattr(fleet_store, "_load_copy_record", broken) - assert fleet_store.copy_start(tmp_path / "x" / "fleet.jsonl", "s3://x", run="r@1.0") == 0 + other = tmp_path / "x" / "fleet.jsonl" + other.parent.mkdir() + other.write_bytes(_text(A_ROWS)) + assert fleet_store.copy_start(other, "s3://x", run="r@1.0") == other.stat().st_size # fewer lines, not others' monkeypatch.setattr(fleet_store, "copy_start", lambda *a, **k: (_ for _ in ()).throw(RuntimeError("boom"))) _new_run() log = _launch(tmp_path, tmp_path / "s") # the launch goes on, its fleet.jsonl local diff --git a/yeto/dashboard/fleet_store.py b/yeto/dashboard/fleet_store.py index 94c0ecab3..e19f6da13 100644 --- a/yeto/dashboard/fleet_store.py +++ b/yeto/dashboard/fleet_store.py @@ -14,9 +14,11 @@ id ``k``) and ``fleet`` for a launch of the whole fleet; each launcher process adds its own folder (a random nonce: two launchers of one host never share one, even with the same pid in the same second), so no two write the same key. The copy covers this run's part of -the local file (:func:`copy_start`: a run directory reused by another run starts at the -file's end); a launcher restarted for the same run uploads its earlier lines again, and the -readers fold each record once. ``yeto down`` copies the ``island_stop`` lines it appends +the local file only, as ``fleet.store.json`` records it (:func:`copy_start`, see "which part +of the local file belongs to this store" below): a run directory reused by another run, or +copied under another name, starts at the file's end; a launcher restarted for the same run +uploads its earlier lines again, and the readers fold each record once. ``yeto down`` copies +the ``island_stop`` lines it appends into the store the record of its run names (:func:`upload_appended`). Observation only: a failed upload is a WARN on stderr and is retried with the next @@ -78,7 +80,13 @@ def incarnation(*, host: str | None = None, pid: int | None = None, now: float | # record (written before this copy existed), starts at the file's end, so an earlier run's # lines never reach this run's store (the rule of ``tape_upload.syncer_uploaders(from_end=True)``). # A launch that does not copy the file voids the record (:func:`copy_off`): no store, the file's -# end. ``yeto down`` copies its lines only for the run the record names. +# end. ``yeto down`` copies its lines only for the run the record names. The run is named by +# its directory name and registry start (``@``), so a copied run directory +# is another run. A record that does not parse is a WARN and counts as none, but the copy +# then starts at this run's first line (the first with ``time_unix`` at or after the run's +# registry start), or at the file's end when that start is unknown: fewer lines rather than +# another run's; ``yeto down`` copies nothing for it. The record is written whole (a temporary +# file renamed over it), so a crash mid-write leaves the previous record or the new one. COPY_RECORD = "fleet.store.json" COPY_SCHEMA = "yeto.fleet.log-copy/v1" @@ -150,39 +158,84 @@ def _size(p: Path) -> int: def _write_record(p: Path, doc: dict) -> None: + """The record, written whole: a temporary file next to it renamed over it.""" + record = copy_record_path(p) + tmp = record.with_name(f".{record.name}.{os.getpid()}.{secrets.token_hex(3)}.tmp") try: p.parent.mkdir(parents=True, exist_ok=True) - copy_record_path(p).write_text(json.dumps(doc, sort_keys=True) + "\n", encoding="utf-8") + tmp.write_text(json.dumps(doc, sort_keys=True) + "\n", encoding="utf-8") + os.replace(tmp, record) except OSError as exc: + try: + tmp.unlink(missing_ok=True) + except OSError: + pass _stderr(f"[launcher] WARN: fleet.jsonl store copy: {COPY_RECORD} not written ({type(exc).__name__})") +def _started_of(run: str | None) -> float | None: + """The registry start in a :func:`run_identity` (None: no identity, or not one).""" + try: + return float(str(run).rsplit("@", 1)[1]) if run else None + except (IndexError, ValueError): + return None + + +def _first_line_at(p: Path, started: float, size: int) -> int: + """The byte offset of the first complete line of ``p`` whose ``time_unix`` is at or after + ``started`` (this run's first line: an earlier run's lines precede it), else ``size``.""" + offset = 0 + with p.open("rb") as fh: + for line in fh: + if offset + len(line) > size or not line.endswith(b"\n"): + break + try: + t = json.loads(line).get("time_unix") + except (ValueError, AttributeError): + t = None + if isinstance(t, (int, float)) and not isinstance(t, bool) and t >= started: + return offset + offset += len(line) + return size + + def copy_start(path: str | os.PathLike, store: str, *, learner_id: Any = None, run: str | None = None, log: Callable[[str], None] | None = None) -> int: """The byte offset of ``path`` this launch's copy into ``store`` starts at (see above), recorded for the next launch and for ``yeto down``. ``run``: :func:`run_identity` (None: - the file's end). A corrupt record (a WARN) is taken as none, but the copy starts at the - file's start: where this run's lines begin is unknown, and the readers fold each record - once. Never raises (a record that cannot be written: the offset still holds for this launch).""" + the file's end). A corrupt record (a WARN) is taken as none: the copy starts at this run's + first line (:func:`_corrupt_start`). Never raises (a record that cannot be written: the + offset still holds for this launch).""" p = Path(path) size = _size(p) try: known, why = _load_copy_record(p) if why is not None: - _corrupt(why, "the copy starts at the file's start", log or _stderr) - start = 0 + start = _corrupt_start(p, why, run, size, log or _stderr) else: same = (known is not None and known.get("store") == str(store) and run is not None and known.get("run") == run) start = min(known["start"], size) if same else size except Exception as exc: # noqa: BLE001 - telemetry never stops a launch - _corrupt(type(exc).__name__, "the copy starts at the file's start", log or _stderr) - start = 0 + _corrupt(type(exc).__name__, "the copy starts at the file's end", log or _stderr) + start = size _write_record(p, {"schema": COPY_SCHEMA, "store": str(store), "start": start, "run": run, "learner_id": learner_id if lane(learner_id) != FLEET_LANE else None}) return start +def _corrupt_start(p: Path, why: str, run: str | None, size: int, log: Callable[[str], None]) -> int: + """Where the copy of a run whose record is corrupt starts: this run's first line (by its + registry start), else (no start known) the file's end. Never another run's lines.""" + started = _started_of(run) + if started is None: + _corrupt(why, "this run's start is unknown, so the copy starts at the file's end", log) + return size + start = _first_line_at(p, started, size) + _corrupt(why, f"the copy starts at this run's first line (byte {start}: time_unix at or after its start)", log) + return start + + def copy_off(path: str | os.PathLike, *, run: str | None = None) -> None: """A launch that does not copy ``path`` (no store, no island records, the copy turned off): its record, if any, names no store from the file's end on, so neither ``yeto down`` diff --git a/yeto/rl/fleet_islands.py b/yeto/rl/fleet_islands.py index de152e519..4569b0d29 100644 --- a/yeto/rl/fleet_islands.py +++ b/yeto/rl/fleet_islands.py @@ -300,16 +300,21 @@ def session_check(run: Any, doc: dict[str, Any], member: dict[str, Any], running.append(_as_launched(objects, {**previous, "name": f"{previous['name']} (its machines before the move)", "island_name": previous["name"]})) try: - fleet_session.check(run.trainer_argv() if hasattr(run, "trainer_argv") else run.cfg["trainer"]["argv"], - [member], syncer_epoch=epoch if isinstance(epoch, int) else None, running=running, - allow_unparsable_running=allow_unparsable_running) + skipped = fleet_session.check( + run.trainer_argv() if hasattr(run, "trainer_argv") else run.cfg["trainer"]["argv"], + [member], syncer_epoch=epoch if isinstance(epoch, int) else None, running=running, + allow_unparsable_running=allow_unparsable_running) except ValueError as error: if unread is None: raise raise ValueError(f"{error} (the fleet's syncer record could not be read ({unread}), so the island's " "machines before the move were taken to hold a running session; retry once the " "record reads)") from None - print(f"fleet island: island {member['name']} agrees with the syncer launch on the syncer session") + if skipped: # --allow-unparsable-running: not every running island was compared + print(f"fleet island: island {member['name']}: checked {len(running) - len(skipped)} of {len(running)} " + f"islands; skipped {', '.join(skipped)} (unparsable record)") + else: + print(f"fleet island: island {member['name']} agrees with the syncer launch on the syncer session") # -- the command -------------------------------------------------------------------------------- diff --git a/yeto/rl/fleet_session.py b/yeto/rl/fleet_session.py index 2f22cc2cf..43bbfed98 100644 --- a/yeto/rl/fleet_session.py +++ b/yeto/rl/fleet_session.py @@ -429,7 +429,7 @@ def problems(syncer: LaunchSession, islands: Iterable[LaunchSession]) -> list[st def check(syncer_argv: list[str], members: Iterable[dict[str, Any]], *, syncer_epoch: int | None = None, prepare: Callable[[Any], None] | None = None, running: Iterable[dict[str, Any]] = (), - allow_unparsable_running: bool = False) -> None: + allow_unparsable_running: bool = False) -> list[str]: """Raise ValueError naming every disagreement between the syncer launch (``syncer_argv``) and the island launches of ``members`` (trainer members of the desired state), each compiled with the syncer record's term (``syncer_epoch``; None: the syncer launch's), @@ -439,7 +439,8 @@ def check(syncer_argv: list[str], members: Iterable[dict[str, Any]], *, syncer_e does not compile cannot be compared with and refuses the check; for a recorded ``launch_argv`` (written when that incarnation started, so a changed config does not change it) ``allow_unparsable_running`` (:data:`ALLOW_UNPARSABLE_RUNNING`) makes that a - WARN and leaves the island out of the comparison.""" + WARN and leaves the island out of the comparison. Returns the names of the running + islands left out that way (empty: every one was compared).""" from yeto.rl import island_launches as il # noqa: PLC0415 try: @@ -455,7 +456,7 @@ def check(syncer_argv: list[str], members: Iterable[dict[str, Any]], *, syncer_e except (OSError, ValueError) as error: # json.JSONDecodeError is a ValueError raise ValueError(f"island {member.get('name')} (learner {member.get('learner_id')}): its launch " f"refuses its options: {type(error).__name__}: {error}") from None - held = [] + held, skipped = [], [] for member in running: # ``launch_argv``: the argv the island was started with (as recorded) try: argv = member.get("launch_argv") or il.launch_argv(member, syncer=record) @@ -474,8 +475,10 @@ def check(syncer_argv: list[str], members: Iterable[dict[str, Any]], *, syncer_e f"remove that island first (yeto fleet island remove --name {name})") from None print(f"fleet session: WARN: {text}; {ALLOW_UNPARSABLE_RUNNING}: the island is left out of the " "comparison", file=sys.stderr) + skipped.append(str(name)) found = (problems(syncer, islands) + identity_problems(syncer, islands, held) + shape_problems(islands, held) + placement_problems(islands, held)) if found: raise ValueError("the fleet's launches do not agree on the syncer session (the syncer would refuse " "these islands at HELLO): " + "; ".join(found)) + return skipped