Skip to content

[DRAFT] add Ray Train health / monitoring / diagnostics - #66247

Open
liulehui wants to merge 9 commits into
ray-project:masterfrom
liulehui:train-health-nvsentinel
Open

liulehui wants to merge 9 commits into
ray-project:masterfrom
liulehui:train-health-nvsentinel

Conversation

@liulehui

Copy link
Copy Markdown
Contributor

prototype for Ray Train health / monitoring / diagnostics

@liulehui liulehui changed the title [DRAFT] [DRAFT] add Ray Train health / monitoring / diagnostics Sep 17, 2026
@liulehui liulehui added the go add ONLY when ready to merge, run all tests label Sep 17, 2026
@liulehui
liulehui force-pushed the train-health-nvsentinel branch from 93b576f to b6cac26 Compare September 24, 2026 19:03
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]>
@liulehui
liulehui force-pushed the train-health-nvsentinel branch from b6cac26 to 8c58156 Compare September 28, 2026 05:17
Signed-off-by: Lehui Liu <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Oct 13, 2026
@liulehui
liulehui marked this pull request as ready for review October 13, 2026 02:21
@liulehui
liulehui requested a review from a team as a code owner October 13, 2026 02:21

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

Comment on lines +254 to +261
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
),
)

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.

high

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()

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.

medium

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.

Suggested change
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:

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.

medium

Use the evaluator instance directly instead of its id().

Suggested change
if id(evaluator) in self._disabled:
if evaluator in self._disabled:

"Evaluator %s raised; disabling it for this run.",
type(evaluator).__name__,
)
self._disabled.add(id(evaluator))

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.

medium

Add the evaluator instance directly instead of its id().

Suggested change
self._disabled.add(id(evaluator))
self._disabled.add(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)

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.

medium

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.

Suggested change
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()

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.

medium

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.

Suggested change
self.health_reported_at = time.time()
self.health_reported_at = time.monotonic()

@ray-gardener ray-gardener Bot added the train Ray Train Related Issue label Oct 13, 2026
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Oct 13, 2026
matthewdeng pushed a commit that referenced this pull request Oct 13, 2026
…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]>

This branch has not been deployed

No deployments
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 unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant