Repository navigation
[train][1/n] Add ray.train.health contracts: probes, health state, decisions, policies - #66536
Conversation
33f0fd7 to
a4dc0c5
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new health monitoring framework under 'ray.train.health', defining core abstractions for health decisions, policies, probes, and state tracking, along with associated unit tests. The feedback suggests enhancing 'HealthState.results' to support instance-level probe names and to explicitly validate that the probe class subclasses a supported concrete probe type (raising a 'TypeError' if not). This change requires importing 'NodeProbe' in 'state.py'. Additionally, the reviewer recommends adding unit tests to verify these new behaviors.
d94216f to
ca1a0d4
Compare
matthewdeng
left a comment
There was a problem hiding this comment.
General recommendation is that we should aim to be as restrictive as possible in this version of the API. It will be easier for us to expand rather than restrict it over time.
| probe_creator: Optional[ProbeCreator] = None | ||
| evaluator_creator: Optional[EvaluatorCreator] = None |
There was a problem hiding this comment.
Should these be optional or required?
There was a problem hiding this comment.
can both optional but not at the same time (NOOP), added a __post__init__ for validation.
There was a problem hiding this comment.
Should this just default to a func that returns empty list instead?
| Attributes: | ||
| probe_creator: Builds the policy's probes, once per run. | ||
| evaluator_creator: Builds the policy's evaluators, once per run. | ||
| preflight: Also run the policy's ``OnDemandProbe``s on every candidate |
There was a problem hiding this comment.
Is there ever a scenario where OnDemandProbes are defined here but not used for preflight?
There was a problem hiding this comment.
for a OnDemand Probe that needs to be run both at preflight and midtrain.
user should create:
a PreflightHealthPolicy contains that ProbeA
a midTrainingHealthPolicy contains that ProbeA
and pass HealthConfig(policies=[PreflightHealthPolicy(), midTrainingHealthPolicy()])
ca1a0d4 to
c8b882b
Compare
There was a problem hiding this comment.
Reviewing the example, you have ClusterProbe and OnDemandProbe that don't exist here. Do the types of probes help? Can't everything be done with just the superclass rather than users inherit from one of the probe subclasses in here
Could you produce a UML diagram of the classes as its not clear here or in the REP how the classes are combined together
sure, updated the PR description with the UML diagram. |
106314d to
cdab83d
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cdab83d. Configure here.
matthewdeng
left a comment
There was a problem hiding this comment.
nice nice, thanks for adding the mermaid diagram, made it very easy to review
|
|
||
| probe_creator: Optional[ProbeCreator] = None | ||
| evaluator_creator: Optional[EvaluatorCreator] = None | ||
| preflight: bool = False |
There was a problem hiding this comment.
Should preflight be an attribute of the HealthPolicy or the Probe itself?
My gut feeling is that we might want to somehow unify preflight with Diagnose since they run once, whereas the Probe interface currently has a poll_interval_s attribute, which doesn't actually apply for these?
There was a problem hiding this comment.
I think preflight should be an attribute of Policy and now the HealthCheck. But I moved it off from both so that HealthCheck is now just probes + evaluators, and when it runs is set by where it's placed:
- HealthConfig.checks: run periodically while training runs
- explictly specify HealthConfig.preflight_checks: run once on each node before training starts
- Diagnose(checks=[...]): run once, whenever HealthDecision is Diagnose.
So pre-flight and Diagnose share one shape: run a set of checks once.
On poll_interval_s: I kept it on Probe so each probe can sample at its own rate. The docstring now says it only applies when the probe is polled periodically and is unused when it's polled once. That seemed simpler than a separate probe type or mixin, which would make probe authors decide up front how their probe will be used.
| @abc.abstractmethod | ||
| def poll(self) -> ProbeResult: | ||
| """Poll this worker once. | ||
|
|
||
| Returns: | ||
| The result. | ||
| """ | ||
| raise NotImplementedError |
There was a problem hiding this comment.
This seems to be the same in WorkerProbe and NodeProbe -- upstream to Probe for now?
There was a problem hiding this comment.
I kept poll() on each subclass: ControllerProbe (ray-project/ray#66648 · [train][2/n] Add ControllerProbe…) returns {key: ProbeResult} rather than one ProbeResult, this is because some tool like NVSentinel and NcclRas already has the global view. the key here is either NodeIdStr or rank id.
shared Probe.poll() would have to be overridden with a different return type.
There was a problem hiding this comment.
I did some research, I think for controller probe, we still want to keep {key: ProbeResult} in the beginning, which can support NVSentinel, NVRx, NcclRas.
We can extend it the return type later if we see if cannot be covered.
…ns, policies First layer of the Ray Train Monitoring and Diagnostics stack. Adds the data contracts only; nothing is wired into the controller yet. - probe.py: ProbeResult (metrics and a timestamp), Probe, WorkerProbe and NodeProbe. - state.py: HealthState, the latest ProbeResult per probe, keyed by world rank or node ID. - decision.py: Action, Noop, Reattempt, Evict, Diagnose. - policy.py: Evaluator, HealthPolicy, HealthConfig. All public classes are PublicAPI(alpha). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
…strings - Rename HealthPolicy to HealthCheck (policy.py -> check.py): probes and the evaluators that decide on their readings. HealthConfig.policies becomes checks, and the preflight flag moves out of the check into HealthConfig.preflight_checks, so where a check runs is set by where it is placed. - Diagnose takes checks instead of probes, so the evaluators that decide on a one-off poll come with it. - Evict is keyword-only and target_nodes is required, so Evict(["n1"]) no longer evicts nothing. - Remove HealthState.results(); evaluators read probe_results by Probe.probe_name(). - poll_interval_s stays on Probe and only applies when the probe is polled periodically. - Docstrings describe the interfaces only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
30d6ff1 to
e99d7a3
Compare
| mid_training_checks: List[HealthCheck] = field(default_factory=list) | ||
| preflight_checks: List[HealthCheck] = field(default_factory=list) |
There was a problem hiding this comment.
What does it mean to have poll_interval_s for a Probe in a preflight check?
There was a problem hiding this comment.
after our discussion, changed to
PeriodicProbe: a Probe + poll_interval_s
OnDemandProbe: for a run once Probe, later we can add stop_worker as an attribute.
- Add PeriodicProbe(probe, poll_interval_s) and OnDemandProbe(probe), and remove poll_interval_s from Probe. A HealthCheck's probe_creator returns wrapped probes. - Move Evaluator to evaluator.py. - HealthCheck creators default to returning an empty list. - Rename HealthConfig.mid_training_checks to inflight_checks. - Remove Diagnose.target_ranks and target_nodes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
| inflight_checks: Checks that run during training. Their probes must be | ||
| wrapped in ``PeriodicProbe``. | ||
| preflight_checks: Checks that run once on each node before training | ||
| starts. Their probes must be wrapped in ``OnDemandProbe``. |
There was a problem hiding this comment.
There is a code smell here if these constraints are defined in the requirements and not the interface itself.
Could we simplify it by removing these interfaces and moving it to the HealthCheck instead? I'm curious if poll_interval_s needs to be an attribute of the actual Probe itself or the HealthCheck.
class HealthCheck:
probe_creator: Callable[[], List[Probe]]
evaluator_creator: Callable[[], List[Evaluator]]
class PeriodicHealthCheck(HealthCheck):
poll_interval_s: float
class HealthConfig:
inflight_checks: List[PeriodicHealthCheck]
preflight_checks: List[HealthCheck]
class Diagnose(HealthDecision):
checks: List[HealthCheck]There was a problem hiding this comment.
done. l am good first keep it in HealthCheck, if later we found the need that each probe needs its own frequency we can then added there.
Remove PeriodicProbe and OnDemandProbe. A PeriodicHealthCheck polls its probes every poll_interval_s, and HealthConfig.inflight_checks takes PeriodicHealthChecks, so the constraint lives in the types. probe_creator returns plain probes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
## Description Second PR of the [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack, on top of #66536. Adds a third probe kind, `ControllerProbe`, named for where it runs: in the Ray Train controller process. Some sources already aggregate across the cluster, so one query answers for the whole run. NCCL RAS is the case study: one `ncclras` query reports every communicator. A `ControllerProbe` polls such a source once and returns one result per key it chooses (here, per communicator). - `probe.py`: `ControllerProbe.poll() -> {key: ProbeResult}`. One instance is used for the whole run, so it can keep state between polls (for example the previous snapshot, to compute a delta). `poll()` takes no arguments for now; a context, such as the run's worker-to-node map, can be added by the first probe that needs it. - `state.py`: `HealthState.probe_results` also holds `ControllerProbe` readings, keyed by the probe's own keys. Nothing polls it yet; that comes with the controller integration. ### Difference compared with the REP The REP has no controller-side probe. ## Test - `pytest python/ray/train/v2/tests/test_health_contracts.py`: 14 passed. - `pre-commit run` on the changed files: all passed. - `ci/ray_ci/doc/cmd_check_api_param_coverage.py .`: no newly-undocumented public-API parameters. ## Duplicate check and AI assistance Part of the stack started in #66536; no other open PR adds a Ray Train health module. Written with AI assistance (Claude Code); I reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
## Description 1st PR of a new [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack for Worker level integration with Ray Train V2. Adds `WorkerProbe` support to the Ray Train `WorkerGroup`, mirroring what `NodeMonitorGroup` does for `NodeProbe`s. Each train worker samples its `WorkerProbe`s in their own daemon threads every `poll_interval_s`, and keeps the latest samples on its `TrainContext`. - The probes come in through a `WorkerGroupCallback`'s `before_init_train_context`, as `worker_probes`. - `poll_status()` returns the latest samples as `WorkerStatus.probe_results`, so they ride the poll the controller already makes. `WorkerGroup`: - `poll_probes_async(probes, timeout_s, ranks=None)` polls probes once on some or all workers. Each worker runs them in a `ThreadRunner` started through `execute_async`, so `poll_status()` keeps answering meanwhile. - `poll_probe_results()` returns `{probe name: {world rank: ProbeResult}}` once every worker answered or the timeout passed, and `None` until then, like `NodeMonitorGroup.poll_probe_results()`. A worker that did not answer, or whose actor failed, carries the error in its results. Wiring these results into the `HealthManager` comes in a later PR. Illustration of how periodic and on-demand probes flow through the WorkerGroup periodic: <img width="793" height="452" alt="image" src="https://github.com/user-attachments/assets/3217844a-3ba2-421f-bc47-2acfdc22c87a" /> on demand: <img width="579" height="441" alt="image" src="https://github.com/user-attachments/assets/810829cd-272e-41e7-a404-9170b79653aa" /> ## Related: 1. REP: https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics 2. #66536 ## Test unit tests Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…67671) ## Description 5th PR of the [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack, after #66536, #66648, #66650 and #66649. `ControllerProbe` (2/n) had nowhere to run. This PR runs it on a `NodeMonitor` on the controller's node, next to the `NodeMonitor`s on the worker nodes, so a slow or hanging probe never blocks the controller. ### How it works - **`NodeMonitor`** samples and polls on demand any probe the same way. A `NodeProbe` gives a `ProbeResult`, and a `ControllerProbe` gives `{key: ProbeResult}`. A poll that raises gives a `ProbeResult` with the `error`. - **`NodeMonitorGroup`** runs a monitor of the `NodeProbe`s on each worker node, with `start_worker_node_monitors(node_ids)` / `shutdown_worker_node_monitors()`, and a monitor of the `ControllerProbe`s on the controller's node, with `start_controller_node_monitor(node_id)`. It polls both kinds in one issue-and-collect loop, as `WorkerGroup` polls its workers. `poll_status()` (in-flight) and `poll_probe_results()` (on-demand) both return a `NodeMonitorGroupPollStatus`, where a monitor that died or did not answer in time has its `monitor_error`. - **`HealthManager.reset()`** starts both. The controller node's monitor always starts, so on-demand `ControllerProbe`s work without an in-flight one; without `ControllerProbe`s it has no sampling threads. One function builds the `HealthState` of both in-flight and on-demand checks, and a failed monitor gives each of its probes its error. As in 4/n, a worker node's failed monitor stops, with its results, until the next `reset()`. While the controller node's monitor fails, each `ControllerProbe` has its error. - **`HealthState`** has two new fields for the `ControllerProbe`s: `controller_probe_results`, `{probe name: {key: ProbeResult}}`, and `controller_probe_errors`, `{probe name: exception}` for each whose latest poll failed. `probe_results` now holds only `WorkerProbe` and `NodeProbe` results. Nothing calls the `HealthManager` yet; the controller integration comes later in the stack. ### In-flight checks <img width="686" height="955" alt="image" src="https://github.com/user-attachments/assets/23b502d2-417d-4008-bc22-dd5bfe2807bb" /> ### On-demand checks <img width="1024" height="895" alt="image" src="https://github.com/user-attachments/assets/e1f4eb22-376d-4f21-bb7d-59a6b0683b60" /> ## Test unit tests --------- Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
) ## Description 6th PR of the [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack, on top of #67671. The `HealthManager` decides on `Reattempt`, `Evict` or `Diagnose`, but nothing acted on its decisions yet. This PR runs its in-flight checks in the Ray Train controller and acts on what they decide. ### How it works - **`RunConfig.health_config`** (Alpha) takes a `HealthConfig`. The controller makes a `HealthManager` of its `inflight_checks`. `preflight_checks` only logs a warning for now. - **`HealthCallback`**, a `WorkerGroupCallback`, calls `HealthManager.reset()` with the worker group's nodes after each attempt starts, and `shutdown()` before the worker group shuts down or aborts. - **The `RUNNING` step** calls `evaluate_inflight_checks()` after it acts on worker errors. Each decision other than a `Noop` first goes to the new `after_health_decision` hook of `ControllerCallback` and `UserCallback`, then: - `Reattempt` restarts the worker group through the failure policy with a `HealthCheckError`, like a worker error, so it counts against `max_failures`. - `Evict` restarts the worker group without going through the failure policy. Every later attempt adds `ray.io/node-id: !in(<evicted nodes>)` to each worker's label selector, so no worker lands on an evicted node. A node is evicted once, so evictions are bounded by the number of nodes. - `Diagnose` is not acted on yet. - **`HealthCheckError`** (DeveloperAPI) is a `WorkerGroupError` that keeps the `decision` behind the restart. WorkerProbes in the controller's `HealthState`, pre-flight checks and `Diagnose` come later in the stack. ### Controller flow ## Related 1. REP: https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics 2. #66536, #66648, #66650, #66649, #67671 ## Test `test_health_e2e` trains on a cluster of two 1-CPU nodes with `max_failures=0` and an evaluator that evicts every node: the second attempt runs on the other node, and the run fails once no node is left to start on. --------- Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Description
First PR of a stack implementing the Ray Train Monitoring and Diagnostics REP. This one adds only the data contracts in a new
ray.train.healthmodule; nothing is wired into the controller yet.probe.py:ProbeResult(named numeric readings, plus when they were taken),Probe, and the two probe kinds, named for where they run:WorkerProbe(inside each training worker) andNodeProbe(on each node, outside the workers).state.py:HealthState, what evaluators read:probe_results, the latestProbeResultof each probe, keyed by probe name and then world rank or node ID.decision.py: the decisionsNoop,Reattempt,EvictandDiagnose.Diagnose.checksnames the health checks to run once.evaluator.py:Evaluator(returns oneHealthDecision, with an optionalon_worker_group_start()hook).check.py:HealthCheck(probes plus the evaluators that decide on their readings; both creators default to none),PeriodicHealthCheck(aHealthCheckwhose probes are polled everypoll_interval_s), andHealthConfig(inflight_checks, which arePeriodicHealthChecks that run during training, andpreflight_checks, which run once before training).Next in the stack:
ControllerProbe(#66648),NodeMonitor(#66650),HealthManager(#66649), thenray.train.health.report(), the controller integration, and running checks once (diagnostics and pre-flight).See a draft for the REP in: #66247
classDiagram direction LR class HealthConfig { inflight_checks: List~PeriodicHealthCheck~ preflight_checks: List~HealthCheck~ } class HealthCheck { probe_creator() List~Probe~ evaluator_creator() List~Evaluator~ } class PeriodicHealthCheck { poll_interval_s: float } class Probe { <<abstract>> name: str } class WorkerProbe { <<abstract>> poll() ProbeResult } class NodeProbe { <<abstract>> poll() ProbeResult } class ProbeResult { metrics: Dict~str,float~ timestamp_s: float } class HealthState { probe_results: Dict } class Evaluator { <<abstract>> evaluate(state) HealthDecision on_worker_group_start() } class HealthDecision { <<abstract>> reason: str } class Evict { target_nodes: List~str~ } class Diagnose { checks: List~HealthCheck~ } HealthConfig o-- PeriodicHealthCheck : inflight HealthConfig o-- HealthCheck : preflight HealthCheck <|-- PeriodicHealthCheck HealthCheck ..> Probe : creates HealthCheck ..> Evaluator : creates Probe <|-- WorkerProbe Probe <|-- NodeProbe WorkerProbe ..> ProbeResult : returns NodeProbe ..> ProbeResult : returns HealthState o-- ProbeResult : latest per probe, per rank or node Evaluator ..> HealthState : reads Evaluator ..> HealthDecision : returns HealthDecision <|-- Noop HealthDecision <|-- Reattempt HealthDecision <|-- Evict HealthDecision <|-- Diagnose Diagnose o-- HealthCheck : runs onceTest
pytest python/ray/train/v2/tests/test_health_contracts.py: 12 passed.pre-commit runon the changed files: all passed.ci/ray_ci/doc/cmd_check_api_param_coverage.py .: no newly-undocumented public-API parameters.The run in (1) and (2) used the earlier prototype; the release scripts move onto these contracts later in the stack.
Duplicate check and AI assistance
No other open PR adds a Ray Train health module; searching open PRs for "train health probe", "ray.train.health" and "health monitoring train" returns only this stack and the draft #66247. Written with AI assistance (Claude Code); I reviewed every changed line.