Repository navigation
Conversation
93b576f to
b6cac26
Compare
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
b6cac26 to
8c58156
Compare
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive health monitoring and diagnostics framework for Ray Train v2, adding the ray.train.health module, a HealthManager to aggregate signals, and integrating them into the controller loop via HealthCallback. The feedback highlights several critical improvements: resolving a potential crash during diagnostic uploads when storage is disabled, using Evaluator instances directly in sets instead of their integer IDs for better type safety, adding a fallback to next() in merge_decisions to prevent StopIteration errors, and consistently using time.monotonic() instead of time.time() to avoid clock-drift issues.
| storage = worker_group._storage_context | ||
| self._runner = OnDemandRunner( | ||
| run_on_node=_run_on_nodes, | ||
| run_on_worker=run_on_workers, | ||
| upload=functools.partial( | ||
| _upload_files, storage.storage_filesystem, storage.experiment_fs_path | ||
| ), | ||
| ) |
There was a problem hiding this comment.
If storage.storage_filesystem is None (e.g., when storage is disabled in local or testing environments), functools.partial will still bind None and create a callable upload function. When a diagnostic probe attempts to call ctx.upload, it will invoke _upload_files with storage_filesystem=None, which will fail inside _upload_to_fs_path. Setting upload to None if storage.storage_filesystem is None allows probes to gracefully skip uploading.
storage = worker_group._storage_context
upload_fn = (
functools.partial(
_upload_files, storage.storage_filesystem, storage.experiment_fs_path
)
if storage.storage_filesystem is not None
else None
)
self._runner = OnDemandRunner(
run_on_node=_run_on_nodes,
run_on_worker=run_on_workers,
upload=upload_fn,
)|
|
||
| # Kept across restarts: an evicted node stays out for the whole run. | ||
| self._evicted: Set[str] = set() | ||
| self._disabled: Set[int] = set() |
There was a problem hiding this comment.
Instead of storing id(evaluator) in a Set[int], you can store the Evaluator instances directly in a Set[Evaluator]. Standard Python objects are hashable by identity, making this approach cleaner and more type-safe.
| self._disabled: Set[int] = set() | |
| self._disabled: Set[Evaluator] = set() |
| ) -> List[HealthDecision]: | ||
| decisions: List[HealthDecision] = [] | ||
| for evaluator in evaluators: | ||
| if id(evaluator) in self._disabled: |
| "Evaluator %s raised; disabling it for this run.", | ||
| type(evaluator).__name__, | ||
| ) | ||
| self._disabled.add(id(evaluator)) |
| top = max(SEVERITY[d.action] for d in live) | ||
| winners = [d for d in live if SEVERITY[d.action] == top] | ||
| present = {d.cause for d in winners} | ||
| cause = next(c for c in _CAUSE_PRIORITY if c in present) |
There was a problem hiding this comment.
Providing a default fallback to next() prevents a potential StopIteration exception if a new Cause is added in the future but not updated in _CAUSE_PRIORITY.
| cause = next(c for c in _CAUSE_PRIORITY if c in present) | |
| cause = next((c for c in _CAUSE_PRIORITY if c in present), Cause.UNKNOWN) |
| self.health_metrics.update(metrics) | ||
| if step is not None: | ||
| self.health_step = step | ||
| self.health_reported_at = time.time() |
There was a problem hiding this comment.
Using time.time() (wall-clock time) for health_reported_at can cause issues if compared with time.monotonic() (which is used in other parts of the health framework like _ClusterProbeThread and NcclHangEvaluator). It is highly recommended to use time.monotonic() consistently for all elapsed time and interval measurements to prevent bugs due to system clock adjustments.
| self.health_reported_at = time.time() | |
| self.health_reported_at = time.monotonic() |
…cisions, policies (#66536) ## Description First PR of a stack implementing the [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics). This one adds only the data contracts in a new `ray.train.health` module; 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) and `NodeProbe` (on each node, outside the workers). - `state.py`: `HealthState`, what evaluators read: `probe_results`, the latest `ProbeResult` of each probe, keyed by probe name and then world rank or node ID. - `decision.py`: the decisions `Noop`, `Reattempt`, `Evict` and `Diagnose`. `Diagnose.checks` names the health checks to run once. - `evaluator.py`: `Evaluator` (returns one `HealthDecision`, with an optional `on_worker_group_start()` hook). - `check.py`: `HealthCheck` (probes plus the evaluators that decide on their readings; both creators default to none), `PeriodicHealthCheck` (a `HealthCheck` whose probes are polled every `poll_interval_s`), and `HealthConfig` (`inflight_checks`, which are `PeriodicHealthCheck`s that run during training, and `preflight_checks`, which run once before training). Next in the stack: `ControllerProbe` (#66648), `NodeMonitor` (#66650), `HealthManager` (#66649), then `ray.train.health.report()`, the controller integration, and running checks once (diagnostics and pre-flight). See a draft for the REP in: #66247 ```mermaid 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 once ``` ## Test 1. test with draft PR #66247 with script: https://gist.github.com/liulehui/5d65f0fc9c27298872ec49e454d65ad7 2. example logs: ``` ============================================================================== health: ray.train.health ============================================================================== injected: rank 1 stops calling the collective at step 100 and sleeps (a silent hang) (TrainController pid=25958) [State Transition] SHUTTING_DOWN -> ERRORED. (TrainController pid=26887) Requesting resources: {'GPU': 1} * 4 (TrainController pid=26887) /home/ray/anaconda3/lib/python3.12/site-packages/ray/data/_internal/execution/interfaces/execution_options.py:436: RayDeprecationWarning: `ExecutionOptions.exclude_resources` is deprecated and will be removed after January 2027. Use `ExecutionOptions.label_selector` to constrain Ray Data work to labeled nodes. (TrainController pid=26887) self.exclude_resources = exclude_resources (TrainController pid=26887) [State Transition] INITIALIZING -> SCHEDULING. (TrainController pid=26887) [Health] pre-flight passed on 4 node(s). (TrainController pid=26887) Attempting to start training worker group of size 4 with the following resources: [{'GPU': 1}] * 4 (RayTrainWorker pid=8859, ip=10.0.154.65) Setting up process group for: env:// [rank=0, world_size=4] (TrainController pid=26887) {"asctime":"2026-09-28 10:59:04,061","levelname":"E","message":"Actor with class name: 'PreemptionWatcher' and ID: '527407ea2951e6244aed01d302000000' has constructor arguments in the object store and max_restarts > 0. If the arguments in the object store go out of scope or are lost, the actor restart will fail. See #53727 for more details.","filename":"core_worker.cc","lineno":2465} (TrainController pid=26887) Started training worker group of size 4: (TrainController pid=26887) - (ip=10.0.154.65, pid=8859) world_rank=0, local_rank=0, node_rank=0 (TrainController pid=26887) - (ip=10.0.149.4, pid=8860) world_rank=1, local_rank=0, node_rank=1 (TrainController pid=26887) - (ip=10.0.138.97, pid=8935) world_rank=2, local_rank=0, node_rank=2 (TrainController pid=26887) - (ip=10.0.132.60, pid=8993) world_rank=3, local_rank=0, node_rank=3 (TrainController pid=26887) [State Transition] SCHEDULING -> RUNNING. (TrainController pid=26887) [Health] DIAGNOSE (NO_PROGRESS): 1 of 1 NCCL communicators (0x6b6b31bd2e55f51) made no progress for 20s; running diagnostics before attributing it (TrainController pid=26887) [Health] diagnostic output: /mnt/cluster_storage/nccl_hang_health_1790618333/health_diagnostics/nccl_ras (TrainController pid=26887) [Health] diagnostic output: /mnt/cluster_storage/nccl_hang_health_1790618333/health_diagnostics/nvidia_smi (TrainController pid=26887) [Health] diagnostic output: /mnt/cluster_storage/nccl_hang_health_1790618333/health_diagnostics/stack_traces (TrainController pid=26887) [Health] REATTEMPT (NO_PROGRESS): 1 of 1 NCCL communicators (0x6b6b31bd2e55f51) made no progress for 20s; diagnostics found no hardware fault, so this is software or data (TrainController pid=26887) [FailurePolicy] RAISE (TrainController pid=26887) Source: worker group (TrainController pid=26887) Error count: 1 (max allowed: 0) (TrainController pid=26887) Error: Training failed due to worker errors: (TrainController pid=26887) 1 of 1 NCCL communicators (0x6b6b31bd2e55f51) made no progress for 20s; diagnostics found no hardware fault, so this is software or data (TrainController pid=26887) ray.train.v2.api.exceptions.HealthDecisionError: Training failed due to worker errors: (TrainController pid=26887) 1 of 1 NCCL communicators (0x6b6b31bd2e55f51) made no progress for 20s; diagnostics found no hardware fault, so this is software or data (TrainController pid=26887) [State Transition] RUNNING -> SHUTTING_DOWN. (TrainController pid=26887) Torch process group shutdown timed out after 30 seconds (TrainController pid=26887) [State Transition] SHUTTING_DOWN -> ERRORED. ``` 3. Unit tests and checks on this PR: - `pytest python/ray/train/v2/tests/test_health_contracts.py`: 12 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. 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. --------- Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
prototype for Ray Train health / monitoring / diagnostics