Repository navigation
[Train] Shut down failed worker group before sizing replacement - #67651
ryanaoleary wants to merge 4 commits into
Conversation
…oller Signed-off-by: Ryan O'Leary <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Manual Testing StepsStep 1: Deploy a TPU v7x
|
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 93491ad. Configure here.
Jadiouo
left a comment
There was a problem hiding this comment.
Verified 93491ad against base d6974fe on CPU through the public API: a local Cluster with a 0-CPU head and two 1-CPU nodes, DataParallelTrainer with num_workers=(2, 2) and elastic_resize_monitor_interval_s=2.0. I removed one node mid-training and checked resources 40 s later.
- PR: on entering RestartingState the old worker group is shut down right away. 40 s later available CPU is 1.0, no placement group is left, and a standalone 1-CPU task runs within 8 s. Training restarts once the node rejoins.
- Base: in 1 of 4 runs, the failure was detected about 22 s after the node removal. The scaling decision was a no-op and the old group was not shut down. 40 s later available CPU was 0.0, the placement group was RESCHEDULING, and the 1-CPU task couldn't run. In the other 3 runs the failure was detected within 1 s, before the node was marked dead, so base resized right away and shut the old group down as a side effect. The leak therefore shows up when the node is already gone at decision time, as in your GKE preemption test, and this PR handles both orderings.
The new test fails on base and passes here; test_resize_and_fail_with_replica_groups passes on both.
…rors Signed-off-by: Ryan O'Leary <[email protected]>
) ## Why are these changes needed? When `ray.kill` terminates a TPU worker during fault recovery or elastic resizing, the Raylet releases the placement group's TPU bundle as soon as the worker IPC socket closes. Meanwhile, the Linux kernel is still releasing the dying process's VFIO devices and unpinning IOMMU DMA pages, which takes 2.1–2.4 s on an 8-core TPU v7x worker with 256 GiB of allocated HBM. Because `libtpu` and `TorchTPU` open `/dev/vfio/<group>` once without retry, a replacement worker scheduled onto the same host during that window fails with `EBUSY`: - In `JaxTrainer`, the replacement worker fails on its first `jax.devices()` call, consuming one `FailureConfig(max_failures)` retry and 7.3–9.7 s to restart the worker group. - In `TorchTrainer` with `backend="tpu_dist"`, `dist.init_process_group("tpu_dist")` runs inside `after_worker_group_start`, where a `RuntimeError` raises a non-retryable `ControllerError` that aborts the job regardless of `max_failures`. Because Linux VFIO `O_RDWR` opens are mutually exclusive, a worker must only probe its own assigned groups so it does not contend with healthy peer workers on the same host. This PR adds `wait_for_tpu_vfio_ready` in `ray._private.accelerators.tpu` and calls it before TPU distributed initialization in `JaxTrainer` and `TorchTrainer`: - `get_current_process_tpu_vfio_devices` filters `/sys/kernel/iommu_groups/<group>/devices/*/vendor` for Google TPU PCI devices with vendor ID `0x1ae0`, sorts them by PCI `domain:bus:device.function`, and groups dual-VF functions `.0` and `.1` by physical chip. - Whole-chip workers resolve their assigned VFIO groups from `TPU_VISIBLE_CHIPS`, or all chips on the host when unset. Per-device `TorchTrainer` workers using `tpu_dist` pass their single assigned device index from `TPU_VISIBLE_DEVICES` or `LOCAL_RANK`. - `wait_for_tpu_vfio_ready` probes only the current process's target `/dev/vfio/<group>` paths with `os.open` and `os.close`, polling every 50 ms while `os.open` returns `EBUSY` up to a 10 s timeout. On hosts without TPU VFIO groups, it returns immediately. ## Related issue number Contributes to [[Train] JaxTrainer Implementation Tracking Issue (ray#55162)](#55162) and [[Core][Train] Support Torch runtime with TPUs (ray#64055)](#64055). Complements [[Train] Shut down failed worker group before sizing replacement (ray#67651)](#67651). ## Checks - [x] I've signed off every commit(by using the -s flag, i.e., `git commit -s`) in this PR. - [x] I've run `scripts/format.sh` to lint the changes in this PR. - [ ] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API reference. For example, if I added a method in Python, I've added it to `doc/source/tune/api/` under the corresponding `.rst` file. - [x] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/ - Testing Strategy - [x] Unit tests (`test_tpu.py`: 121 passed, `test_torch_device_manager.py`: 8 passed, `test_jax_trainer.py`: 3 passed) and manual verification on GKE TPU v7x (see comment below) - [ ] Release tests - [ ] This PR is not tested :( --------- Signed-off-by: Ryan O'Leary <[email protected]>
…able replica groups Signed-off-by: Ryan O'Leary <[email protected]>
…overy Signed-off-by: Ryan O'Leary <[email protected]>
|
@liulehui @pseudo-rnd-thoughts this PR is ready for review if you get a chance. During elastic recovery, failed worker groups stayed alive holding nodes and |

Why are these changes needed?
Two teardown bugs in Ray Train V2 leave resources stuck or stall recovery when a worker group fails or restarts:
/dev/vfiodevices while training waits for capacity.Behavior changes
Before asking the scaling policy for a replacement size, the controller now shuts down the failed worker group unless a proper subset of replica groups can be replaced in place under Ray Train manages TorchFT replica group restarts (ray#61475):
Shutdown clears the worker group reference, so teardown runs once on restart and is skipped on later no-op polls and during resize execution. Partial replica-group failures keep the worker group intact for in-place replacement; full replica-group failures and restarts with no failing workers tear down immediately.
During shutdown, the backend setup callback now skips graceful collective teardown when the latest poll status has errors or is unfinished, matching Ray Train V1 restart behavior:
Worker group cleanup also resets the cached poll status alongside the rest of its state. Cleanly finished runs, unpolled direct worker group shutdowns, and single replica-group replacements still run graceful backend teardown.
Related issue number
Contributes to [Train] JaxTrainer Implementation Tracking Issue (ray#55162) and [Core][Train] Support Torch runtime with TPUs (ray#64055).
Complements [Train] Wait for worker TPU VFIO devices before distributed init (ray#67756).
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.doc/source/tune/api/under the corresponding.rstfile.test_controller.py,test_worker_group.py,test_controller_callback_behaviour.py,test_failure_policy.py,test_elastic_scaling_policy.py) and manual verification on GKE TPU v7x (see comment below)