Skip to content

[train] Make ray.train.get_preemption_info() consistent across workers - #65183

Merged
matthewdeng merged 3 commits into
ray-project:masterfrom
liulehui:stage5-bugfix
Aug 4, 2026
Merged

matthewdeng merged 3 commits into
ray-project:masterfrom
liulehui:stage5-bugfix

Conversation

@liulehui

@liulehui liulehui commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

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.

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

#63968

Additional information

unit tests

@liulehui
liulehui requested a review from a team as a code owner August 3, 2026 20:32
@liulehui liulehui added the go add ONLY when ready to merge, run all tests label Aug 3, 2026

@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 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.

Comment on lines +66 to +68
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.

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.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

correct, changed to return local value instead.

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.

Hmm wouldn't that lead to the original problem that this PR is trying to solve?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@ray-gardener ray-gardener Bot added the train Ray Train Related Issue label Aug 4, 2026
@matthewdeng
matthewdeng merged commit 28f0d09 into ray-project:master Aug 4, 2026
6 checks passed
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
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]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
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]>
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