Skip to content

[train] Add end-to-end scheduling tests for Train V2 worker placement - #67421

Merged
pseudo-rnd-thoughts merged 3 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/scheduling-regression-tests
Oct 27, 2026
Merged

pseudo-rnd-thoughts merged 3 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:train-autoscaler/scheduling-regression-tests

Conversation

@pseudo-rnd-thoughts

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Description

Adds end-to-end scheduling tests to python/ray/train/v2/tests/test_scheduling.py. They check that a Train V2 run still starts and finishes in cases the existing tests don't cover.

Most existing Train scheduling tests stub the AutoscalingCoordinator. Its view of the cluster can be wrong in three ways:

  • Total capacity per node, not free capacity, so it can't see work that never registered with it.
  • Nodes ray.nodes() reports as alive, which includes draining nodes.
  • A from-scratch recompute whenever nodes join or leave, so reservations move.

The pinning in #66002, reverted in #67337, turned the first three cases below into runs that retried forever, and no test noticed.

Test Scenario Must happen
test_starts_when_a_node_is_unusable[slot_held_outside_the_coordinator] Node X sorts first, but its only slot is held by an actor that never registered with the coordinator The run starts on node Y
test_starts_when_a_node_is_unusable[draining] X is busy and draining after a preemption notice, so it is still Alive The run starts on Y
test_concurrent_runs_survive_node_churn Runs A and B each hold a slot. A node joins and sorts first, then B's node is removed B restarts on the new node, A isn't disturbed, and both finish
test_runs_queue_for_a_single_slot Run A holds the only slot when run B is submitted B keeps retrying past a failed start attempt, then starts on the same node once A finishes
test_a_finished_run_releases_its_resources A run finishes on the only slot node Its placement group is removed, a new HIGH-priority coordinator request gets the slot, and a second run lands on the same node
test_strict_spread_starts_on_an_autoscaling_cluster A STRICT_SPREAD run on an AutoscalingCluster (autoscaler v2) with no worker nodes The autoscaler launches one node per worker and the run starts
test_strict_pack_starts_on_an_autoscaling_cluster A 4-worker STRICT_PACK run on the same kind of cluster The autoscaler launches a node with room for every worker, and all 4 workers start there

Implementation notes:

  • Shared cluster for existing tests. The PACK/SPREAD and label-selector tests never change their cluster, so they now share one class-scoped cluster, in TestOnSharedCluster, instead of starting five. A module-scoped cluster would stay up while the other tests start their own.
  • Driver on the head node. Each new run's driver, and so its controller, runs in a task pinned to the head node, so the tests can drain and remove worker nodes.
  • Short start timeout. The new tests' cluster fixtures set RAY_TRAIN_WORKER_GROUP_START_TIMEOUT_S=5, so failed attempts cycle quickly.
  • Pickling. The module registers itself with ray.cloudpickle.register_pickle_by_value, so workers don't need to import it.
  • No GPU on the head. The autoscaling tests set GPU: 0 on the head. Otherwise, on a host with a GPU, for example a Mac, Ray detects one on the head, and STRICT_SPREAD then needs one launched node fewer. That hides the bug.
  • Bazel size. The target is already exclusive, which AutoscalingCluster needs because it runs ray stop --force. Its size goes from medium to large.

Not covered here. These belong with the fixes in #67422 that make them pass:

  • elastic runs with a draining or occupied node;
  • aborting a run while it waits for resources;
  • the coordinator actor's node dying.

The coordinator's priority ordering, Train at HIGH ahead of Ray Data, has no unit test yet either.

AI assistance (Claude Code) was used to write these tests, check them against broken code, and write this description.

🤖 Generated with Claude Code

…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
pseudo-rnd-thoughts force-pushed the train-autoscaler/scheduling-regression-tests branch from e6704bc to 3eb6a6b Compare October 27, 2026 10:08
…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]>
@pseudo-rnd-thoughts pseudo-rnd-thoughts changed the title [train] Add regression tests for Train V2 worker placement when the coordinator's view is wrong [train] Add end-to-end scheduling tests for Train V2 worker placement Oct 27, 2026
@pseudo-rnd-thoughts pseudo-rnd-thoughts added train Ray Train Related Issue go add ONLY when ready to merge, run all tests labels Oct 27, 2026
@pseudo-rnd-thoughts
pseudo-rnd-thoughts marked this pull request as ready for review October 27, 2026 14:25
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 27, 2026 14:25

@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 updates the test_scheduling target size to large and introduces a comprehensive set of new tests in test_scheduling.py to verify scheduling behavior under various cluster scenarios, including node churn, resource queuing, and autoscaling. A critical issue was identified in the _drain helper function, where GcsClient.drain_node is passed a hex string node_id instead of its binary representation, which will cause a TypeError.

Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit df4c47a into ray-project:master Oct 27, 2026
6 checks passed
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