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
3 changes: 2 additions & 1 deletion tests/test_node_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def test_a_bad_lease_store_is_refused(value):


def test_the_unknown_field_message_names_lease_store():
with pytest.raises(InventoryError, match=r"known: \['images', 'lease_store', 'node_health', 'nodes'\]"):
with pytest.raises(InventoryError,
match=r"known: \['images', 'lease_store', 'node_health', 'nodes', 'site_images'\]"):
parse_inventory({"lease": "s3://x", "nodes": [_raw(0)]})


Expand Down
677 changes: 677 additions & 0 deletions tests/test_site_images.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/yeto_home_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"YETO_ISLANDS_LOG_DIR": "islands", # yeto.rl.trainer_worker.LocalLaunchOps launch logs
"YETO_SSH_RUNS_DIR": "ssh-runs", # yeto.rl.ssh_harness.prepare plans
"YETO_VERDA_IDS_PATH": "verda-instance-ids.json", # yeto.sky_patches.verda
"YETO_SITE_IMAGES_PATH": "site-images.yaml", # yeto.launch.site_images.default_path
}
# Points into one real run's ledger when inherited from an operator shell.
CLEARED_ENV = ("YETO_RESOURCE_LEDGER",)
Expand Down
21 changes: 18 additions & 3 deletions yeto/launch/node_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
of a file without ``images:`` may have no image: an ``ssh:`` trainer island runs
the run's ``--rl-image`` (an inventory image must then name the same one), an SSH
sampler pool its ``container.image``. The trainer preflight also compares ``uname -m`` with
``cpu_arch``.
``cpu_arch``. The top-level ``site_images:`` names the site image catalog
(:mod:`yeto.launch.site_images`, default ``~/.yeto/site-images.yaml``; a relative path
is taken from the inventory's directory): an island or pool of these nodes that names
no image takes the catalog's verified image for its model there.

Example::

Expand Down Expand Up @@ -472,6 +475,17 @@ def parse_node(raw: Any, *, index: int, images: Mapping[str, str] | None = None,
return node


def site_images_value(document: Any) -> str | None:
"""The inventory document's top-level ``site_images:``, the site image catalog's path
(:mod:`yeto.launch.site_images`; None: not given). Refuses a value that is not a path."""
if not isinstance(document, Mapping) or document.get("site_images") is None:
return None
value = document["site_images"]
if not isinstance(value, str) or not value.strip():
raise InventoryError(f"inventory site_images: must be a file path, not {value!r}")
return value


def parse_inventory(document: Any) -> NodeList:
"""The ``nodes:`` list of a loaded inventory document (a :class:`NodeList`: with
the top-level ``lease_store``)."""
Expand All @@ -481,14 +495,15 @@ def parse_inventory(document: Any) -> NodeList:
if isinstance(document, list):
entries = document
elif isinstance(document, dict):
unknown = sorted(set(document) - {"nodes", "images", "node_health", "lease_store"})
unknown = sorted(set(document) - {"nodes", "images", "node_health", "lease_store", "site_images"})
if unknown:
raise InventoryError(f"unknown top-level inventory field(s) {unknown} "
f"(known: ['images', 'lease_store', 'node_health', 'nodes'])")
f"(known: ['images', 'lease_store', 'node_health', 'nodes', 'site_images'])")
entries = document.get("nodes")
images = parse_images(document.get("images"))
health = parse_node_health(document.get("node_health"), "inventory")
lease_store = parse_lease_store(document.get("lease_store"))
site_images_value(document)
else:
raise InventoryError(f"the inventory must be a mapping with a nodes list, got "
f"{type(document).__name__}")
Expand Down
71 changes: 64 additions & 7 deletions yeto/launch/rl_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,71 @@ def resolve_default_rl_image(args) -> None:
except backends.UnknownBackend as exc:
raise ValueError(str(exc)) from None
if getattr(args, "rl_image", None) is None:
flags = _rl_backend_module(args, "launch_flags")
if getattr(flags, "DEFAULT_RL_IMAGE", None): # rl-verl-backend: Modal-built engine image
args.rl_image = flags.DEFAULT_RL_IMAGE
import sys

nodes, why = _site_catalog_trainer_nodes(args)
if nodes is not None: # an all-ssh: trainer fleet whose inventory names no image
from . import site_images

try:
choice = site_images.select(
None, getattr(args, "model", None), "trainer", nodes,
engine=getattr(args, "rl_backend", None) or backends.DEFAULT_BACKEND,
path=site_images.inventory_catalog_path(getattr(args, "rl_node_inventory", None)),
default=lambda: _builtin_rl_image(args))
except site_images.SiteImagesError as exc:
raise ValueError(str(exc)) from None
args.rl_image = f"docker:{choice.ref}" if choice.source == site_images.SOURCE_SITE else choice.ref
print(f"[launcher] {choice.line('ssh trainer')}", file=sys.stderr, flush=True)
return
from ..rl import default_rl_image

args.rl_image = default_rl_image(recipe=getattr(args, "rl_model_recipe", None),
tuning=getattr(args, "tuning", None))
args.rl_image = _builtin_rl_image(args)
if why:
print(f"[launcher] trainer image {args.rl_image} (source: built-in default; {why})", file=sys.stderr,
flush=True)


def _builtin_rl_image(args) -> str:
"""The engine's pinned default ``--rl-image``."""
flags = _rl_backend_module(args, "launch_flags")
if getattr(flags, "DEFAULT_RL_IMAGE", None): # rl-verl-backend: Modal-built engine image
return flags.DEFAULT_RL_IMAGE
from ..rl import default_rl_image

return default_rl_image(recipe=getattr(args, "rl_model_recipe", None), tuning=getattr(args, "tuning", None))


MIXED_FLEET = ("the --gpu fleet mixes ssh: and cloud islands: the site image catalog is read only when every "
"--gpu entry is ssh:")


def _site_catalog_trainer_nodes(args) -> tuple[list | None, str]:
"""``(nodes, why)``: the trainer nodes of a ``--gpu`` whose every entry is an ``ssh:``
island and whose ``--rl-node-inventory`` names no image for them (the site image
catalog may then give one, :mod:`yeto.launch.site_images`); None for any other launch
(no ssh: island, no inventory, an inventory image: the configuration names its image).
``why``: the line a mixed fleet (ssh: and cloud islands) prints for its built-in
default (a cloud island's cards do not take part in a site match)."""
path = getattr(args, "rl_node_inventory", None)
if not path or not getattr(args, "gpu", None):
return None, ""
from ..gpu_spec import parse_gpu_spec
from .node_inventory import InventoryError, load_inventory

try:
clouds = [spec.cloud for spec in parse_gpu_spec(args.gpu)]
if "ssh" not in clouds:
return None, ""
# the trainer nodes and their spares (a role of the trainer's kind: trainer-spare): a spare
# that replaces a node runs the island's image, so the record must fit it too
nodes = [n for n in load_inventory(path)
if not n.roles or any(r == "trainer" or r.startswith("trainer-") for r in n.roles)]
except (ValueError, InventoryError): # the launch's own checks name a bad --gpu or inventory
return None, ""
if not nodes or any(n.image for n in nodes):
return None, ""
if not all(cloud == "ssh" for cloud in clouds):
return None, MIXED_FLEET
return nodes, ""


def _rl_callable(value: str | None, flag: str, *, required: bool) -> None:
Expand Down
Loading
Loading