From f5064027d16e3297f8093913971c7c667a2813de Mon Sep 17 00:00:00 2001 From: Michael Chung Date: Fri, 27 Nov 2026 02:15:06 +0800 Subject: [PATCH 1/2] own-cluster rehearsal polish: tcp nodes in the probe, one line per lease-probe finding, own ssh nodes at $0 - cluster probe: a node whose inventory declares no RDMA fabric (tcp) is reported as "no RDMA fabric" with a next step, not "fabric unavailable"; it no longer makes the probe exit 1 (--write still sets fabric_group unavailable). The JSON record gains "no_rdma". - node lease takeover probe: each finding is printed once (docker's one daemon seen by the user's and the sudo view, a labelled yeto-- container matched by label and name printed the same line up to four times). - cost: an ssh_trainer row of nodes without price_per_card_hour is the operator's own machines: $0, not unpriced, so no cost_unpriced warning per incarnation. Co-Authored-By: Claude Opus 5.5 --- docs/COST_GUARD.md | 3 +++ tests/test_fabric_groups.py | 34 +++++++++++++++++++++++++++++++ tests/test_node_lease.py | 16 +++++++++++++++ tests/test_ssh_trainer_storage.py | 25 ++++++++++++++++++++--- yeto/cost/billing.py | 9 ++++++-- yeto/launch/fabric_groups.py | 27 +++++++++++++++++++----- yeto/launch/node_lease.py | 26 +++++++++++++++-------- 7 files changed, 121 insertions(+), 19 deletions(-) diff --git a/docs/COST_GUARD.md b/docs/COST_GUARD.md index fe286e402..8d2880ca2 100644 --- a/docs/COST_GUARD.md +++ b/docs/COST_GUARD.md @@ -46,6 +46,9 @@ How cost is computed: wire overhead. The ledger entry's `egress_events` lists which of these events count. - **National Compute**: lease duration × rate. A lease past its `lease_until` keeps billing until it is deleted, and it is counted that way. Set `YETO_NC_USD_PER_GPU_HOUR` (or `YETO_NC_USD_PER_UCR`) to price it. +- **SSH trainer nodes** (a node inventory): the inventory's `price_per_card_hour` times the cards. A + node without `price_per_card_hour` is the operator's own machine and counts as $0 (not unpriced, no + `cost_unpriced` warning), as for an `ssh:` sampler pool. - A resource without a known rate is reported as **unpriced** (`cost_unpriced` event), never as $0, and is not counted toward the budget. Configure a rate for it. diff --git a/tests/test_fabric_groups.py b/tests/test_fabric_groups.py index 16ad153c0..6c699eba5 100644 --- a/tests/test_fabric_groups.py +++ b/tests/test_fabric_groups.py @@ -344,6 +344,40 @@ def test_three_connected_nodes_form_a_group_and_a_socket_node_is_fabric_unavaila assert sum("torch.distributed.run" in s for _, s in ops.scripts) == 2 * 6 # every pair ran its own NCCL +def _tcp_inventory(tmp_path, fabrics): + path = tmp_path / "nodes.yaml" + path.write_text(yaml.safe_dump({"nodes": [_entry(i, fabric=f) for i, f in enumerate(fabrics)]})) + return path + + +def test_a_tcp_node_is_no_group_and_no_probe_failure_with_a_next_step(tmp_path, capsys): + """Rehearsal: tcp nodes were first said to "get no group", then reported "fabric + unavailable" (with the ib_write_bw noise of their pairs) and the probe exited 1.""" + path = _tcp_inventory(tmp_path, ["ib", "ib", "tcp"]) + assert cluster_cli.main(_args(path, "--write"), ops=_ops_for(path), log=lambda m: None) == 0 + cap = capsys.readouterr() + assert "nodes ['b300-2'] declare no RDMA fabric (ib / roce): they get no group" in cap.err + (tcp,) = [x for x in cap.out.splitlines() if "b300-2" in x] + assert tcp.startswith(f"{fg.NO_RDMA}: b300-2: fabric tcp in the inventory: no group, single-node islands only") + assert f"next: {fg.NO_RDMA_NEXT}" in tcp and fg.UNAVAILABLE not in cap.out + groups = {n.name: n.fabric_group for n in load_inventory(path)} + assert groups["b300-0"] == groups["b300-1"] != FABRIC_UNAVAILABLE and groups["b300-2"] == FABRIC_UNAVAILABLE + + +def test_a_probe_of_tcp_nodes_only_says_so_for_every_node_and_exits_0(tmp_path, capsys): + path = _tcp_inventory(tmp_path, ["tcp", "tcp"]) + assert cluster_cli.main(_args(path, "--json"), ops=_ops_for(path), log=lambda m: None) == 0 + record = json.loads(capsys.readouterr().out) + assert record["groups"] == {} and record["unavailable"] == {} and record["bad_edges"] == [] + assert record["no_rdma"] == {"b300-0": "tcp", "b300-1": "tcp"} + + +def test_a_declared_ib_node_that_runs_over_sockets_stays_fabric_unavailable(): + nodes, ops = _cluster(2, socket={"b300-1"}) + result = _probe(nodes, ops) + assert result.no_rdma == {} and list(result.unavailable) == ["b300-0", "b300-1"] and not result.clean + + def test_a_triangle_with_a_missing_edge_is_no_group_of_three(): names = ["b300-0", "b300-1", "b300-2"] result = fg.group_nodes(names, _pair_checks(names, socket={("b300-0", "b300-2")})) diff --git a/tests/test_node_lease.py b/tests/test_node_lease.py index b9e55aa57..1dc5faffd 100644 --- a/tests/test_node_lease.py +++ b/tests/test_node_lease.py @@ -939,6 +939,22 @@ def test_the_probe_finds_trainer_process_groups_and_venv_samplers(tmp_path): assert os.environ.get("FAKE_STATE_DIR") is None +def test_the_probe_prints_each_finding_once(tmp_path): + """Rehearsal: one labelled trainer container named ``yeto--...`` on a docker node + whose ``sudo -n`` works was printed four times (two views x label and name listing).""" + import subprocess + + env = _node_bin(tmp_path) + rows = [{"name": "yeto-run-a-fake", "labels": {node_lease.RUN_LABEL: "run-a"}}] + for view in ("docker", "docker-root"): # docker's one daemon: both views list the container + (tmp_path / f"{view}.json").write_text(json.dumps(rows)) + out = subprocess.run(["bash", "-c", node_lease.still_runs_script("run-a", sudo=True)], capture_output=True, + text=True, env=env).stdout + lines = [x for x in out.splitlines() if x.startswith(node_lease.PROBE_MARK)] + assert lines == [f"{node_lease.PROBE_MARK} found=container:yeto-run-a-fake", f"{node_lease.PROBE_MARK} done"] + assert node_lease.parse_probe(out) == (True, ["container:yeto-run-a-fake"]) + + def test_the_node_runtime_labels_its_containers_only_when_asked(tmp_path): from tests.test_ssh_sampler_pool import conf from yeto.node import launch as node_launch diff --git a/tests/test_ssh_trainer_storage.py b/tests/test_ssh_trainer_storage.py index 421ca866a..9b896cabb 100644 --- a/tests/test_ssh_trainer_storage.py +++ b/tests/test_ssh_trainer_storage.py @@ -5,6 +5,7 @@ import dataclasses import functools +import json import os import subprocess from pathlib import Path @@ -249,7 +250,7 @@ def run(self, n, script, *, timeout): assert [r.id for r in ledger.open_resources()] == ["k31/trainer-i4"] -def test_cost_prices_an_incarnation_by_the_declared_price_or_leaves_it_unpriced(tmp_path): +def test_cost_prices_an_incarnation_by_the_declared_price_or_at_zero_on_own_nodes(tmp_path): ledger = ResourceLedger(tmp_path / "resources.jsonl", clock=lambda: 1000.0) nodes = [b300(i, price_per_card_hour=1.0) for i in range(6)] for i, priced in ((1, nodes), (2, [b300(0)])): @@ -258,8 +259,26 @@ def test_cost_prices_an_incarnation_by_the_declared_price_or_leaves_it_unpriced( summary = billing.resource_costs(ledger.resources(), now=1000.0 + 1800) by_id = {item.key: item for item in summary.items} assert by_id["ssh_trainer:k31/t-i1"].estimated_usd == pytest.approx(24.0) # 48 cards, $1, 30 min - assert not by_id["ssh_trainer:k31/t-i2"].priced - assert "price_per_card_hour" in by_id["ssh_trainer:k31/t-i2"].note + own = by_id["ssh_trainer:k31/t-i2"] # no price: the operator's own node, $0 and not unpriced + assert own.priced and own.estimated_usd == 0.0 and "price_per_card_hour" in own.note + assert summary.unpriced == [] + + +def test_the_cost_guard_does_not_warn_about_own_ssh_nodes(tmp_path): + """Rehearsal: every incarnation of a resident ssh trainer on own nodes (no + price_per_card_hour) raised a cost_unpriced warning.""" + from yeto.cost.guard import CostGuard, GuardConfig + + ledger = ResourceLedger(tmp_path / "resources.jsonl", clock=lambda: 1000.0) + ledger.created("ssh_trainer", "k31/t-i0", "t-i0", **ssh_trainer_ledger.created_attrs( + run_id="k31", island="t", incarnation=0, nodes=[b300(0)], docker=True, kill_grace_s=30)) + guard = CostGuard("k31", GuardConfig(), ledger=ledger, events_path=tmp_path / "events.jsonl", + clock=lambda: 1000.0 + 600, log=lambda *_: None) + guard.tick() + events = [json.loads(x) for x in (tmp_path / "events.jsonl").read_text().splitlines()] + assert [e for e in events if e.get("event") == "cost_unpriced"] == [] + (tick,) = [e for e in events if e.get("event") == "cost_tick"] + assert tick["unpriced"] == [] and tick["total_usd"] == 0.0 # ---------------------------------------------------------------- multi-node staged releases diff --git a/yeto/cost/billing.py b/yeto/cost/billing.py index 799059de3..1264ad412 100644 --- a/yeto/cost/billing.py +++ b/yeto/cost/billing.py @@ -452,6 +452,9 @@ def _nc_rate(r: Resource, rates: Rates) -> float | None: return None +OWN_SSH_NODES_NOTE = "own SSH nodes (no price_per_card_hour): $0" + + def _span_cost(r: Resource, start: float, now: float, rate: float | None, note: str = "") -> ItemCost: end = r.released_at if r.released_at is not None else now if end < start and r.key not in _SKEW_WARNED: @@ -547,9 +550,11 @@ def covered_until(c: Resource) -> float: elif _provider_cost(r.kind) is not None: # an island provider's machine (nc_lease) items.append(_provider_cost(r.kind)(r, now, rates)) elif r.kind == "ssh_trainer": # the operator's machines: the inventory's declared price + # a node without price_per_card_hour is the operator's own machine: $0 (the inventory's + # default, as for an ssh: sampler pool), not unpriced rate = r.attrs.get("usd_per_hour") - items.append(_span_cost(r, r.created_at, now, None if rate is None else float(rate), - "" if rate is not None else "SSH nodes without price_per_card_hour")) + items.append(_span_cost(r, r.created_at, now, 0.0 if rate is None else float(rate), + "" if rate is not None else OWN_SSH_NODES_NOTE)) elif r.kind == "sky_cluster": rate = r.attrs.get("usd_per_hour") note = "" diff --git a/yeto/launch/fabric_groups.py b/yeto/launch/fabric_groups.py index e1028f1e8..c34ff960d 100644 --- a/yeto/launch/fabric_groups.py +++ b/yeto/launch/fabric_groups.py @@ -50,6 +50,9 @@ HINT = ("the node inventory declares no fabric_group: a multi-node island may land on nodes that do not " "reach each other over IB / RoCE; `yeto cluster probe` groups them (docs/OWN_CLUSTERS.md)") UNAVAILABLE = "fabric unavailable" +NO_RDMA = "no RDMA fabric" +NO_RDMA_NEXT = ("if the node has IB / RoCE HCAs, set its fabric to ib or roce in the inventory and probe " + "again; otherwise nothing to do (yeto preflight checks the node itself)") _log = logging.getLogger(__name__) @@ -225,14 +228,18 @@ class ProbeResult: pair_problems: dict[str, str] = field(default_factory=dict) bad_edges: list[tuple[str, str, str]] = field(default_factory=list) warnings: list[str] = field(default_factory=list) + # node -> its declared fabric, for the nodes that declare no RDMA fabric (``tcp``): no group by + # their own inventory, single-node islands only; not a probe failure + no_rdma: dict[str, str] = field(default_factory=dict) @property def clean(self) -> bool: return not self.unavailable and not self.bad_edges def assignment(self) -> dict[str, str]: - """Node name -> group name (``unavailable``: no RDMA to the others).""" - out = {n: FABRIC_UNAVAILABLE for n in self.unavailable} + """Node name -> group name (``unavailable``: no RDMA to the others, a node that + declares no RDMA fabric included).""" + out = {n: FABRIC_UNAVAILABLE for n in [*self.unavailable, *self.no_rdma]} for g, members in self.groups.items(): out.update({n: g for n in members}) return dict(sorted(out.items())) @@ -242,10 +249,13 @@ def lines(self) -> list[str]: out += [f"missing edge {a}<->{b}: {why}" for a, b, why in self.bad_edges] for n, why in self.unavailable.items(): out.append(f"{UNAVAILABLE}: {n}: {'; '.join(why) or 'no RDMA edge to another node'}") + for n, fabric in self.no_rdma.items(): + out.append(f"{NO_RDMA}: {n}: fabric {fabric} in the inventory: no group, single-node islands only " + f"(fabric_group {FABRIC_UNAVAILABLE}); next: {NO_RDMA_NEXT}") return out def record(self) -> dict[str, Any]: - return {"groups": self.groups, "unavailable": self.unavailable, + return {"groups": self.groups, "unavailable": self.unavailable, "no_rdma": self.no_rdma, "edges": [list(e) for e in self.edges], "pair_problems": self.pair_problems, "bad_edges": [list(e) for e in self.bad_edges], "warnings": self.warnings} @@ -545,7 +555,14 @@ def group_nodes(names: Sequence[str], checks: Sequence[Any], *, states: Sequence previous: Mapping[str, str | None] | None = None, reserved: Iterable[str] = (), nccl_pairs: str = "all") -> ProbeResult: """The fabric groups of ``names`` from a preflight's ``checks`` (and its node - ``states``: the declared rails, the fabric keys).""" + ``states``: the declared rails, the fabric keys). A node whose state declares no + RDMA fabric (``tcp``) is in ``no_rdma``, not ``unavailable``: the probe does not + group it, and that is no failure of the probe.""" + from .ssh_trainer_island import RDMA_FABRICS # noqa: PLC0415 - the island imports this module + + declared = {s.node.name: getattr(s.node, "fabric", None) for s in states} + no_rdma = {n: str(declared[n]) for n in names if declared.get(n) not in (None, *RDMA_FABRICS)} + names = [n for n in names if n not in no_rdma] blocked = node_blocks(names, checks, states) edges, problems, warns = evaluate_pairs(names, checks, nccl_pairs=nccl_pairs, blocked=blocked) edge = {frozenset(e) for e in edges} @@ -560,7 +577,7 @@ def group_nodes(names: Sequence[str], checks: Sequence[Any], *, states: Sequence keys = {s.node.name: fabric_keys(s) for s in states} ids = assign_ids(multi, keys=keys, previous=previous, reserved=reserved) result = ProbeResult(groups=dict(sorted(zip(ids, multi))), edges=edges, pair_problems=problems, - bad_edges=bad, warnings=warns) + bad_edges=bad, warnings=warns, no_rdma=dict(sorted(no_rdma.items()))) for part in parts: if len(part) > 1: continue diff --git a/yeto/launch/node_lease.py b/yeto/launch/node_lease.py index 56c57e2b9..41a52e505 100644 --- a/yeto/launch/node_lease.py +++ b/yeto/launch/node_lease.py @@ -249,16 +249,24 @@ def still_runs_script(run: str, *, sudo: bool = False) -> str: * ``sampler:``: a venv sampler (the start marker ``yeto-ssh-sampler::`` in its arguments; assembled at run time, so the probe never finds itself). - Every finding refuses a takeover; the caller treats a missing ``done`` line the same.""" + Each finding is printed once, however many views and listings see it (docker's one + daemon answers the user's and the ``sudo -n`` view alike; a labelled ``yeto--`` + container matches the label and the name). Every finding refuses a takeover; the + caller treats a missing ``done`` line the same.""" if not re.fullmatch(r"[A-Za-z0-9_.:+-]+", str(run)): raise NodeLeaseError(f"run {run!r}: not a plain word") prefix = re.sub(r"[^A-Za-z0-9_.-]", "-", f"yeto-{run}-") head, tail = SAMPLER_MARKER[:5], SAMPLER_MARKER[5:] - found = f"echo \"{PROBE_MARK} found=" + say = "say \"" names = "--format '{{.Names}}'" return ( f"m={head}; m=\"${{m}}{tail}:{run}:\"\n" "err=$(mktemp 2>/dev/null || echo \"/tmp/yeto-lease-probe.$$\")\n" + "seen=' '\n" + "say() { # a finding, once: a container seen by two views or two listings is one line\n" + " case \"$seen\" in *\" $1 \"*) return;; esac\n" + f" seen=\"$seen$1 \"; echo \"{PROBE_MARK} found=$1\"\n" + "}\n" "listed() { # after a failed ps: a daemon that is not running lists nothing; any other failure: unknown\n" " grep -qi 'permission denied' \"$err\" 2>/dev/null && return 1\n" " grep -q 'Cannot connect to the Docker daemon' \"$err\" 2>/dev/null || return 1\n" @@ -272,26 +280,26 @@ def still_runs_script(run: str, *, sudo: bool = False) -> str: " ok=1\n" "}\n" "report() {\n" - f" for n in $mine; do {found}container:$n\"; done\n" + f" for n in $mine; do {say}container:$n\"; done\n" " for n in $all; do\n" - f" case \"$n\" in {prefix}*) {found}container:$n\";;\n" + f" case \"$n\" in {prefix}*) {say}container:$n\";;\n" " yeto-sampler-*) case \" $(echo $labelled) \" in *\" $n \"*) ;; " - f"*) {found}unconfirmed:container:$n\";; esac;;\n" + f"*) {say}unconfirmed:container:$n\";; esac;;\n" " esac\n done\n}\n" "sudo_ok=0; command -v sudo >/dev/null 2>&1 && sudo -n true 2>/dev/null && sudo_ok=1\n" "for e in docker podman; do command -v $e >/dev/null 2>&1 || continue\n" " view $e; plain=$ok; [ $ok = 1 ] && report\n" " root=0; if [ $sudo_ok = 1 ]; then view sudo -n $e; root=$ok; [ $ok = 1 ] && report; fi\n" " case $e in\n" - f" docker) [ $plain = 1 ] || [ $root = 1 ] || {found}unconfirmed:docker\";;\n" - f" *) [ $plain = 1 ] || {found}unconfirmed:$e\"\n" - + (f" [ $root = 1 ] || {found}unconfirmed:sudo-$e\";;\n" if sudo else " ;;\n") + f" docker) [ $plain = 1 ] || [ $root = 1 ] || {say}unconfirmed:docker\";;\n" + f" *) [ $plain = 1 ] || {say}unconfirmed:$e\"\n" + + (f" [ $root = 1 ] || {say}unconfirmed:sudo-$e\";;\n" if sudo else " ;;\n") + " esac\n" "done\n" "rm -f \"$err\"\n" f"for f in \"$HOME/{TRAINER_STATE_DIR}/{run}\"/*/pgid; do [ -f \"$f\" ] || continue; d=${{f%/pgid}}\n" " [ -f \"$d/rc\" ] && continue; pid=$(cat \"$f\" 2>/dev/null)\n" - f" [ \"$pid\" -gt 1 ] 2>/dev/null && kill -0 -- -$pid 2>/dev/null && {found}process:${{d##*/}}\"\n" + f" [ \"$pid\" -gt 1 ] 2>/dev/null && kill -0 -- -$pid 2>/dev/null && {say}process:${{d##*/}}\"\n" "done\n" f"ps -eo pid=,args= 2>/dev/null | M=\"$m\" awk -v me=$$ '$1 != me && index($0, ENVIRON[\"M\"]) " f"{{print \"{PROBE_MARK} found=sampler:\" $1}}'\n" From f67da9611613aa4662978335cdd3876333ed63c7 Mon Sep 17 00:00:00 2001 From: Michael Chung Date: Fri, 27 Nov 2026 03:59:19 +0800 Subject: [PATCH 2/2] Review fixes: a partly priced ssh incarnation stays unpriced; a tcp node's failed node checks fail the probe - ssh_trainer ledger rows count their nodes with and without price_per_card_hour. $0 only when no node declares a price (own machines); when only some do, the row stays unpriced and the cost guard warns (cost_unpriced). A row without the counts (an older ledger) stays unpriced as on main. - cluster probe: a node declaring no RDMA fabric still reports its failed node checks (image pull, container, host probe, unreachable ssh; not its IB checks, not a clock skew alone) with a fix-the-node next step, and fails the probe (exit 1, JSON "no_rdma_failed"). hccs is documented as no RDMA fabric. - tests: partly priced rows, rows without counts, a tcp node whose pull is refused or that is unreachable, declared roce nodes are grouped. Co-Authored-By: Claude Opus 5.5 --- docs/COST_GUARD.md | 7 ++++--- tests/test_fabric_groups.py | 32 +++++++++++++++++++++++++++++++ tests/test_ssh_trainer_storage.py | 27 ++++++++++++++++++++++++++ yeto/cost/billing.py | 22 ++++++++++++++++----- yeto/launch/fabric_groups.py | 28 +++++++++++++++++++++------ yeto/launch/ssh_trainer_ledger.py | 10 +++++++--- 6 files changed, 109 insertions(+), 17 deletions(-) diff --git a/docs/COST_GUARD.md b/docs/COST_GUARD.md index 8d2880ca2..164ab39ec 100644 --- a/docs/COST_GUARD.md +++ b/docs/COST_GUARD.md @@ -46,9 +46,10 @@ How cost is computed: wire overhead. The ledger entry's `egress_events` lists which of these events count. - **National Compute**: lease duration × rate. A lease past its `lease_until` keeps billing until it is deleted, and it is counted that way. Set `YETO_NC_USD_PER_GPU_HOUR` (or `YETO_NC_USD_PER_UCR`) to price it. -- **SSH trainer nodes** (a node inventory): the inventory's `price_per_card_hour` times the cards. A - node without `price_per_card_hour` is the operator's own machine and counts as $0 (not unpriced, no - `cost_unpriced` warning), as for an `ssh:` sampler pool. +- **SSH trainer nodes** (a node inventory): the inventory's `price_per_card_hour` times the cards. When + no node of an incarnation declares `price_per_card_hour`, the nodes are the operator's own machines and + count as $0 (not unpriced, no `cost_unpriced` warning), as for an `ssh:` sampler pool. When only some + of its nodes declare a price, the incarnation is unpriced (a forgotten price is never read as $0). - A resource without a known rate is reported as **unpriced** (`cost_unpriced` event), never as $0, and is not counted toward the budget. Configure a rate for it. diff --git a/tests/test_fabric_groups.py b/tests/test_fabric_groups.py index 6c699eba5..de65cb521 100644 --- a/tests/test_fabric_groups.py +++ b/tests/test_fabric_groups.py @@ -372,6 +372,38 @@ def test_a_probe_of_tcp_nodes_only_says_so_for_every_node_and_exits_0(tmp_path, assert record["no_rdma"] == {"b300-0": "tcp", "b300-1": "tcp"} +def test_a_tcp_node_that_fails_its_node_checks_fails_the_probe_with_the_reason(tmp_path, capsys): + """REV-904b M2: a tcp node whose image pull is refused is a probe failure (main: rc 1 with + the image_pull reason), not "nothing to do".""" + path = _tcp_inventory(tmp_path, ["ib", "ib", "tcp"]) + ops = _ops_for(path, behaviors={"b300-2": Behavior(pull=(1, "pull access denied for x"))}) + assert cluster_cli.main(_args(path), ops=ops, log=lambda m: None) == 1 + (tcp,) = [x for x in capsys.readouterr().out.splitlines() if "b300-2" in x] + assert tcp.startswith(f"{fg.NO_RDMA}: b300-2: fabric tcp") and "node checks FAILED: image_pull:" in tcp + assert "pull access denied" in tcp and f"next: {fg.NO_RDMA_FAILED_NEXT}" in tcp and "nothing to do" not in tcp + path = _tcp_inventory(tmp_path, ["tcp", "tcp"]) + ops = _ops_for(path, behaviors={"b300-1": Behavior(pull=(1, "pull access denied for x"))}) + assert cluster_cli.main(_args(path, "--json"), ops=ops, log=lambda m: None) == 1 + record = json.loads(capsys.readouterr().out) + assert list(record["no_rdma_failed"]) == ["b300-1"] and record["no_rdma"] == {"b300-0": "tcp", "b300-1": "tcp"} + path = _tcp_inventory(tmp_path, ["ib", "ib", "tcp"]) + ops = _ops_for(path, behaviors={"b300-2": Behavior(ssh_rc=255)}) + assert cluster_cli.main(_args(path, "--force"), ops=ops, log=lambda m: None) == 1 # past the idle check + (tcp,) = [x for x in capsys.readouterr().out.splitlines() if "b300-2" in x] + assert "node checks FAILED: ssh:" in tcp # unreachable: a failure (a clock skew alone is not) + + +def test_declared_roce_nodes_are_grouped_and_never_no_rdma(): + names = ["r-0", "r-1"] + states = [SimpleNamespace(node=SimpleNamespace(name=n, fabric="roce", env={}, cards_per_node=8), ports=None) + for n in names] + result = fg.group_nodes(names, _pair_checks(names), states=states) + assert result.no_rdma == {} and list(result.groups.values()) == [names] and result.clean + tcp = [SimpleNamespace(node=SimpleNamespace(name=n, fabric="tcp", env={}, cards_per_node=8), ports=None) + for n in names] + assert fg.group_nodes(names, _pair_checks(names), states=tcp).no_rdma == {"r-0": "tcp", "r-1": "tcp"} + + def test_a_declared_ib_node_that_runs_over_sockets_stays_fabric_unavailable(): nodes, ops = _cluster(2, socket={"b300-1"}) result = _probe(nodes, ops) diff --git a/tests/test_ssh_trainer_storage.py b/tests/test_ssh_trainer_storage.py index 9b896cabb..dc75accd4 100644 --- a/tests/test_ssh_trainer_storage.py +++ b/tests/test_ssh_trainer_storage.py @@ -264,6 +264,33 @@ def test_cost_prices_an_incarnation_by_the_declared_price_or_at_zero_on_own_node assert summary.unpriced == [] +def test_a_partly_priced_incarnation_stays_unpriced_and_the_guard_warns(tmp_path): + """REV-904b M1: 5 nodes at $3 per card hour and one without a price is not $0.""" + from yeto.cost.guard import CostGuard, GuardConfig + + ledger = ResourceLedger(tmp_path / "resources.jsonl", clock=lambda: 1000.0) + nodes = [b300(i, price_per_card_hour=3.0) for i in range(5)] + [b300(5)] + attrs = ssh_trainer_ledger.created_attrs(run_id="k31", island="t", incarnation=0, nodes=nodes, docker=True, + kill_grace_s=30) + assert (attrs["usd_per_hour"], attrs["priced_nodes"], attrs["unpriced_nodes"]) == (None, 5, 1) + ledger.created("ssh_trainer", "k31/t-i0", "t-i0", **attrs) + (item,) = billing.resource_costs(ledger.resources(), now=1000.0 + 1800).items + assert not item.priced and item.rate_usd_per_hour is None and "1 of 6 SSH nodes" in item.note + guard = CostGuard("k31", GuardConfig(), ledger=ledger, events_path=tmp_path / "events.jsonl", + clock=lambda: 1000.0 + 600, log=lambda *_: None) + guard.tick() + events = [json.loads(x) for x in (tmp_path / "events.jsonl").read_text().splitlines()] + assert [e["resource"] for e in events if e.get("event") == "cost_unpriced"] == ["ssh_trainer:k31/t-i0"] + + +def test_a_row_without_node_counts_stays_unpriced(tmp_path): + """A ledger written before the rows counted their nodes: no price is not read as $0.""" + ledger = ResourceLedger(tmp_path / "resources.jsonl", clock=lambda: 1000.0) + ledger.created("ssh_trainer", "k31/t-i0", "t-i0", run_id="k31", gpus=8, usd_per_hour=None) + (item,) = billing.resource_costs(ledger.resources(), now=1000.0 + 1800).items + assert not item.priced and "price_per_card_hour" in item.note + + def test_the_cost_guard_does_not_warn_about_own_ssh_nodes(tmp_path): """Rehearsal: every incarnation of a resident ssh trainer on own nodes (no price_per_card_hour) raised a cost_unpriced warning.""" diff --git a/yeto/cost/billing.py b/yeto/cost/billing.py index 1264ad412..4b80470c0 100644 --- a/yeto/cost/billing.py +++ b/yeto/cost/billing.py @@ -455,6 +455,19 @@ def _nc_rate(r: Resource, rates: Rates) -> float | None: OWN_SSH_NODES_NOTE = "own SSH nodes (no price_per_card_hour): $0" +def _ssh_nodes_without_price(attrs: Mapping[str, Any]) -> tuple[float | None, str]: + """``(rate, note)`` of an ssh_trainer row without ``usd_per_hour``: $0 when none of its + nodes declares ``price_per_card_hour`` (the operator's own machines, as an ``ssh:`` + sampler pool), unpriced when only some do (a forgotten price is not $0) or when the + row does not count its nodes (a ledger written before it did).""" + priced, unpriced = attrs.get("priced_nodes"), attrs.get("unpriced_nodes") + if priced == 0 and isinstance(unpriced, int) and unpriced > 0: + return 0.0, OWN_SSH_NODES_NOTE + if isinstance(priced, int) and isinstance(unpriced, int) and priced > 0: + return None, f"{unpriced} of {priced + unpriced} SSH nodes without price_per_card_hour" + return None, "SSH nodes without price_per_card_hour" + + def _span_cost(r: Resource, start: float, now: float, rate: float | None, note: str = "") -> ItemCost: end = r.released_at if r.released_at is not None else now if end < start and r.key not in _SKEW_WARNED: @@ -550,11 +563,10 @@ def covered_until(c: Resource) -> float: elif _provider_cost(r.kind) is not None: # an island provider's machine (nc_lease) items.append(_provider_cost(r.kind)(r, now, rates)) elif r.kind == "ssh_trainer": # the operator's machines: the inventory's declared price - # a node without price_per_card_hour is the operator's own machine: $0 (the inventory's - # default, as for an ssh: sampler pool), not unpriced - rate = r.attrs.get("usd_per_hour") - items.append(_span_cost(r, r.created_at, now, 0.0 if rate is None else float(rate), - "" if rate is not None else OWN_SSH_NODES_NOTE)) + rate, note = r.attrs.get("usd_per_hour"), "" + if rate is None: + rate, note = _ssh_nodes_without_price(r.attrs) + items.append(_span_cost(r, r.created_at, now, None if rate is None else float(rate), note)) elif r.kind == "sky_cluster": rate = r.attrs.get("usd_per_hour") note = "" diff --git a/yeto/launch/fabric_groups.py b/yeto/launch/fabric_groups.py index c34ff960d..66fdff3b7 100644 --- a/yeto/launch/fabric_groups.py +++ b/yeto/launch/fabric_groups.py @@ -53,6 +53,7 @@ NO_RDMA = "no RDMA fabric" NO_RDMA_NEXT = ("if the node has IB / RoCE HCAs, set its fabric to ib or roce in the inventory and probe " "again; otherwise nothing to do (yeto preflight checks the node itself)") +NO_RDMA_FAILED_NEXT = "fix the node (yeto preflight on it names the fix) and probe again" _log = logging.getLogger(__name__) @@ -228,13 +229,16 @@ class ProbeResult: pair_problems: dict[str, str] = field(default_factory=dict) bad_edges: list[tuple[str, str, str]] = field(default_factory=list) warnings: list[str] = field(default_factory=list) - # node -> its declared fabric, for the nodes that declare no RDMA fabric (``tcp``): no group by - # their own inventory, single-node islands only; not a probe failure + # node -> its declared fabric, for the nodes that declare no RDMA fabric (``tcp``; ``hccs`` is + # Ascend's in-node interconnect, no RDMA fabric between nodes either): no group by their own + # inventory, single-node islands only; not a probe failure by itself no_rdma: dict[str, str] = field(default_factory=dict) + # such a node -> its failed node checks (image pull, container, ssh, ...): those are failures + no_rdma_failed: dict[str, list[str]] = field(default_factory=dict) @property def clean(self) -> bool: - return not self.unavailable and not self.bad_edges + return not self.unavailable and not self.bad_edges and not self.no_rdma_failed def assignment(self) -> dict[str, str]: """Node name -> group name (``unavailable``: no RDMA to the others, a node that @@ -250,12 +254,16 @@ def lines(self) -> list[str]: for n, why in self.unavailable.items(): out.append(f"{UNAVAILABLE}: {n}: {'; '.join(why) or 'no RDMA edge to another node'}") for n, fabric in self.no_rdma.items(): - out.append(f"{NO_RDMA}: {n}: fabric {fabric} in the inventory: no group, single-node islands only " - f"(fabric_group {FABRIC_UNAVAILABLE}); next: {NO_RDMA_NEXT}") + head = (f"{NO_RDMA}: {n}: fabric {fabric} in the inventory: no group, single-node islands only " + f"(fabric_group {FABRIC_UNAVAILABLE})") + failed = self.no_rdma_failed.get(n) + out.append(f"{head}; node checks FAILED: {'; '.join(failed)}; next: {NO_RDMA_FAILED_NEXT}" if failed + else f"{head}; next: {NO_RDMA_NEXT}") return out def record(self) -> dict[str, Any]: return {"groups": self.groups, "unavailable": self.unavailable, "no_rdma": self.no_rdma, + "no_rdma_failed": self.no_rdma_failed, "edges": [list(e) for e in self.edges], "pair_problems": self.pair_problems, "bad_edges": [list(e) for e in self.bad_edges], "warnings": self.warnings} @@ -265,6 +273,9 @@ def record(self) -> dict[str, Any]: "dev_infiniband", "dev_infiniband_container", "memlock_container", "tools") # a FAIL of any of these: the node's HCAs cannot carry the island (no edge at all) _HCA_CHECKS = ("ib_ports", "ib_hca", "gid", "dev_infiniband") +# the node checks that fail a node declaring no RDMA fabric: what keeps the node from running the +# image (its IB / RoCE checks do not apply; ssh only when the node is unreachable, not a clock skew) +_NO_RDMA_REASONS = tuple(r for r in _NODE_REASONS if r not in (*_HCA_CHECKS, "dev_infiniband_container", "ssh")) def _over_ib(check: Any) -> bool: @@ -562,6 +573,10 @@ def group_nodes(names: Sequence[str], checks: Sequence[Any], *, states: Sequence declared = {s.node.name: getattr(s.node, "fabric", None) for s in states} no_rdma = {n: str(declared[n]) for n in names if declared.get(n) not in (None, *RDMA_FABRICS)} + unreachable = {s.node.name for s in states if getattr(s, "reachable", True) is False} + no_rdma_failed = {n: list(dict.fromkeys( + f"{c.name}: {c.detail}" for c in checks if c.scope == n and c.status == "FAIL" + and (c.name in _NO_RDMA_REASONS or (c.name == "ssh" and n in unreachable))))[:4] for n in no_rdma} names = [n for n in names if n not in no_rdma] blocked = node_blocks(names, checks, states) edges, problems, warns = evaluate_pairs(names, checks, nccl_pairs=nccl_pairs, blocked=blocked) @@ -577,7 +592,8 @@ def group_nodes(names: Sequence[str], checks: Sequence[Any], *, states: Sequence keys = {s.node.name: fabric_keys(s) for s in states} ids = assign_ids(multi, keys=keys, previous=previous, reserved=reserved) result = ProbeResult(groups=dict(sorted(zip(ids, multi))), edges=edges, pair_problems=problems, - bad_edges=bad, warnings=warns, no_rdma=dict(sorted(no_rdma.items()))) + bad_edges=bad, warnings=warns, no_rdma=dict(sorted(no_rdma.items())), + no_rdma_failed={n: why for n, why in sorted(no_rdma_failed.items()) if why}) for part in parts: if len(part) > 1: continue diff --git a/yeto/launch/ssh_trainer_ledger.py b/yeto/launch/ssh_trainer_ledger.py index 6b5d590c6..6144a2d39 100644 --- a/yeto/launch/ssh_trainer_ledger.py +++ b/yeto/launch/ssh_trainer_ledger.py @@ -21,8 +21,10 @@ script on every node, then ends the run's node leases there (inventory ``lease_store``: the row records the lease store and holder); * the cost is the inventory's declared ``price_per_card_hour`` times the cards - (:func:`usd_per_hour`); a node without a price leaves the row unpriced (the - customer's own machines). + (:func:`usd_per_hour`). The row also counts the nodes with and without a price + (``priced_nodes`` / ``unpriced_nodes``): when no node declares one, the nodes are + the operator's own machines and cost $0; when only some do, the row is unpriced + (``yeto.cost.billing``: a forgotten price is never read as $0). """ from __future__ import annotations @@ -51,7 +53,9 @@ def created_attrs(*, run_id: str, island: str, incarnation: int, nodes: Sequence return {"run_id": str(run_id), "island": str(island), "incarnation": int(incarnation), "nodes": [{"name": n.name, "host": n.host, "proxy_jump": n.proxy_jump} for n in nodes], "docker": bool(docker), "kill_grace_s": int(kill_grace_s), - "gpus": sum(n.cards_per_node for n in nodes), "usd_per_hour": usd_per_hour(nodes)} + "gpus": sum(n.cards_per_node for n in nodes), "usd_per_hour": usd_per_hour(nodes), + "priced_nodes": sum(1 for n in nodes if n.price_per_card_hour is not None), + "unpriced_nodes": sum(1 for n in nodes if n.price_per_card_hour is None)} def record(op: str, *, run_id: str, island: str, incarnation: int, attrs: dict[str, Any] | None = None) -> None: