Autoscaler API

RayDogNodeProvider: YellowDog as the cloud behind Ray’s autoscaler.

Ray constructs this class itself, from the provider section of a cluster YAML, in two kinds of process:

  • on the client, for each ray up, ray down, ray exec and so on. Here the provider finds the cluster by name, creates its head node, and tears the cluster down;

  • on the head node, once, inside Ray’s monitor. Here it creates and removes worker nodes as the autoscaler asks.

Which of the two it is, it reads from its own config: the copy of the config that Ray sends to the head node is stamped by prepare_for_head_node.

A node, to Ray, is a YellowDog task. Nothing is torn down as a side effect: not by the constructor, not by a failed lookup, not by garbage collection. A cluster ends only when Ray asks for its head node to be terminated, or calls cleanup_cluster_resources.

class yellowdog_ray.autoscaler.provider.RayDogNodeProvider(provider_config: dict[str, Any], cluster_name: str)[source]

Bases: NodeProvider

static bootstrap_config(cluster_config: dict[str, Any]) → dict[str, Any][source]

Check the cluster config and make it self-contained. Runs on the client before anything is created (though not before every command: Ray caches the result).

cleanup_cluster_resources() → None[source]

Called by ray down once the nodes have gone: make sure the cluster has gone with them. Never raises.

create_node(node_config: dict[str, Any], tags: dict[str, str], count: int) → dict[str, Any] | None[source]

Creates a number of nodes within the namespace.

Optionally returns a mapping from created node ids to node metadata.

Optionally may throw a ray.autoscaler.node_launch_exception.NodeLaunchException which the autoscaler may use to provide additional functionality such as observability.

create_node_with_resources_and_labels(node_config: dict[str, Any], tags: dict[str, str], count: int, resources: dict[str, float], labels: dict[str, str]) → dict[str, Any] | None[source]

Ray’s launchers call this, with what a worker’s node type declares, and each worker is given the declaration. The head’s comes from the config.

external_ip(node_id: str) → str | None[source]

Returns the external ip of the given node.

static fillout_available_node_types_resources(cluster_config: dict[str, Any]) → dict[str, Any][source]

Ray calls this just before it validates a config. RayDog uses it to fill in the general Ray settings that Ray requires but gives an external provider no defaults for, so that a cluster YAML can leave them out.

internal_ip(node_id: str) → str | None[source]

Returns the internal ip (Ray ip) of the given node.

is_running(node_id: str) → bool[source]

Return whether the specified node is running.

is_terminated(node_id: str) → bool[source]

Return whether the specified node is terminated.

node_tags(node_id: str) → dict[str, str][source]

Returns the tags of the given node (string dict).

non_terminated_nodes(tag_filters: dict[str, str]) → list[str][source]

The cluster’s live nodes with these tags. This is the one call that consults the platform; the per-node queries answer from what it found.

prepare_for_head_node(cluster_config: dict[str, Any]) → dict[str, Any][source]

The config for the head node’s copy of this provider: the same, stamped with which cluster it belongs to and where its credentials will be.

set_node_tags(node_id: str, tags: dict[str, str]) → None[source]

Sets the tag values (string dict) for the specified node.

terminate_node(node_id: str) → dict[str, Any] | None[source]

Terminates the specified node.

Optionally return a mapping from deleted node ids to node metadata.

terminate_nodes(node_ids: list[str]) → dict[str, Any] | None[source]

Stop nodes. Terminating the head node ends the whole cluster.

The RayDog part of a Ray cluster config: what it may contain and what it means.

Only two parts of the cluster YAML are RayDog’s: the provider section and each node type’s node_config. Everything here is plain data handling with no platform calls, so that a mistake is reported before anything is created.

class yellowdog_ray.autoscaler.config.HeadInfo(work_requirement_id: str, credentials_file: str)[source]

What the head node’s copy of the config is stamped with.

credentials_file: str
work_requirement_id: str
class yellowdog_ray.autoscaler.config.ProviderConfig(cluster_name: 'str', namespace: 'str', head_start_script: 'str', worker_start_script: 'str', tag: 'str | None' = None, lifetime: 'timedelta | None' = datetime.timedelta(days=1), build_timeout: 'timedelta' = datetime.timedelta(seconds=600), node_idle_shutdown: 'timedelta' = datetime.timedelta(seconds=60), worker_start_grace: 'timedelta' = datetime.timedelta(0), refresh_interval: 'timedelta' = datetime.timedelta(seconds=2), autoscaler_v2: 'bool' = True, max_workers: 'Mapping[str, int]'=<factory>, head_resources: 'Mapping[str, float]'=<factory>, head_labels: 'Mapping[str, str]'=<factory>, head: 'HeadInfo | None' = None)[source]
autoscaler_v2: bool = True
build_timeout: timedelta = datetime.timedelta(seconds=600)
cluster_name: str
head: HeadInfo | None = None
head_labels: Mapping[str, str]
head_resources: Mapping[str, float]
head_start_script: str
lifetime: timedelta | None = datetime.timedelta(days=1)
max_workers: Mapping[str, int]
namespace: str
node_idle_shutdown: timedelta = datetime.timedelta(seconds=60)
refresh_interval: timedelta = datetime.timedelta(seconds=2)
settings() → ClusterSettings[source]
tag: str | None = None
worker_start_grace: timedelta = datetime.timedelta(0)
worker_start_script: str