Repository navigation
[train] Make ray.train.get_preemption_info() consistent across workers - #65183
Conversation
Signed-off-by: Lehui Liu <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a generic collective operation framework to Ray Train, specifically adding support for an all_gather operation alongside the existing broadcast operation. This is used to ensure that preemption information is consistently merged and synchronized across all training workers, preventing deadlocks when workers branch based on preemption status. The feedback from the reviewer highlights a potential race condition where a fast worker could start a new collective round and overwrite active data before slower workers finish reading it. To address this, the reviewer suggests tracking which ranks have already joined the current active round using a new _has_joined state variable.
| Returns ``None`` if the barrier was reset while waiting, which happens when a | ||
| worker dies and the replica group is replaced. Callers should fall back to | ||
| their local value in that case rather than failing the training function. |
There was a problem hiding this comment.
Is this behavior intentional? If a node gets preempted, shouldn't we want the other workers to still detect preemption so that they can do checkpointing?
There was a problem hiding this comment.
correct, changed to return local value instead.
There was a problem hiding this comment.
Hmm wouldn't that lead to the original problem that this PR is trying to solve?
There was a problem hiding this comment.
actually, I removed the try/catch as currently it is unreachable.
we exclude torchft from preemption signal feature support, so SyncActor won't reset if worker died. https://github.com/ray-project/ray/blob/master/python/ray/train/v2/_internal/execution/controller/controller.py#L208-L220
here if the preemption happens in this collective, the UDF will raise, similar to preemption happens during ray.train.report().
We will have a follow up implementation to relax the barrier among health ranks, including report() and get_preemption_info() so that health ranks can do checkpointing with preempted ranks gone.
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
ray-project#65183) ## Description `ray.train.get_preemption_info()` (added in ray-project#64360) was a local, per-worker read. The preemption notice is fanned out to workers as independent, un-awaited RPCs, so different workers might observe it on different steps, which will cause an issue in the below example. ```python for step in range(total_steps): train_step() # DDP gradient all-reduce: a barrier if ray.train.get_preemption_info() is not None: ray.train.report(metrics, checkpoint=ckpt) # report(): another barrier ``` Let's assume that the preemption signal lands on rank 1 first | | rank 0 | rank 1 | |---|---|---| | step N, after `train_step()` | local read → `None` → **skips** the branch | local read → `Info` → **enters** `report()` | | step N | proceeds to `train_step()` → blocks in the DDP all-reduce | blocked in the `report()` barrier | Deadlock. Rank 0 waits for rank 1's gradients; rank 1 waits for rank 0 to reach `report()`. This PR makes `ray.train.get_preemption_info()` a collective with broadcast_from_rank_zero, so all ranks reads the same preemption info as rank0 sees.. The value is now safe to use as the condition for another collective, e.g. ray.train.report(). After this change, both ranks receive `Info` on the same step and enter `report()` together. Other considerations I have and rejected by myself: 1. add another `ray.train.reach_preemption_sync_point()`. this way we have `ray.train.get_preemption_info()` as non consistent read while `ray.train.reach_preemption_sync_point()` do a collective, but the non consistent read api does not add a lot value and eventually need to preemption info, and two user api will introduce disagreement and hurt usability. 2. in the follow up PR, we will address relaxing the barrier among health ranks ## Related issues ray-project#63968 ## Additional information unit tests --------- Signed-off-by: Lehui Liu <[email protected]>
ray-project#65183) ## Description `ray.train.get_preemption_info()` (added in ray-project#64360) was a local, per-worker read. The preemption notice is fanned out to workers as independent, un-awaited RPCs, so different workers might observe it on different steps, which will cause an issue in the below example. ```python for step in range(total_steps): train_step() # DDP gradient all-reduce: a barrier if ray.train.get_preemption_info() is not None: ray.train.report(metrics, checkpoint=ckpt) # report(): another barrier ``` Let's assume that the preemption signal lands on rank 1 first | | rank 0 | rank 1 | |---|---|---| | step N, after `train_step()` | local read → `None` → **skips** the branch | local read → `Info` → **enters** `report()` | | step N | proceeds to `train_step()` → blocks in the DDP all-reduce | blocked in the `report()` barrier | Deadlock. Rank 0 waits for rank 1's gradients; rank 1 waits for rank 0 to reach `report()`. This PR makes `ray.train.get_preemption_info()` a collective with broadcast_from_rank_zero, so all ranks reads the same preemption info as rank0 sees.. The value is now safe to use as the condition for another collective, e.g. ray.train.report(). After this change, both ranks receive `Info` on the same step and enter `report()` together. Other considerations I have and rejected by myself: 1. add another `ray.train.reach_preemption_sync_point()`. this way we have `ray.train.get_preemption_info()` as non consistent read while `ray.train.reach_preemption_sync_point()` do a collective, but the non consistent read api does not add a lot value and eventually need to preemption info, and two user api will introduce disagreement and hurt usability. 2. in the follow up PR, we will address relaxing the barrier among health ranks ## Related issues ray-project#63968 ## Additional information unit tests --------- Signed-off-by: Lehui Liu <[email protected]> Signed-off-by: 400Ping <[email protected]>
ray-project#65183) ## Description `ray.train.get_preemption_info()` (added in ray-project#64360) was a local, per-worker read. The preemption notice is fanned out to workers as independent, un-awaited RPCs, so different workers might observe it on different steps, which will cause an issue in the below example. ```python for step in range(total_steps): train_step() # DDP gradient all-reduce: a barrier if ray.train.get_preemption_info() is not None: ray.train.report(metrics, checkpoint=ckpt) # report(): another barrier ``` Let's assume that the preemption signal lands on rank 1 first | | rank 0 | rank 1 | |---|---|---| | step N, after `train_step()` | local read → `None` → **skips** the branch | local read → `Info` → **enters** `report()` | | step N | proceeds to `train_step()` → blocks in the DDP all-reduce | blocked in the `report()` barrier | Deadlock. Rank 0 waits for rank 1's gradients; rank 1 waits for rank 0 to reach `report()`. This PR makes `ray.train.get_preemption_info()` a collective with broadcast_from_rank_zero, so all ranks reads the same preemption info as rank0 sees.. The value is now safe to use as the condition for another collective, e.g. ray.train.report(). After this change, both ranks receive `Info` on the same step and enter `report()` together. Other considerations I have and rejected by myself: 1. add another `ray.train.reach_preemption_sync_point()`. this way we have `ray.train.get_preemption_info()` as non consistent read while `ray.train.reach_preemption_sync_point()` do a collective, but the non consistent read api does not add a lot value and eventually need to preemption info, and two user api will introduce disagreement and hurt usability. 2. in the follow up PR, we will address relaxing the barrier among health ranks ## Related issues ray-project#63968 ## Additional information unit tests --------- Signed-off-by: Lehui Liu <[email protected]>
Description
ray.train.get_preemption_info()(added in #64360) was a local, per-worker read. The preemption notice is fanned out to workers as independent, un-awaited RPCs, so different workers might observe it on different steps, which will cause an issue in the below example.Let's assume that the preemption signal lands on rank 1 first
train_step()None→ skips the branchInfo→ entersreport()train_step()→ blocks in the DDP all-reducereport()barrierDeadlock. Rank 0 waits for rank 1's gradients; rank 1 waits for rank 0 to reach
report().This PR makes
ray.train.get_preemption_info()a collective with broadcast_from_rank_zero, so all ranks reads the same preemption info as rank0 sees.. The value is now safe to use as the condition for another collective, e.g. ray.train.report().After this change, both ranks receive
Infoon the same step and enterreport()together.Other considerations I have and rejected by myself:
ray.train.reach_preemption_sync_point(). this way we haveray.train.get_preemption_info()as non consistent read whileray.train.reach_preemption_sync_point()do a collective, but the non consistent read api does not add a lot value and eventually need to preemption info, and two user api will introduce disagreement and hurt usability.Related issues
#63968
Additional information
unit tests