Skip to content

[train][2/n] Move the NCCL hang detector onto ray.train.health - #67916

Merged
pseudo-rnd-thoughts merged 3 commits into
masterfrom
ray-train-health/nccl-ras-health
Nov 20, 2026
Merged

pseudo-rnd-thoughts merged 3 commits into
masterfrom
ray-train-health/nccl-ras-health

Conversation

@liulehui

@liulehui liulehui commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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=1 now runs the NCCL RAS hang detector as a ray.train.health check, instead of NCCLRASCallback. The controller adds the check to the run, and it runs through the HealthManager like any other check. The callback's code stays, unregistered, until a follow-up PR deletes it.

image
  • NCCLRASProbe polls ncclras -f json every 15s, as a periodic NodeProbe on each node. NCCLHangEvaluator tracks each communicator's frozen streak, from one node's newest report.
  • A suspected hang returns a Diagnose with NCCLRASTextProbe. SuspectedHangEvaluator logs NCCL's text report, and training continues.
  • A confirmed hang returns a Diagnose with four probes: nvidia-smi and ncclras -f text on each node, and the Flight Recorder dump and stack traces on each worker. ConfirmedHangEvaluator uploads them to hang_detector/ as today, then returns Reattempt for RAY_TRAIN_NCCL_RAS_ACTION=fail, or Noop for observe.

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_failures budget, and observe as the default.

Changed:

  • The error on fail. A confirmed hang fails the attempt with a HealthCheckError, a WorkerGroupError whose message includes the hang report, instead of NCCLHangError. Code that catches ray.train.NCCLHangError needs to catch WorkerGroupError instead.
  • Where ncclras runs. On each node, instead of on the first worker that answers.
  • How the diagnostics run. All at once, within 35s, instead of one after another on the controller thread.
  • Where the env vars are read. The controller reads them, and Ray Train propagates them from the driver. An invalid value fails trainer.fit() before training starts, instead of when the trainer is constructed.
  • The Flight Recorder dump reads ProcessGroupNCCL's buffer (_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.py holds the callback's helpers in the callback's order. All but run_ncclras, run_nvidia_smi and dump_flight_recorder are identical.
  • In nccl_ras/evaluators.py, the detection methods keep the callback's code, except where a health decision replaces a side effect, such as returning a Diagnose instead of capturing the diagnostics on the controller thread.
  • Not ported, because the health framework replaces it: RASPoller, fan_out_to_workers, DiagnosticResult, and the callback's controller and worker group hooks.

Related

  1. REP: https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics
  2. [train][5/n] Run ControllerProbes on the controller's node monitor #67671, [train][6/n] Act on health decisions in the Ray Train controller #67856, [train][3/n] Add WorkerProbe results and health reports to the HealthState #67879, [train][4/n] Wire WorkerProbes through the HealthManager #67915, [train][1/n] Give each health probe its own timeout #68191

Test

unit tests
test_health_e2e.py drives the detector end to end on CPU, with a fake ncclras.

