Skip to content
Merged
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
17 changes: 16 additions & 1 deletion docs/DASHBOARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,22 @@ 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 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. 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
Expand Down
12 changes: 11 additions & 1 deletion docs/FLEET_TRAINER_ISLANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <island>`).
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
Expand Down
94 changes: 92 additions & 2 deletions tests/test_fleet_islands_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,46 @@ 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]


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}"],
# 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():
Expand Down Expand Up @@ -353,12 +393,62 @@ 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
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):
"""--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
Expand Down
143 changes: 143 additions & 0 deletions tests/test_fleet_log_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,146 @@ 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_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 + 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
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 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_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()
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
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


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)
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
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
Loading
Loading