Skip to content

[train] Revert Train V2 reservation pinning (#66002, #66646) - #67337

Merged
pseudo-rnd-thoughts merged 2 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:revert-train-reservation-pinning
Oct 27, 2026
Merged

pseudo-rnd-thoughts merged 2 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:revert-train-reservation-pinning

Conversation

@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member

Description

Reverts #66646, then #66002, so Train V2 schedules workers the way it did in 2.59. #66001 and #66370 stay; without these two PRs, Train only uses the AutoscalingCoordinator's reservation to count how many workers fit.

#66002 pins every Train V2 worker to a node from the coordinator's reservation, using a ray.io/node-id bundle label selector. #66646 builds on it. The reservation was built to size autoscaler requests, and it isn't accurate enough to pin to:

  • It counts capacity that isn't available. It's built from the nodes ray.nodes() reports as Alive, which includes draining nodes, and it uses each node's total resources rather than what's free. So it can reserve a node that is draining, or capacity that's already held by work that never went through the coordinator (any other task, actor, placement group or Serve replica).
  • It moves. It's recomputed from scratch on every tick, ordered by resources whose memory value differs slightly even between nodes of the same type. When a node joins, an existing run's reservation can move to other nodes, including nodes another run is using.

When a pin is wrong, the run can't go anywhere else. The pinned placement group never gets placed, and the autoscaler sees no unmet demand, because request_resources already counts the reserved capacity. The controller retries the same pins after each startup timeout, and with the default controller_failure_limit=-1 it never stops.

Reproductions on master

With ray.cluster_utils.Cluster, a head node plus worker nodes X and Y, each with one slot resource. X sorts first in the coordinator. A one-worker run asks for {"slot": 1}, with RAY_TRAIN_WORKER_GROUP_START_TIMEOUT_S=5:

State of X Pinning off Master (#66002 + #66646)
X's slot held by an actor that didn't go through the coordinator Starts on Y on the first attempt Never starts: 12 startup attempts in 60s, all pinned to X
X draining after a preemption notice (still Alive=True) Starts on Y on the first attempt Never starts: same loop

Driving _AutoscalingCoordinatorActor directly with two runs holding reservations, one node joining with slightly more memory moves both reservations. The second run's new reservation then lands on nodes where the first run's workers are already running.

A fixed-size run that asks for more than the cluster has keeps the TrainController actor at 101% CPU while it waits, and abort() can't reach it. #66646 made the fixed scaling policy wait for its reservation inside the controller loop, and _step never awaits on that path.

Other failures

Bringing pinning back

The goal of #66002, keeping concurrent runs off each other's capacity, still stands. A follow-up can bring pinning back as a single change, off by default behind a flag. It should let a pin cost at most one startup attempt, retrying unpinned if the pinned placement group doesn't place in time. It should also make the reservation leave out draining nodes and stay put when nodes join.

Not part of this revert

_step also busy-waits for elastic runs below min_workers, and that predates #66002. The yield in #66763 fixes it and applies with or without this revert.

Related issues

Reverts #66002 and #66646. Related to #66766, #66794, #66762, #66763, #66765 and #67327.

These open PRs build on #66002 and would need rebasing or closing: #66762, #66763 and #66765.

For releases/2.60.0, which has #66002 but not #66646, a matching revert of #66002 will follow as a cherry-pick. It's the alternative to #67327, which cherry-picks #66646 onto that branch instead.

Additional information

Not a duplicate. No open PR reverts #66002 or #66646.

Revert details. Two commits: git revert c85447533d (#66646), then git revert e39557f46c (#66002). Both applied cleanly. #66225's later change to controller.py merged automatically. No master commit has touched these files since #66646. No references to the removed functions remain. pre-commit passes on all changed files.

Testing. Run locally on macOS:

pytest python/ray/train/v2/tests/test_elastic_scaling_policy.py        # 15 passed
pytest python/ray/train/v2/tests/test_autoscaling_coordinator_client.py # 1 passed
pytest python/ray/train/v2/tests/test_failure_policy.py                # 18 passed
pytest python/ray/train/tests/test_autoscaling_coordinator_client.py   # 3 passed
pytest python/ray/train/v2/tests/test_controller.py                    # 22 passed
pytest python/ray/train/v2/tests/test_controller_callback_behaviour.py # 10 passed
pytest python/ray/train/v2/tests/test_worker_group.py                  # 39 passed
pytest python/ray/train/v2/tests/test_scheduling.py                    # 7 passed
pytest python/ray/data/tests/test_autoscaling_coordinator.py           # 55 passed
pytest python/ray/train/v2/tests/test_elastic_e2e.py                   # 1 passed
pytest python/ray/train/v2/tests/test_data_integration.py              # 26 passed

I haven't run the train_elastic_e2e_with_node_killing release test on this branch.

AI assistance (Claude Code) was used to investigate the failures, write the reproductions, make this revert and write this description.

🤖 Generated with Claude Code

Mark Towers and others added 2 commits October 23, 2026 18:32
…zed them (ray-project#66646)"

This reverts commit c854475.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
…vations (ray-project#66002)"

This reverts commit e39557f.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 23, 2026 17:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the node-pinning logic (label selectors) from Ray Train V2's scaling policies and worker group startup, simplifying resource requests and placement group waiting. It also moves the _get_reserved_resources method directly into ElasticScalingPolicy. A bug was identified in this new method where transient failures when fetching reserved resources would incorrectly overwrite and clear the cached _latest_reserved_resources with None. A code suggestion was provided to ensure the cache is only updated upon a successful query.

Comment on lines +266 to +285
reserved_resources = None
try:
reserved_resources = ray.get(
self._autoscaling_coordinator.get_reserved_resources.remote(
self._requester_id
),
timeout=AUTOSCALING_REQUESTS_GET_TIMEOUT_S,
)
except Exception:
msg = (
f"Failed to get reserved resources for {self._requester_id}."
" Will not resize the worker group."
" If this only happens transiently during network partition or"
" CPU being overloaded, it's safe to ignore this error."
" If this error persists, file a GitHub issue."
)
logger.warning(msg, exc_info=True)
finally:
self._latest_reserved_resources_query_time = time_monotonic()
self._latest_reserved_resources = reserved_resources

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In _get_reserved_resources, if ray.get raises an exception, reserved_resources remains None. In the finally block, self._latest_reserved_resources is then overwritten with None. This clears the cache on any transient failure (such as a temporary network partition or coordinator timeout), which causes subsequent calls within GET_RESERVED_RESOURCES_INTERVAL_S to also return None instead of the last known good cached resources.

We should only update self._latest_reserved_resources when the query succeeds, allowing the cache to persist and be returned on transient failures.

Suggested change
reserved_resources = None
try:
reserved_resources = ray.get(
self._autoscaling_coordinator.get_reserved_resources.remote(
self._requester_id
),
timeout=AUTOSCALING_REQUESTS_GET_TIMEOUT_S,
)
except Exception:
msg = (
f"Failed to get reserved resources for {self._requester_id}."
" Will not resize the worker group."
" If this only happens transiently during network partition or"
" CPU being overloaded, it's safe to ignore this error."
" If this error persists, file a GitHub issue."
)
logger.warning(msg, exc_info=True)
finally:
self._latest_reserved_resources_query_time = time_monotonic()
self._latest_reserved_resources = reserved_resources
try:
reserved_resources = ray.get(
self._autoscaling_coordinator.get_reserved_resources.remote(
self._requester_id
),
timeout=AUTOSCALING_REQUESTS_GET_TIMEOUT_S,
)
self._latest_reserved_resources = reserved_resources
except Exception:
msg = (
f"Failed to get reserved resources for {self._requester_id}."
" Will not resize the worker group."
" If this only happens transiently during network partition or"
" CPU being overloaded, it's safe to ignore this error."
" If this error persists, file a GitHub issue."
)
logger.warning(msg, exc_info=True)
finally:
self._latest_reserved_resources_query_time = time_monotonic()

@pseudo-rnd-thoughts pseudo-rnd-thoughts added train Ray Train Related Issue go add ONLY when ready to merge, run all tests labels Oct 23, 2026
sai-miduthuri added a commit that referenced this pull request Oct 26, 2026
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]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit 5e0d20c into ray-project:master Oct 27, 2026
7 checks passed
pseudo-rnd-thoughts pushed a commit to pseudo-rnd-thoughts/ray that referenced this pull request Oct 27, 2026
…oordinator's view is wrong

Train V2 sizes its worker group from the AutoscalingCoordinator's
reservation, which is built from each node's total capacity, counts
draining nodes as alive, and is recomputed from scratch when nodes join or
leave. Pinning workers to that reservation (ray-project#66002, reverted in ray-project#67337)
turned each of the following into a run that retried the same pins forever.
These tests assert that the run starts and finishes instead:

- Capacity held outside the coordinator: an actor holds node X's slot. The
  run must start on node Y.
- Draining node: X is draining after a preemption notice and is still
  reported alive. The run must start on Y.
- Node churn with two runs: a node joins and sorts first, then the node of
  the second run is removed. The second run must restart on the new node
  without disturbing the first, and both must finish.
- STRICT_SPREAD on an autoscaling cluster (ray-project#66766): the autoscaler must
  launch one node per worker, and the run must start on two nodes.

Each run's driver and controller stay on the head node, so the scenarios can
drain and remove worker nodes. Against the code before the revert, the
occupied and draining tests time out, the churn test's second run loops
on WorkerGroupStartupTimeoutError while the new node sits free, and the
STRICT_SPREAD run waits forever on a reservation that covers one node.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants