Repository navigation
[train] Pin worker groups to the reservation snapshot that sized them - #66646
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Justin Yu <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request refactors the scaling policy and worker group initialization in Ray Train v2 to handle node-pinning and reservation decisions more robustly. It updates both elastic and fixed scaling policies to include node-pinning label selectors directly in the resize decisions, built from fresh reservation snapshots. Additionally, the worker group now monitors pinned nodes and aborts waiting for placement groups early if a pinned node dies. The review feedback suggests improving robustness against transient failures: wrapping the ray.nodes() liveness check in a try-except block to handle GCS query failures, and explicitly handling None returns from _get_reserved_resources(recompute=True) in both elastic and fixed scaling policies to prevent misleading log outputs.
| alive_node_ids = {node["NodeID"] for node in ray.nodes() if node["Alive"]} | ||
| dead_node_ids = pinned_node_ids - alive_node_ids | ||
| if dead_node_ids: | ||
| logger.info( | ||
| "Giving up on the placement group early: the worker group is " | ||
| f"pinned to nodes that are no longer alive: {sorted(dead_node_ids)}." | ||
| ) | ||
| return False |
There was a problem hiding this comment.
Querying ray.nodes() directly inside the placement group wait loop can raise transient exceptions (e.g., RaySystemError or gRPC timeouts) if the GCS is temporarily overloaded or recovering from a node failure. Wrapping this call in a try-except block ensures that transient GCS query failures do not crash the entire controller/worker group startup, allowing it to retry or continue waiting gracefully.
| alive_node_ids = {node["NodeID"] for node in ray.nodes() if node["Alive"]} | |
| dead_node_ids = pinned_node_ids - alive_node_ids | |
| if dead_node_ids: | |
| logger.info( | |
| "Giving up on the placement group early: the worker group is " | |
| f"pinned to nodes that are no longer alive: {sorted(dead_node_ids)}." | |
| ) | |
| return False | |
| try: | |
| alive_node_ids = {node["NodeID"] for node in ray.nodes() if node["Alive"]} | |
| dead_node_ids = pinned_node_ids - alive_node_ids | |
| if dead_node_ids: | |
| logger.info( | |
| "Giving up on the placement group early: the worker group is " | |
| f"pinned to nodes that are no longer alive: {sorted(dead_node_ids)}." | |
| ) | |
| return False | |
| except Exception as e: | |
| logger.warning( | |
| f"Failed to query ray.nodes() to check pinned node liveness: {e}" | |
| ) |
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]>
Description
test_elastic_e2ehas been timing out on CI since #66002, which pins Train V2 workers to AutoscalingCoordinator reservations. The elastic worker group start waits the full 60s (RAY_TRAIN_WORKER_GROUP_START_TIMEOUT_S) whenever the reservation changes between the scaling decision and pinning. The decision is sized from the cached reservation, while the pins come from a separaterecompute=Truepoll in_try_get_selectors, so:max_workersbundles, so afterResizeDecision(14)the reservation can reach 32 slots.len(label_selectors) != num_workersthen never passes.This PR takes the decision and the pins from the same snapshot, so they can't disagree:
ResizeDecision.ResizeDecision.label_selectorsis built by the scaling policy from the reservation that chosenum_workers, using the same_floor_slotsmath. The STRICT_PACK/STRICT_SPREAD layout check from [train] Pin Train V2 workers to autoscaling coordinator reservations … #66002 is kept. The controller just applies the pins and no longer polls the coordinator.recompute=True) view. In the non-running path it reads the fresh view only once the cached one looks ready, so waiting doesn't trigger a full coordinator tick every loop.make_decision_for_non_running_worker_group(returningNoopDecisionuntil every worker is covered), the same way elastic waits formin_workers. This removesget_reserved_bundle_label_selectors, its 60s poll loop, and the controller'sWorkerGroupStartupTimeoutErrorraise. Both policies log a rate-limited "Waiting for reserved resources" message while they wait. Before, elastic logged nothing when nothing was reserved.ray.nodes()reports dead, but the GCS can still report a just-removed node as alive for a short time. A pin made in that window can never be placed, soWorkerGroupnow pollspg_handle.wait()in 1s intervals and stops as soon as a pinned node is no longer alive. It raises the same retryableWorkerGroupStartupTimeoutErrorinstead of stalling for 60s.test_elastic_e2ehits this window on purpose by removing every node and restarting right away. Locally this went from a 60s stall to giving up after about 1s.Skipping pins (TPU, zero-resource workers, user
label_selector) moves intoScalingPolicy._should_pin_to_reservation. The controller still lets a callback-providedlabel_selectorwin, because the policy can't see those.Behavior change: a fixed run waiting for capacity no longer fails and retries every 60s through the failure policy. It waits in the controller loop like elastic. With the default
controller_failure_limit=-1, the only visible difference is the log messages.Related issues
Alternative to #66601, which fixes the same
test_elastic_e2eflake differently: it picks a subset of a larger reservation with_compute_reservationsand adds a relative_FIT_EPSILONto the coordinator's shared_bundle_can_fit_on_node. This PR avoids the Train → Ray Data_compute_reservationsdependency and leaves the coordinator's fit check, which every requester shares, unchanged. It also avoids an extra restart when the reservation grows, because it starts at the size the reservation supports now.Testing
All passing locally (macOS,
ray_dev_py311):In the last
test_elastic_e2erun, the controller log shows the "decide 4 right after every node was removed" restart stopping after about 1s ("Giving up on the placement group early…") instead of the 60s stall seen before the early-stop change.Known gap: when it stops early, the retried
WorkerGroupStartupTimeoutErrorstill says "timed out after 60.0 seconds". The info log just before it gives the real reason.AI assistance (Claude Code) was used to write this change.
🤖 Generated with Claude Code