Repository navigation
[data] Track autoscaling coordinator reservations per node - #66001
Conversation
The autoscaling coordinator reserved resources as a flat list of bundles, which told a requester how much it had but not where. Callers that want to pin work to the capacity reserved for them (Ray Train, next in this stack) can't do that without node identity. Key the reservation by node id instead: - `get_reserved_resources()` returns `Dict[NodeIdStr, ResourceDict]`, keyed in the order bundles were placed so callers can tell which node holds which bundle. - `request_resources()` takes a `strategy` (PACK/SPREAD/STRICT_PACK/ STRICT_SPREAD) controlling how a requester's bundles are distributed over nodes. STRICT_PACK collapses the bundles into one sum so the autoscaler is asked for a single node big enough to hold them. The strategy is fixed for the lifetime of a request: flipping it would reshuffle every bundle out from under whatever the requester already placed. - `request_remaining` becomes a list of resource types rather than a bool, so leftovers are split per type among the requesters that asked for that type instead of all-or-nothing. - `get_reserved_resources(force=True)` recomputes against a fresh view of the cluster, for callers that turn the answer into node pins and must not pin to a node that has since died. - Nodes are scanned largest-CPU-first so packing prefers big nodes. - `_tick` no longer lets an exception escape: it runs on a bare background thread, where that would silently stop autoscaling for every requester on the cluster. Train V2's `_count_possible_workers` is updated for the new return type; its coordinator integration lands in the next commit in this stack. Test: pytest python/ray/data/tests/test_autoscaling_coordinator.py Signed-off-by: iamjustinhsu <[email protected]> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes core reservation and leftover-sharing logic used by Ray Data autoscaling and Train worker counting; incorrect placement or stale `recompute` behavior could mis-size clusters or pin to dead nodes. > > **Overview** > Ray Data’s autoscaling coordinator now reports **where** capacity is reserved, not just **how much**, and exposes finer control over leftovers and bundle placement. > > **`get_reserved_resources()`** returns a per-node map (`node_id → resource bundle`) instead of a flat bundle list. Ray Data autoscalers and Ray Train’s elastic scaling policy sum over `.values()` when computing totals; Train can use node identity for pinning in follow-up work. > > **`request_resources()`** gains a **`strategy`** (`PACK` / `SPREAD` / `STRICT_PACK` / `STRICT_SPREAD`) that drives `_compute_reservations` when rereserving cluster capacity. **`STRICT_PACK`** also collapses requested bundles (and label selectors) into one summed bundle when forwarding to the autoscaler SDK. Strategy and **`request_remaining`** cannot change mid-request. > > **`request_remaining`** is no longer a boolean: callers pass a list of resource types (e.g. **`STANDARD_RESOURCE_TYPES`**) so leftover CPU/GPU/memory/object store is split **per type** among requesters that asked for that type, merged onto the same node keys as explicit reservations. > > Other coordinator behavior: nodes are ordered for placement like Ray Core (largest capacity first); actor **`get_reserved_resources(..., recompute=True)`** runs a full tick before answering; background **`_tick`** swallows exceptions so one failure does not stop cluster-wide autoscaling. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5f1e10f943716edad17f470566729c1ad26bfc87. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Signed-off-by: iamjustinhsu <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request refactors the autoscaling coordinator to track reserved resources on a per-node basis (using node ID mappings) rather than as a flat list of resource bundles, and introduces explicit placement strategies (PACK, SPREAD, STRICT_PACK, STRICT_SPREAD). It also updates the request_remaining parameter to target specific resource types and adapts Ray Train's elastic scaling policy and tests to the new dictionary structure. The review feedback highlights potential runtime errors or crashes during node sorting and resource mapping if NodeID or Resources are missing or None, suggesting safer fallback defaults.
| def _sort_key(node): | ||
| # Mirrors Ray Core's bundle ordering in scarcest resource first, most of it first. | ||
| # Core also ranks custom resources (between GPU and object store | ||
| # memory); we skip them, since it's opaque to us. NodeID breaks ties so | ||
| # the order is stable across ticks. | ||
| resources = node.get("Resources", {}) | ||
| return ( | ||
| -resources.get("GPU", 0), | ||
| -resources.get("object_store_memory", 0), | ||
| -resources.get("memory", 0), | ||
| -resources.get("CPU", 0), | ||
| node.get("NodeID", ""), | ||
| ) |
There was a problem hiding this comment.
If node.get("Resources") or node.get("NodeID") is None, this function can raise an AttributeError or TypeError during sorting, which would cause the background tick thread to fail. Using node.get("Resources") or {} and node.get("NodeID") or "" is much safer and prevents potential crashes.
| def _sort_key(node): | |
| # Mirrors Ray Core's bundle ordering in scarcest resource first, most of it first. | |
| # Core also ranks custom resources (between GPU and object store | |
| # memory); we skip them, since it's opaque to us. NodeID breaks ties so | |
| # the order is stable across ticks. | |
| resources = node.get("Resources", {}) | |
| return ( | |
| -resources.get("GPU", 0), | |
| -resources.get("object_store_memory", 0), | |
| -resources.get("memory", 0), | |
| -resources.get("CPU", 0), | |
| node.get("NodeID", ""), | |
| ) | |
| def _sort_key(node): | |
| # Mirrors Ray Core's bundle ordering in scarcest resource first, most of it first. | |
| # Core also ranks custom resources (between GPU and object store | |
| # memory); we skip them, since it's opaque to us. NodeID breaks ties so | |
| # the order is stable across ticks. | |
| resources = node.get("Resources") or {} | |
| return ( | |
| -resources.get("GPU", 0), | |
| -resources.get("object_store_memory", 0), | |
| -resources.get("memory", 0), | |
| -resources.get("CPU", 0), | |
| node.get("NodeID") or "", | |
| ) |
| node_id = node.get("NodeID", "") | ||
| per_node_resource = cluster_node_resources.setdefault(subcluster, {}) | ||
| per_node_resource[node_id] = node["Resources"] |
There was a problem hiding this comment.
If node.get("NodeID") is None, node_id will be None. Additionally, accessing node["Resources"] directly can raise a KeyError if the key is missing, or store None if the value is None. It is safer to use node.get("NodeID") or "" and node.get("Resources") or {} to prevent potential runtime errors.
| node_id = node.get("NodeID", "") | |
| per_node_resource = cluster_node_resources.setdefault(subcluster, {}) | |
| per_node_resource[node_id] = node["Resources"] | |
| node_id = node.get("NodeID") or "" | |
| per_node_resource = cluster_node_resources.setdefault(subcluster, {}) | |
| per_node_resource[node_id] = node.get("Resources") or {} |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8dac4e1. Configure here.
| f" until the next tick in {self.TICK_INTERVAL_S} seconds." | ||
| " If this error persists, file a GitHub issue.", | ||
| exc_info=RAY_DATA_AUTOSCALING_COORDINATOR_LOG_TRACEBACK, | ||
| ) |
There was a problem hiding this comment.
Tick failure skips reservation refresh
Medium Severity
A failure in _merge_and_send_requests is caught by _tick and then skips _update_cluster_node_resources and _refresh_resource_reservations. get_reserved_resources(recompute=True) calls _tick, so a send error leaves reservations pointing at nodes that have already died.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 8dac4e1. Configure here.
Co-authored-by: Mark Towers <[email protected]> Signed-off-by: Mark Towers <[email protected]>
…ct#66001) The autoscaling coordinator reserved resources as a flat list of bundles, which told a requester how much it had but not where. Callers that want to pin work to the capacity reserved for them (Ray Train, next in this stack) can't do that without node identity. Key the reservation by node id instead: - `get_reserved_resources()` returns `Dict[NodeIdStr, ResourceDict]`, keyed in the order bundles were placed so callers can tell which node holds which bundle. - `request_resources()` takes a `strategy` (PACK/SPREAD/STRICT_PACK/ STRICT_SPREAD) controlling how a requester's bundles are distributed over nodes. STRICT_PACK collapses the bundles into one sum so the autoscaler is asked for a single node big enough to hold them. The strategy is fixed for the lifetime of a request: flipping it would reshuffle every bundle out from under whatever the requester already placed. - `request_remaining` becomes a list of resource types rather than a bool, so leftovers are split per type among the requesters that asked for that type instead of all-or-nothing. - `get_reserved_resources(force=True)` recomputes against a fresh view of the cluster, for callers that turn the answer into node pins and must not pin to a node that has since died. - Nodes are scanned largest-CPU-first so packing prefers big nodes. - `_tick` no longer lets an exception escape: it runs on a bare background thread, where that would silently stop autoscaling for every requester on the cluster. Train V2's `_count_possible_workers` is updated for the new return type; its coordinator integration lands in the next commit in this stack. Test: pytest python/ray/data/tests/test_autoscaling_coordinator.py <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes core reservation and leftover-sharing logic used by Ray Data autoscaling and Train worker counting; incorrect placement or stale `recompute` behavior could mis-size clusters or pin to dead nodes. > > **Overview** > Ray Data’s autoscaling coordinator now reports **where** capacity is reserved, not just **how much**, and exposes finer control over leftovers and bundle placement. > > **`get_reserved_resources()`** returns a per-node map (`node_id → resource bundle`) instead of a flat bundle list. Ray Data autoscalers and Ray Train’s elastic scaling policy sum over `.values()` when computing totals; Train can use node identity for pinning in follow-up work. > > **`request_resources()`** gains a **`strategy`** (`PACK` / `SPREAD` / `STRICT_PACK` / `STRICT_SPREAD`) that drives `_compute_reservations` when rereserving cluster capacity. **`STRICT_PACK`** also collapses requested bundles (and label selectors) into one summed bundle when forwarding to the autoscaler SDK. Strategy and **`request_remaining`** cannot change mid-request. > > **`request_remaining`** is no longer a boolean: callers pass a list of resource types (e.g. **`STANDARD_RESOURCE_TYPES`**) so leftover CPU/GPU/memory/object store is split **per type** among requesters that asked for that type, merged onto the same node keys as explicit reservations. > > Other coordinator behavior: nodes are ordered for placement like Ray Core (largest capacity first); actor **`get_reserved_resources(..., recompute=True)`** runs a full tick before answering; background **`_tick`** swallows exceptions so one failure does not stop cluster-wide autoscaling. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5f1e10f943716edad17f470566729c1ad26bfc87. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- > Thank you for contributing to Ray! 🚀 > Please review the [Ray Contribution Guide](https://docs.ray.io/en/master/ray-contribute/getting-involved.html) before opening a pull request. >⚠️ Remove these instructions before submitting your PR. > 💡 Tip: Mark as draft if you want early feedback, or ready for review when it's complete. ## Description > Briefly describe what this PR accomplishes and why it's needed. ## Related issues > Link related issues: "Fixes ray-project#1234", "Closes ray-project#1234", or "Related to ray-project#1234". ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. Signed-off-by: iamjustinhsu <[email protected]>
…ssed (ray-project#66370) Co-authored-by: Mark Towers <[email protected]> Signed-off-by: Mark Towers <[email protected]>
…ct#66001) The autoscaling coordinator reserved resources as a flat list of bundles, which told a requester how much it had but not where. Callers that want to pin work to the capacity reserved for them (Ray Train, next in this stack) can't do that without node identity. Key the reservation by node id instead: - `get_reserved_resources()` returns `Dict[NodeIdStr, ResourceDict]`, keyed in the order bundles were placed so callers can tell which node holds which bundle. - `request_resources()` takes a `strategy` (PACK/SPREAD/STRICT_PACK/ STRICT_SPREAD) controlling how a requester's bundles are distributed over nodes. STRICT_PACK collapses the bundles into one sum so the autoscaler is asked for a single node big enough to hold them. The strategy is fixed for the lifetime of a request: flipping it would reshuffle every bundle out from under whatever the requester already placed. - `request_remaining` becomes a list of resource types rather than a bool, so leftovers are split per type among the requesters that asked for that type instead of all-or-nothing. - `get_reserved_resources(force=True)` recomputes against a fresh view of the cluster, for callers that turn the answer into node pins and must not pin to a node that has since died. - Nodes are scanned largest-CPU-first so packing prefers big nodes. - `_tick` no longer lets an exception escape: it runs on a bare background thread, where that would silently stop autoscaling for every requester on the cluster. Train V2's `_count_possible_workers` is updated for the new return type; its coordinator integration lands in the next commit in this stack. Test: pytest python/ray/data/tests/test_autoscaling_coordinator.py <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes core reservation and leftover-sharing logic used by Ray Data autoscaling and Train worker counting; incorrect placement or stale `recompute` behavior could mis-size clusters or pin to dead nodes. > > **Overview** > Ray Data’s autoscaling coordinator now reports **where** capacity is reserved, not just **how much**, and exposes finer control over leftovers and bundle placement. > > **`get_reserved_resources()`** returns a per-node map (`node_id → resource bundle`) instead of a flat bundle list. Ray Data autoscalers and Ray Train’s elastic scaling policy sum over `.values()` when computing totals; Train can use node identity for pinning in follow-up work. > > **`request_resources()`** gains a **`strategy`** (`PACK` / `SPREAD` / `STRICT_PACK` / `STRICT_SPREAD`) that drives `_compute_reservations` when rereserving cluster capacity. **`STRICT_PACK`** also collapses requested bundles (and label selectors) into one summed bundle when forwarding to the autoscaler SDK. Strategy and **`request_remaining`** cannot change mid-request. > > **`request_remaining`** is no longer a boolean: callers pass a list of resource types (e.g. **`STANDARD_RESOURCE_TYPES`**) so leftover CPU/GPU/memory/object store is split **per type** among requesters that asked for that type, merged onto the same node keys as explicit reservations. > > Other coordinator behavior: nodes are ordered for placement like Ray Core (largest capacity first); actor **`get_reserved_resources(..., recompute=True)`** runs a full tick before answering; background **`_tick`** swallows exceptions so one failure does not stop cluster-wide autoscaling. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5f1e10f943716edad17f470566729c1ad26bfc87. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- > Thank you for contributing to Ray! 🚀 > Please review the [Ray Contribution Guide](https://docs.ray.io/en/master/ray-contribute/getting-involved.html) before opening a pull request. >⚠️ Remove these instructions before submitting your PR. > 💡 Tip: Mark as draft if you want early feedback, or ready for review when it's complete. ## Description > Briefly describe what this PR accomplishes and why it's needed. ## Related issues > Link related issues: "Fixes ray-project#1234", "Closes ray-project#1234", or "Related to ray-project#1234". ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. Signed-off-by: iamjustinhsu <[email protected]>
…ssed (ray-project#66370) Co-authored-by: Mark Towers <[email protected]> Signed-off-by: Mark Towers <[email protected]>
Reverts #66002 on `releases/2.60.0`. This is the release-branch counterpart of #67337, which reverts #66646 and then #66002 on master. This branch never had #66646, so only #66002 is reverted here. ## Why #66002 pins every Train V2 worker to a node from the AutoscalingCoordinator's reservation. #67337 explains why that reservation isn't accurate enough to pin to: - It counts draining nodes and capacity held by work that never went through the coordinator. - It moves when nodes join. When a pin is wrong, the pinned placement group never gets placed, and the controller retries the same pins indefinitely. On this branch, the `train_elastic_e2e_with_node_killing.aws` release test failed in 3 of its 5 weekly release-pipeline runs. In builds 109533 and 111090 it looped on `WorkerGroupStartupTimeoutError` until the job timed out. #66766, where STRICT_SPREAD runs can wait forever, also bisects to #66002. After this revert, Train V2 schedules workers the way it did in 2.59. #66001 and #66370 stay, as in #67337, so Train still uses the coordinator's reservation to count how many workers fit. This is the alternative to #67327, which cherry-picks #66646 onto this branch instead. If this PR merges, #67327 should be closed. ## Revert details `git revert e39557f` applied with no conflicts, and git merged #66225's later change to `controller.py` automatically. The revert touches 11 files, with 70 insertions and 759 deletions. - The diff is byte-identical to #67337's revert of #66002 (deb5235), index lines included. - Before the revert, the 11 files on this branch were identical to master right after #67337 reverts #66646. After the revert, they match #67337's head. - No code on this branch references the functions or classes the revert removes. The few names that still have references are definitions that existed before #66002, such as the Ray Data coordinator's `get_reserved_resources`. Not a duplicate: no PR against `releases/2.60.0` reverts #66002. #67337 targets `master`. ## Testing | Command | Result | |---|---| | pre-commit, run as the commit hook on the 11 changed files | Passed (ruff, black, pydoclint, Ray Train circular imports, and the other applicable hooks) | I didn't run the unit tests locally. CI runs them on this PR: - `:bullettrain_front: ml: train v2 tests` runs the `train_v2`-tagged tests, including `test_controller.py`, `test_elastic_scaling_policy.py`, `test_autoscaling_coordinator_client.py` and `test_failure_policy.py`. - `:train: ml: train v1 tests` runs `python/ray/train/tests/test_autoscaling_coordinator_client.py`. - `:train: ml: data integration tests` runs `test_data_integration.py`. #67337 ran the same test files against the same resulting code on master, and they passed. AI assistance was used to prepare this revert. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Sai Miduthuri <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
The coordinator offers nodes to requesters largest first (ray-project#66001). `_sort_key` compared `object_store_memory` and `memory` before CPU and NodeID. Those two come from the free system memory when the raylet starts, so they differ slightly even between nodes of the same type. A node that joined with a little more memory sorted ahead of existing nodes of its type, so every requester's reservation shifted by one node on the next tick. Compare only GPU and CPU, which the node's type fixes. Among nodes of the same shape, order by the view update in which the coordinator first saw the node, then by NodeID. A new node now sorts after existing nodes of its type, while a larger node still sorts first. Rounding memory instead would still split two nodes of the same type that straddle a bucket edge. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
The coordinator offers nodes to requesters largest first (ray-project#66001). `_sort_key` compared `object_store_memory` and `memory` before CPU and NodeID. Those two come from the free system memory when the raylet starts, so they differ slightly even between nodes of the same type. A node that joined with a little more memory sorted ahead of existing nodes of its type, so every requester's reservation shifted by one node on the next tick. Compare only GPU and CPU, which the node's type fixes. Among nodes of the same shape, order by the view update in which the coordinator first saw the node, then by NodeID. A new node now sorts after existing nodes of its type, while a larger node still sorts first. Rounding memory instead would still split two nodes of the same type that straddle a bucket edge. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>


The autoscaling coordinator reserved resources as a flat list of bundles,
which told a requester how much it had but not where. Callers that want to
pin work to the capacity reserved for them (Ray Train, next in this stack)
can't do that without node identity.
Key the reservation by node id instead:
get_reserved_resources()returnsDict[NodeIdStr, ResourceDict], keyedin the order bundles were placed so callers can tell which node holds which bundle.
request_resources()takes astrategy(PACK/SPREAD/STRICT_PACK/ STRICT_SPREAD) controlling how a requester's bundles are distributed overnodes. STRICT_PACK collapses the bundles into one sum so the autoscaler is
asked for a single node big enough to hold them. The strategy is fixed for
the lifetime of a request: flipping it would reshuffle every bundle out
from under whatever the requester already placed.
request_remainingbecomes a list of resource types rather than a bool,so leftovers are split per type among the requesters that asked for that
type instead of all-or-nothing.
get_reserved_resources(force=True)recomputes against a fresh view ofthe cluster, for callers that turn the answer into node pins and must not
pin to a node that has since died.
_tickno longer lets an exception escape: it runs on a bare backgroundthread, where that would silently stop autoscaling for every requester on
the cluster.
Train V2's
_count_possible_workersis updated for the new return type; its coordinator integration lands in the next commit in this stack.Test: pytest python/ray/data/tests/test_autoscaling_coordinator.py
Note
Medium Risk
Changes core reservation and leftover-sharing logic used by Ray Data
autoscaling and Train worker counting; incorrect placement or stale
recomputebehavior could mis-size clusters or pin to dead nodes.Overview
Ray Data’s autoscaling coordinator now reports where capacity is
reserved, not just how much, and exposes finer control over leftovers and bundle placement.
get_reserved_resources()returns a per-node map (node_id → resource bundle) instead of a flat bundle list. Ray Data autoscalers and Ray Train’s elastic scaling policy sum over.values()when computing totals; Train can use node identity for pinning in follow-up work.request_resources()gains astrategy(PACK/SPREAD/STRICT_PACK/STRICT_SPREAD) that drives_compute_reservationswhen rereserving cluster capacity.STRICT_PACKalso collapses requested bundles (and label selectors) into one summed bundle when forwarding to the autoscaler SDK. Strategy andrequest_remainingcannot change mid-request.request_remainingis no longer a boolean: callers pass a list ofresource types (e.g.
STANDARD_RESOURCE_TYPES) so leftover CPU/GPU/memory/object store is split per type among requesters that asked for that type, merged onto the same node keys as explicit reservations.Other coordinator behavior: nodes are ordered for placement like Ray
Core (largest capacity first); actor
get_reserved_resources(..., recompute=True)runs a full tick before answering; background_tickswallows exceptions so one failure does not stop cluster-wide autoscaling.Reviewed by Cursor Bugbot for commit
5f1e10f943716edad17f470566729c1ad26bfc87. Bugbot is set up for automated code reviews on this repo. Configure
here.
Description
Related issues
Additional information