Repository navigation
[train][2/n] Move the NCCL hang detector onto ray.train.health - #67916
Conversation
d3dff7c to
203cdbe
Compare
203cdbe to
14e47b1
Compare
14e47b1 to
189873e
Compare
189873e to
bb7186c
Compare
bb7186c to
2655c1b
Compare
2655c1b to
5f1b44f
Compare
5f1b44f to
13338f8
Compare
13338f8 to
4671b59
Compare
4671b59 to
01bc1cc
Compare
9fd6ff8 to
ee450a3
Compare
fc894d5 to
b0fe250
Compare
b0fe250 to
de39d17
Compare
There was a problem hiding this comment.
Code Review
This pull request migrates the NCCL hang detector from a callback-based implementation to a built-in in-flight health check within the ray.train.health framework. It introduces the periodic health check configuration, evaluators for suspected and confirmed hangs, diagnostic probes (for PyTorch Flight Recorder, nvidia-smi, ncclras, and stack traces), and comprehensive tests. Feedback focuses on enhancing runtime robustness, including eager validation of the NCCL_RAS_ADDR environment variable, defensive parsing of the RAS report timestamp, adding safety guards for worker metadata, and guarding against None values for user-configured health checks in the controller.
de39d17 to
29db681
Compare
29db681 to
3749b35
Compare
## Description 1st of 2 PRs that move the NCCL hang detector onto `ray.train.health`, following 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 #67671 → #67856 → #67879 → #67915. On-demand checks, the pre-flight checks and the checks of a `Diagnose`, shared one fixed 60s timeout. A node or worker also polled its on-demand probes one after another, so one hung probe held up the others and, on a node, every later on-demand check. This PR gives each probe its own timeout: - **`Probe.timeout_s`**, 60s by default, is how long one poll may take. A probe that runs a command passes it to the command, since Ray Train can't stop a poll. - **On-demand probes run in parallel.** A `NodeMonitor` or worker polls each one in its own thread (`OnDemandPolls`). - **One time limit per group.** The probes on the nodes, and those on the workers, get their longest `timeout_s` plus `ON_DEMAND_PROBE_GRACE_S` (5s). The grace lets a probe whose command timed out return why. A probe still running then gets a `TimeoutError`, and the other results still come back. This replaces `DEFAULT_ON_DEMAND_PROBE_TIMEOUT_S`. - **Periodic probes** are polled every `poll_interval_s`, from the start of one poll to the start of the next, instead of `poll_interval_s` after each poll. It also adds two hooks that the NCCL hang detector (2/n, #67916) uses: - **`Evaluator.on_shutdown()`**, called at the end of each attempt, to clear what an evaluator reports outside the run, such as metrics. - **`ProbeResult.detail`**, for a reading's output that isn't a number, such as a report or a stack trace. ### How the timeouts work **Periodic probes, on a `NodeMonitor`** <img width="1857" height="938" alt="image" src="https://github.com/user-attachments/assets/591cd993-6d98-4191-96fc-b532cf514ad1" /> **Periodic probes, on a worker** <img width="1828" height="927" alt="image" src="https://github.com/user-attachments/assets/30d6224f-2f69-45f5-a7da-e9fecdb56e27" /> **On-demand probes, on a `NodeMonitor`** <img width="1874" height="924" alt="image" src="https://github.com/user-attachments/assets/384f7d13-8d61-4ca2-83fd-5b3df7ddb2d2" /> **On-demand probes, on a worker** <img width="1874" height="917" alt="image" src="https://github.com/user-attachments/assets/0e44d680-0194-424c-89c4-24bd4b759584" /> ## Related 1. REP: https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics 2. #67671, #67856, #67879, #67915 3. #67916 (2/n), the first user of these Not a duplicate: no open PR adds per-probe timeouts to `ray.train.health`. ## Test unit tests Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
3749b35 to
a34946b
Compare
pseudo-rnd-thoughts
left a comment
There was a problem hiding this comment.
I haven't read the code, more looked at the structure because I think most of it is just copy and pastes from my ncclras version.
Could you add some of the e2e tests from test_nccl_ras_hang_detection.py? Have you tested this works in a workspace for actually nccl hangs?
| return None, error | ||
|
|
||
|
|
||
| class SuspectedHangEvaluator(Evaluator): |
There was a problem hiding this comment.
Why are two Evaluators necessary? One for the Suspected and Confirmed?
There was a problem hiding this comment.
There are actually three, each doing one thing:
NCCLHangEvaluator, the in-flight one, readsNCCLRASProbe's JSON and decides whether a communicator is fine, suspected or confirmed hung.SuspectedHangEvaluatorlogs NCCL's text report, from the suspected hang'sDiagnose.ConfirmedHangEvaluatoruploads the confirmed hang's diagnostics, then reattempts (fail) or only logs (observe).
A Diagnose runs its checks' probes on demand, and only the evaluators in those checks see the results. So each Diagnose names the evaluator that acts on what it collects.
This is to decouple the decision logic for each probe for flexibility.
RAY_TRAIN_ENABLE_NCCL_HANG_DETECTOR=1 now runs the NCCL hang detector as
a ray.train.health check that the controller adds to the run, instead of
NCCLRASCallback, which stays, unregistered, until a later PR deletes it.
It behaves like the callback: the same env vars, detection, warnings,
diagnostics and uploads, and Grafana gauges.
- ray.train.health.nccl_ras:
- utils: the callback's helpers, copied in its order. Only
run_ncclras, run_nvidia_smi and dump_flight_recorder differ.
- probes: NCCLRASProbe, NCCLRASTextProbe and NvidiaSmiProbe on each
node, FlightRecorderProbe and StackTraceProbe on each worker.
- evaluators: NCCLHangEvaluator, which diagnoses a suspected hang with
NCCL's text report (SuspectedHangEvaluator), and a confirmed one with
the four diagnostics (ConfirmedHangEvaluator, which uploads them,
then reattempts or only logs).
- check: nccl_hang_check(), which reads the env vars.
- The controller adds nccl_hang_check() to the run's in-flight checks,
and the detector's env vars are propagated to it.
- With RAY_TRAIN_NCCL_RAS_ACTION=fail, a confirmed hang is a Reattempt,
which fails the attempt with a HealthCheckError instead of
NCCLHangError.
- The Flight Recorder dump reads ProcessGroupNCCL's buffer, falling back
to the generic one.
The detector's tests, in python/ray/train/health/tests, are copies of
test_nccl_ras_callback.py's. A CPU end-to-end test drives it with a fake
ncclras.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
… two GPU tests to CPU - probe_utils.py holds what the probes run: ncclras, nvidia-smi, py-spy and the Flight Recorder dump. utils.py keeps what the evaluators share: the parsed ncclras report and the rank translation. Both are copied unchanged from the callback's module, in its order. - test_health_e2e.py ports test_nccl_ras_hang_detection.py's healthy run (nothing fires or is uploaded) and its two communicators of which one hangs (only that one is named), with a fake ncclras. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
a34946b to
a242c48
Compare
And yes, I tested it in a workspace, on 4 × A10G with NCCL 2.28.9, with see this gist for all the logs: https://gist.github.com/liulehui/92f3c67921e0eca7b6fed36c3ef33bdd |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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 f14d808. Configure here.
- A confirmed hang whose communicators resumed while its diagnostics were captured no longer reattempts the run, and can be confirmed again. - A confirmed hang's Diagnose is returned on every evaluation until it runs, as the HealthManager drops one while other on-demand checks run. - Warn once when ncclras fails fatally on every node that answered, as a node whose NodeMonitor failed never reports. - Skip a report that doesn't parse and try the next node, as the callback did. - Validate the detector's env vars in fit() on the driver, so an invalid one raises a ValueError again. - Docs: the ncclras report is logged once at suspicion, and only captured at confirmation. - Add TODOs to query one node per poll, to carry only the checks that need idle workers to the next attempt, and to let users add the detector through RunConfig(health_config=...). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
f14d808 to
958982b
Compare

