Repository navigation
[train][data] Fix the Train controller busy-wait and the autoscaling coordinator's view of the cluster - #67422
Closed
pseudo-rnd-thoughts wants to merge 9 commits into
Conversation
…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]>
pseudo-rnd-thoughts
force-pushed
the
train-autoscaler/historic-scheduling-fixes
branch
from
October 27, 2026 10:08
dbe903a to
d31d473
Compare
…eing, release and STRICT_PACK cases The tests check scheduling cases Train V2 must handle, so they belong with the existing placement tests rather than in a file of their own. - Merge the occupied-node and draining-node tests into one parametrized test, test_starts_when_a_node_is_unusable. - Add test_runs_queue_for_a_single_slot: a run waiting for a slot another run holds keeps retrying, then starts on that node once it frees up. - Add test_a_finished_run_releases_its_resources: a finished run gives back its placement group and its coordinator request, so a new request at the same priority gets the slot and a second run lands on the same node. - Add test_strict_pack_starts_on_an_autoscaling_cluster: the autoscaler launches a node with room for every STRICT_PACK worker. - The PACK/SPREAD and label-selector tests don't change their cluster, so they share one class-scoped cluster instead of starting five. - Remove the test_scheduling_regressions target and make test_scheduling large. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
…ecision In INITIALIZING, RESTARTING and RESCHEDULING, `TrainController._step` never awaits. While the scaling policy keeps returning `NoopDecision` (an elastic run waiting for `min_workers` to fit, or a failed coordinator query), `run()` loops without giving up the event loop. The controller actor then spins a full core, and calls like `abort()` can't reach it. This has been the case for elastic runs since elastic training landed; it isn't caused by the reservation pinning that was reverted. `_step` now sleeps `RAY_TRAIN_HEALTH_CHECK_INTERVAL_S` before asking the policy again, matching the running path's poll interval. Once `abort()` can run during that sleep, the control loop must not overwrite the `AbortedState` it sets with the state the iteration computed before the abort, or `run()` would go back to waiting. The loop now leaves a terminal state set concurrently by `abort()` in place. The yield is the control-loop change from ray-project#66763, split out so it can land on its own. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
…sk dies with its node `terminate_node` runs `terminate_current_instance` on the node it terminates, with hard node affinity and the default task retries. The task usually dies with the instance, so Ray retries it, and the retry can never be scheduled: its node is gone. `ray.get` then raises `TaskUnschedulableError`, which fails `train_elastic_e2e_with_node_killing` even when training finished successfully (failure mode A in the release history). Don't retry the killer task, and treat `NodeDiedError`, `WorkerCrashedError` and `TaskUnschedulableError` as the node having gone down, which is the intended outcome. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
`_update_cluster_node_resources` kept every node that `ray.nodes()` reports as `Alive`. A draining node, for example one with a preemption notice or an autoscaler idle-termination drain, still reports `Alive`, but the raylet scheduler rejects new work on it (`ClusterResourceScheduler::NodeAvailable`). So the coordinator reserved capacity that nobody could use: Ray Data budgeted for it, and Train's elastic policy sized runs from it. Ask the GCS for draining nodes on every view refresh and drop them. The query is injectable, like the actor's other cluster dependencies. If it fails, the refresh carries on without draining info instead of failing the whole tick, and it warns on the first failure of a run rather than on every tick. 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]>
`_refresh_resource_reservations` recomputed every requester's reservation from scratch on every tick. When a node joined or left, requesters that weren't on it moved too, often onto nodes another requester had held, for example where that requester's workers were still running. Ray Train needs a requester's reservation to describe where its workers can go, so it can't use a view that moves under it like that. Make explicit reservations sticky. Keep each requester's explicit placement, without its leftover shares, on `OngoingRequest`, and on the next refresh pass `_compute_reservations` a per-requester node order: the nodes the requester held, in the order it held them, then nodes no other live requester held, then the rest. Requesters are still placed in priority order, so a higher-priority requester that arrives later still gets capacity, taking free nodes before nodes others hold. `_compute_reservations` stays pure, and each strategy keeps its meaning: STRICT_PACK uses one node, STRICT_SPREAD distinct nodes, and PACK and SPREAD scan the given order. SPREAD still round-robins over every node, so it can spread onto a node that just joined. Leftover shares are still split per node on every refresh, as before. Because a requester now prefers nodes nobody else holds, its explicit bundles can land on different nodes than before. Where capacity is fragmented, the new order can fit a bundle more or fewer. And since the leftover is split per node with integer division, a requester's total can shift by less than one unit per node and resource type. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
`get_or_create_autoscaling_coordinator` created the detached coordinator with hard node affinity to the first caller's node and `max_restarts=-1`. That caller can be on any node, for example a Train controller or a Ray Data executor running inside a Train worker. If that node died, the actor couldn't be rescheduled (`ActorUnschedulableError`), and every Ray Data and Ray Train requester on the cluster lost the coordinator for good. Soft affinity doesn't keep the local-node preference for this actor: `ClusterResourceScheduler::GetBestSchedulableNode` places an actor that requests no resources on a random node unless its affinity is hard. So the actor would land on any node, including autoscaled workers it would restart off whenever they scale down. Pin it to the head node instead, with a tiny amount of the head node's `node:__internal_head__` resource, the way Ray Serve places its controller. The head node lives as long as the cluster, and a restarted head, with GCS fault tolerance, has the same resource, so the actor can restart there. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
…and losing the coordinator's node Each test fails without the fix in this branch that it covers: - test_elastic_run_starts_when_a_node_is_unusable[draining]: an elastic run of one or two workers starts with one worker when the other node is draining. Without the draining exclusion it retries two workers forever. - test_elastic_run_starts_when_a_node_is_unusable[slot_held_outside_the_coordinator]: marked xfail(strict=True). Elastic runs still size themselves from total capacity, so they retry two workers forever. This records the known gap. - test_ctrl_c_aborts_a_run_waiting_for_workers: Ctrl-C on a real driver process aborts an elastic run waiting for min_workers within 30s. Without the controller yield, the abort never reaches the controller. A Ray task can't stand in for the driver, because a task blocked in ray.get doesn't run Python signal handlers. - test_run_restarts_after_the_coordinators_first_caller_dies: the coordinator is created from node X, a run starts on X and Y, then X dies. The run, which holds a handle to the coordinator, restarts on Y. Without the head-node placement the coordinator dies with X and the run never restarts. - test_higher_priority_request_is_reserved_first: when two requests' bundles don't both fit, a later HIGH request is reserved ahead of an earlier MEDIUM one. Nothing tested the priority ordering before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
pseudo-rnd-thoughts
force-pushed
the
train-autoscaler/historic-scheduling-fixes
branch
from
October 27, 2026 12:16
d31d473 to
368523a
Compare
Member
Author
|
Closed in favor of smaller PRs that implement the different fixes |
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes scheduling problems in Train V2 and the AutoscalingCoordinator that predate the reservation pinning in #66002. The pinning made them visible; its revert (#67337) doesn't fix them. Each fix comes with a test that fails without it.
Before
Train controller: while the scaling policy keeps returning
NoopDecision, for example an elastic run waiting formin_workers,TrainController._stepnever awaits.abort()can't reach it, so Ctrl-C doesn't stop the run.This has been true for elastic runs since [train] Add Elastic Training Capability for Ray Train #60721.
Coordinator, draining nodes: a draining node still reports
Aliveinray.nodes(), so the coordinator counts it, although the scheduler rejects new work there.Coordinator, node order: the order is unstable. The sort key compared per-node
memoryandobject_store_memory, which come from free memory at raylet start, so a newly joined node could jump ahead of existing ones.Coordinator, reservations: every refresh recomputed all reservations from scratch, so a node joining moved requesters that weren't on it.
Coordinator, placement: the coordinator actor ran on the first caller's node, with hard affinity and
max_restarts=-1. If that node died, the actor couldn't be rescheduled. A new caller gets a fresh actor, but requesters that already hold a handle lose it. Train's coordinator client caches its handle, so a running elastic run can't resize or restart.Release harness:
terminate_nodein the elastic node-killing release test runs its killer task on the node it kills, with default retries. The retry can't be scheduled, so the test failed after training had already finished.After
The controller sleeps
RAY_TRAIN_HEALTH_CHECK_INTERVAL_Sbefore asking the policy again, which yields the event loop.abort()that runs during the sleep is no longer overwritten by the state computed before it.The coordinator drops the nodes in
get_draining_nodes(), through an injectable query. If the query fails, it carries on without draining info and warns once.Node order sorts by
(-GPU, -CPU, first seen, NodeID). Largest-first packing is kept, and a new node of the same type sorts last.Reservations stay put. Each requester's placement is kept, and the next refresh tries nodes in this order:
Priority order and strategy semantics are unchanged.
The coordinator actor requests
node:__internal_head__: 0.001, the way Ray Serve places its controller, so it lives on the head node. Soft affinity wouldn't help: the scheduler places a zero-resource actor on a random node unless its affinity is hard.The killer task isn't retried, and
NodeDiedError,WorkerCrashedErrorandTaskUnschedulableErrorcount as the node having gone down.flowchart TD subgraph Before subgraph BS[Subsystem: resource allocation] subgraph BC[Component: AutoscalingCoordinator] B0[actor on first caller's node] B1["ray.nodes() Alive, including draining"] --> B2[sort by GPU, CPU, memory] --> B3[recompute every reservation] end end end subgraph After subgraph AS[Subsystem: resource allocation] subgraph AC[Component: AutoscalingCoordinator] A0[actor on head node] A1["ray.nodes() Alive minus draining"] --> A2[sort by GPU, CPU, first seen] --> A3[keep each requester's nodes first] end end end classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class A0,A1,A2,A3 changedWhat Ray Data users may notice:
request_remainingrequesters, per-node integer division can shift a requester's leftover total by less than one unit per node per resource.Known gaps, not fixed here:
xfail(strict=True). This needs its own design.Subsystems
cluster_autoscaler/. This carries the behavioural change for Ray Data.elastic_util.py.Testing
All runs were local on macOS, on master with Ray rebuilt:
New tests, each confirmed to fail without the fix it covers:
test_elastic_run_starts_when_a_node_is_unusable[draining]test_ctrl_c_aborts_a_run_waiting_for_workerstest_run_restarts_after_the_coordinators_first_caller_diestest_abort_while_waiting_for_a_scaling_decision(controller unit test)TimeoutErrortest_higher_priority_request_is_reserved_firstNot run:
train_elastic_e2e_with_node_killingrelease test.Not a duplicate. I searched open PRs for the coordinator, draining, the controller yield and the release harness. The only overlap is #66763, which bundles the same yield with the Fixed-policy reservation wait from the reverted pinning. This PR takes only the yield, and adds the abort guard.
Related to #67421, #67337, #66002, #66646, #60721 and #66763.
AI assistance (Claude Code) was used to write these changes and tests, run the suites, and write this description.
🤖 Generated with Claude Code