@liulehui
liulehui added this pull request to stack #67857 November 6, 2026 18:10
@pseudo-rnd-thoughts
pseudo-rnd-thoughts force-pushed the ray-train-health/nccl-ras-health branch from d3dff7c to 203cdbe Compare November 9, 2026 10:17
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from 203cdbe to 14e47b1 Compare November 9, 2026 22:59
@liulehui liulehui added the go add ONLY when ready to merge, run all tests label Nov 9, 2026
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from 14e47b1 to 189873e Compare November 10, 2026 17:34
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from 189873e to bb7186c Compare November 10, 2026 18:41
@pseudo-rnd-thoughts
pseudo-rnd-thoughts force-pushed the ray-train-health/nccl-ras-health branch from bb7186c to 2655c1b Compare November 10, 2026 20:51
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from 2655c1b to 5f1b44f Compare November 12, 2026 06:38
@pseudo-rnd-thoughts
pseudo-rnd-thoughts force-pushed the ray-train-health/nccl-ras-health branch from 5f1b44f to 13338f8 Compare November 12, 2026 17:25
Base automatically changed from ray-train-health/worker-probe-wiring to master November 12, 2026 18:39
@pseudo-rnd-thoughts
pseudo-rnd-thoughts force-pushed the ray-train-health/nccl-ras-health branch from 13338f8 to 4671b59 Compare November 12, 2026 18:39
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from 4671b59 to 01bc1cc Compare November 12, 2026 19:06
@liulehui liulehui changed the title [train][7/n] Move the NCCL RAS hang detector onto ray.train.health [train][7/n] Add the NCCL hang detector's probes to ray.train.health Nov 12, 2026
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch 2 times, most recently from 9fd6ff8 to ee450a3 Compare November 14, 2026 23:04
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from fc894d5 to b0fe250 Compare November 15, 2026 22:37
@liulehui
liulehui removed this pull request from stack #67857 November 15, 2026 23:00
@liulehui
liulehui changed the base branch from master to ray-train-health/probe-timeout November 15, 2026 23:00
@liulehui
liulehui added this pull request to stack #68192 November 15, 2026 23:00
@liulehui liulehui changed the title [train][7/n] Add the NCCL hang detector's probes to ray.train.health [train][2/n] Move the NCCL hang detector onto ray.train.health Nov 15, 2026
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from b0fe250 to de39d17 Compare November 15, 2026 23:15
@liulehui
liulehui marked this pull request as ready for review November 15, 2026 23:19
@liulehui
liulehui requested review from a team as code owners November 15, 2026 23:19

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

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added the train Ray Train Related Issue label Nov 16, 2026
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from de39d17 to 29db681 Compare November 17, 2026 18:25

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from 29db681 to 3749b35 Compare November 18, 2026 17:25
Base automatically changed from ray-train-health/probe-timeout to master November 18, 2026 19:44
pseudo-rnd-thoughts pushed a commit that referenced this pull request Nov 18, 2026
## 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]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts force-pushed the ray-train-health/nccl-ras-health branch from 3749b35 to a34946b Compare November 18, 2026 19:44

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are two Evaluators necessary? One for the Suspected and Confirmed?

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.

There are actually three, each doing one thing:

  • NCCLHangEvaluator, the in-flight one, reads NCCLRASProbe's JSON and decides whether a communicator is fine, suspected or confirmed hung.
  • SuspectedHangEvaluator logs NCCL's text report, from the suspected hang's Diagnose.
  • ConfirmedHangEvaluator uploads 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.

liulehui and others added 2 commits November 18, 2026 14:51
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]>
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from a34946b to a242c48 Compare November 18, 2026 22:52
@liulehui

Copy link
Copy Markdown
Contributor Author

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?

test_nccl_ras_hang_detection.py is migrated in this PR: its GPU scenarios run this detector and expect a HealthCheckError. On CPU, test_health_e2e.py covered only the hang, so a242c48 ports two more of the GPU file's cases with a fake ncclras:

  • test_the_nccl_hang_detector_lets_a_healthy_run_finish: the ranks agree, so nothing is suspected and nothing is uploaded.
  • test_the_nccl_hang_detector_names_only_the_hung_communicator: of two communicators, only the hung one is named.

And yes, I tested it in a workspace, on 4 × A10G with NCCL 2.28.9, with release/train_tests/health/nccl_hang.py from #67992. It runs the same hang against this detector and master's NCCLRASCallback.

see this gist for all the logs: https://gist.github.com/liulehui/92f3c67921e0eca7b6fed36c3ef33bdd

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Fix All in Cursor

❌ 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]>
@liulehui
liulehui force-pushed the ray-train-health/nccl-ras-health branch from f14d808 to 958982b Compare November 20, 2026 17:15
@pseudo-rnd-thoughts
pseudo-rnd-thoughts enabled stacked auto-merge (squash) November 20, 2026 17:31
@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit c493813 into master Nov 20, 2026
5 checks passed
@pseudo-rnd-thoughts
pseudo-rnd-thoughts deleted the ray-train-health/nccl-ras-health branch November 20, 2026 18:23
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