Description
2nd of 2 PRs that move the NCCL hang detector onto
ray.train.health, following the Ray Train Monitoring and Diagnostics REP stack, after the per-probe timeouts in 1/n #68191.RAY_TRAIN_ENABLE_NCCL_HANG_DETECTOR=1now runs the NCCL RAS hang detector as aray.train.healthcheck, instead ofNCCLRASCallback. The controller adds the check to the run, and it runs through theHealthManagerlike any other check. The callback's code stays, unregistered, until a follow-up PR deletes it.NCCLRASProbepollsncclras -f jsonevery 15s, as a periodicNodeProbeon each node.NCCLHangEvaluatortracks each communicator's frozen streak, from one node's newest report.DiagnosewithNCCLRASTextProbe.SuspectedHangEvaluatorlogs NCCL's text report, and training continues.Diagnosewith four probes:nvidia-smiandncclras -f texton each node, and the Flight Recorder dump and stack traces on each worker.ConfirmedHangEvaluatoruploads them tohang_detector/as today, then returnsReattemptforRAY_TRAIN_NCCL_RAS_ACTION=fail, orNoopforobserve.Unchanged: the environment variables and their defaults, the 60s, 120s and 10-minute thresholds, the log messages, the uploaded files, the Grafana gauges, the
max_failuresbudget, andobserveas the default.Changed:
fail. A confirmed hang fails the attempt with aHealthCheckError, aWorkerGroupErrorwhose message includes the hang report, instead ofNCCLHangError. Code that catchesray.train.NCCLHangErrorneeds to catchWorkerGroupErrorinstead.ncclrasruns. On each node, instead of on the first worker that answers.trainer.fit()before training starts, instead of when the trainer is constructed._dump_nccl_trace_json). The callback's generic dump holds no NCCL collectives.Most of the code is the callback's, copied:
nccl_ras/utils.pyholds the callback's helpers in the callback's order. All butrun_ncclras,run_nvidia_smianddump_flight_recorderare identical.nccl_ras/evaluators.py, the detection methods keep the callback's code, except where a health decision replaces a side effect, such as returning aDiagnoseinstead of capturing the diagnostics on the controller thread.RASPoller,fan_out_to_workers,DiagnosticResult, and the callback's controller and worker group hooks.Related
Test
unit tests
test_health_e2e.pydrives the detector end to end on CPU, with a fakencclras.