Skip to content

[Train] Add export events for the Ray Train NCCL Hang Detector - #66937

Closed
pseudo-rnd-thoughts wants to merge 25 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/anyscale-integration
Closed

pseudo-rnd-thoughts wants to merge 25 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/anyscale-integration

Conversation

@pseudo-rnd-thoughts

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Description

The NCCL Hang detector currently only reports through logging its findings with no capability for platforms to hook into the detector and know whats happening. This PR adds EXPORT_TRAIN_NCCL_HANG export event that carries the core detector's state: which communicators are hung, if the detector is still running, etc. A future PR can add significantly more data for the ranks involved, their nodes, host, etc for future visualisations of the problem. Importantly, exporting never changes what the detector decides. Every export path catches its own exceptions, and events are sent fire-and-forget without waiting on any actor.

The event

ExportTrainNcclHangEventData (src/ray/protobuf/export_train_nccl_hang.proto) is a snapshot of the communicators the detector considers hung with the poll index, the communicators that are hanging with its state + stalled since timestamp and ras report option. To avoid spamming the consumer, we only export a train nccl hang event in three cases: when at least one communicator is suspected of hanging, the next poll after communicators have been resolved and when the detector is disabled due to ncclras not being available. This allows a consumer to understand when multi-communicator has a mixture of suspected, confirmed and resolved cases.

Examples. […] is the event's communicators.

A hang that resolves. If one communicator resolves while another stays hung, the event just lists fewer of them, e.g. [A:SUSPECTED, B:SUSPECTED] → [B:SUSPECTED].

Suspected, then resolved (both modes)
  poll   1    2    3    4    5    6    7
         ●────●────●────●────●────●────●───── … run continues
              ▲    ▲         ▲    ▲
              │    │         │    └─ MONITORING  []               progress seen: all clear
              │    │         └────── MONITORING  [A:SUSPECTED]    reminder (no report)
              │    └──────────────── MONITORING  [A:SUSPECTED]    + ras_text_report (first suspicion)
              └───────────────────── counts first freeze: stalled_since_ms

Confirmed, then resolved (observe mode only; fail mode raises on confirmation)
         ●────●────●────●────●────●────●───── … run continues
                   ▲    ▲         ▲    ▲
                   │    │         │    └─ MONITORING  []              all clear
                   │    │         └────── MONITORING  [A:CONFIRMED]   reminder
                   │    └──────────────── MONITORING  [A:CONFIRMED]   + report + diagnostics_dir
                   └───────────────────── MONITORING  [A:SUSPECTED]   + report

Important to note that the NCCLHangEvent is not appended to the TrainAttempt which contains the metadata about the training run configurations. As the state of a nccl hang can change over the running of a training attempt then we save the nccl hang events as separate to allow it to evolve over time

Fields

Field Notes
run_id, attempt_id Join to ExportTrainRunEventData.id and ExportTrainRunAttemptEventData.attempt_id
poll_index, timestamp_ms poll_index orders an attempt's events (strictly increasing). The export envelope's timestamp only has one-second resolution
detector_status MONITORING / STOPPED / DISABLED. It describes the detector, not the hang: whether a hang is suspected or confirmed is given by communicators
disabled_reason DISABLED only: RAS_UNAVAILABLE (e.g. the ncclras binary is missing, which the user can fix in their setup) or INTERNAL_ERROR (a detector bug)
ras_text_report NCCL's own ncclras -f text report, on the first poll of a suspected hang and on its confirmation, capped at 32 KB with the beginning kept
diagnostics_dir On the poll that confirms a communicator: where the diagnostics were uploaded (<experiment_fs_path>/hang_detector)
communicators[] communicator_id, state (SUSPECTED / CONFIRMED), stalled_since_ms

Both are proto enums, and the communicator state enum is nested inside Communicator, so it prints unprefixed in the JSON ("SUSPECTED"). stalled_since_ms is the poll before the first frozen poll, since the counts were already frozen then. A reader works out "no progress for N minutes" from it, so the duration keeps increasing between events.

Changes

Core (src/ray/protobuf, ray/_private/event)

  • New export_train_nccl_hang.proto, wired into ExportEvent as SourceType.EXPORT_TRAIN_NCCL_HANG = 10 and train_nccl_hang_event_data = 14.
  • New EventLogType.TRAIN_NCCL_HANG, which writes to its own event_EXPORT_TRAIN_NCCL_HANG.log. Existing readers of the TRAIN_STATE file never see these events, and the Train state schema version (TRAIN_SCHEMA_VERSION) is unchanged.

Train state export (train/v2/_internal/state)

  • schema.py: Pydantic models TrainNcclHangEvent and NcclCommunicator, plus the status, reason and state enums.
  • export.py: train_nccl_hang_event_to_proto, and _truncate_ras_report, which cuts on a UTF-8-safe byte boundary and appends a truncation marker.
  • TrainStateActor keeps one export logger per enabled source type instead of a single TRAIN_STATE logger, so EXPORT_TRAIN_RUN, EXPORT_TRAIN_RUN_ATTEMPT and EXPORT_TRAIN_NCCL_HANG can each be enabled on their own. A new export_train_nccl_hang_event method exports the event, or drops it when its export is disabled. The actor doesn't keep the events; the export log is their only record.
  • New NcclHangEventExporter, which the detector calls. It looks up the state actor once (never creating it, and skipping the lookup if Ray isn't running), sends each event with .remote(), and never raises. It never waits on the actor, so exporting can't stall the controller's poll loop. Without state tracking there is no state actor, so the events are dropped, as the run and attempt events are. Events are sent even when export is disabled, because only the actor's environment says whether it's enabled. They're rare (a few per suspected hang), so sending them costs little.

Hang detector (train/v2/_internal/callbacks/nccl_ras.py)

The poll handling is restructured so that deciding what happened is separate from reporting it:

  • CommStall is one record per stalled communicator: frozen-poll count, start time and whether it's confirmed. It replaces the comm_deadlock_count dict, which stays available as a read-only property for compatibility.
  • PollOutcome describes what one poll found: confirmed, suspected (new or reminder) and recovered communicators, plus the text report and diagnostics directories gathered for them.
  • Each poll now runs evaluate_comm_mismatch (decide; nothing is logged or acted on) → gather_evidence (capture diagnostics on confirmation, fetch the text report on a suspicion) → log_outcome → export_poll → act_on_confirmed_hangs (raise in fail mode, warn in observe mode). The log lines and the event therefore always describe the same poll, and the confirmation is exported before fail mode raises NCCLHangError.
  • before_worker_group_shutdown exports STOPPED when a communicator is hung. The fatal-ncclras path and the unexpected-error path both go through disable(), which exports DISABLED with the matching reason.
  • The detector's decisions are unchanged. Log wording, warning cadence, diagnostics capture order and the text-report fetch are all the same as on master; on a confirmation, the text report the diagnostics already fetch is reused for the event.

Mark Towers and others added 12 commits October 1, 2026 16:28
Signed-off-by: Mark Towers <[email protected]>
# Conflicts:
#	python/ray/train/v2/_internal/callbacks/nccl_ras.py
#	python/ray/train/v2/tests/test_nccl_ras_callback.py
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Add an export event for the Ray Train NCCL hang detector: a new
ExportTrainNcclHangEventData message (in its own proto file, so the train
run schema version is untouched), the EXPORT_TRAIN_NCCL_HANG source type
and a TRAIN_NCCL_HANG EventLogType.

Each event is a snapshot of the detector at one poll it reported on: the
poll index, ACTIVE/STOPPED status, what the poll reported (triggers), the
log headline, the ncclras text report and diagnostics directory when
captured, and the state of every non-healthy communicator (with the stall
start, duration and the stalled ranks grouped by launch count).

The new type is written to its own event_EXPORT_TRAIN_NCCL_HANG.log, never
to event_EXPORT_TRAIN_STATE.log, so existing consumers of the train state
events never see it. The schema change is additive only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Add TrainNcclHangEvent (with NcclCommunicatorState and StalledRanks) to
the Train state schema and TrainStateActor.export_train_nccl_hang_event,
which converts the event and writes it to the EXPORT_TRAIN_NCCL_HANG
export log when that type is enabled. The ncclras text report is capped
at 32 KB, keeping its head. Events are not kept in the actor; their
history lives in the export log.

The state actor now keeps one export logger per enabled source type
instead of one logger and two flags, since the hang events are written to
their own file.

export_nccl_hang_event() is the fire-and-forget entry point for the
detector: it only looks the state actor up (never creates it) and never
raises.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
NCCLRASCallback now exports, through the Train state actor, one
EXPORT_TRAIN_NCCL_HANG event for each poll whose outcome it logs, so a
platform can show a hang without parsing the logs. Each event is a
snapshot of every non-healthy communicator (SUSPECTED or CONFIRMED, plus
RECOVERED for those that recovered on that poll), so the newest event of
an attempt is the detector's current state:

- triggers record what the poll reported: SUSPECTED (a new suspicion or
  the periodic warning, by the same rule as the log), CONFIRMED and
  RECOVERED, together in one event when they coincide;
- a confirmed communicator stays CONFIRMED for the rest of its episode,
  including in the periodic warnings of observe mode;
- the CONFIRMED event is exported after the diagnostics are captured
  (with their directory) and before the fail/observe action, so it exists
  even when NCCLHangError is raised;
- a STOPPED event, at most once per attempt, when the worker group shuts
  down or the detector disables itself with a communicator still stalled.

The ncclras text report is attached once, to the polls that fetched it.
Stalled ranks are Ray Train world ranks grouped by launch count, built
from the same grouping as the log line. Stall start and duration satisfy
timestamp_ms - stalled_since_ms == stall_duration_s for open
communicators.

A communicator that first becomes suspected on the poll another is
confirmed is now warned about (reusing that poll's report) and exported,
instead of waiting for its next periodic warning. Log output is otherwise
unchanged, and exporting never affects detection: every event goes
through one guarded path and the state actor call is fire-and-forget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Add two gauges set by the NCCL hang detector on every poll, healthy or
not, so a run's dashboards can show the shape of a stall over time:

- train_nccl_hang_detector_state: 0 healthy, 1 suspected, 2 confirmed;
- train_nccl_hang_stall_duration_s: the longest stall in progress.

Both are labelled by run name, run id and attempt id only, never by
communicator, as communicator hashes change on every restart. The value is
the worst across communicators. The gauges are reset when the detector
stops watching an attempt (worker group shutdown or self-disable), and
recording them never affects detection.

Adds a GaugeMetric (latest value) next to TimeMetric and EnumMetric.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts pseudo-rnd-thoughts added the train Ray Train Related Issue label Oct 12, 2026
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested review from a team as code owners October 12, 2026 13:59
@pseudo-rnd-thoughts pseudo-rnd-thoughts added the go add ONLY when ready to merge, run all tests label Oct 12, 2026

@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 the EXPORT_TRAIN_NCCL_HANG event type to the Ray Train export API, allowing NCCL hang detector events to be exported to their own log file. It updates the hang detector callback to translate RAS communicator ranks into Ray Train world ranks for clearer diagnostics, records run-level metrics for hang detector state and stall duration, and exports detailed snapshots of stalled communicators. Additionally, comprehensive unit and integration tests are added to verify the new event export, metrics, and rank translation logic. There are no review comments to address, so I have no feedback to provide.

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

Comment thread src/ray/protobuf/export_event.proto Resolved
Mark Towers and others added 4 commits October 14, 2026 17:45
Resolve conflicts with ray-project#66203 (flight recorder): keep the branch's debug-step
message structure and add the flight recorder dump and its debug step; port
the branch's export, metrics and rank-translation tests onto master's
rewritten test_nccl_ras_callback.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
…scale-integration

Signed-off-by: Mark Towers <[email protected]>

# Conflicts:
#	python/ray/train/v2/_internal/callbacks/nccl_ras.py
#	python/ray/train/v2/tests/test_nccl_ras_callback.py
Signed-off-by: Mark Towers <[email protected]>

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

Mark Towers added 2 commits October 19, 2026 12:12
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts pseudo-rnd-thoughts changed the title [DO NOT MERGE / Train] Export events for hang-detector states [Train] Add export events for the Ray Train NCCL Hang Detector Oct 19, 2026
Mark Towers added 2 commits October 19, 2026 15:59
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 20, 2026 16:45
Signed-off-by: Mark Towers <[email protected]>

@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 and found 2 potential issues.

There are 5 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit c1feaaf. Configure here.

outcome.new_suspicion
or outcome.periodic_reminder
or outcome.recovered_comms
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Confirmation drops recovery logging

Low Severity

When one communicator confirms on the same poll that another recovers, the confirmed_comms branch runs and the elif that calls log_suspected_and_recovered_comms is skipped. The recovery is still reflected in the exported communicator list, but the detector no longer logs that the recovered communicator resumed progress.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c1feaaf. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did a more holistic upgrade at this time to review almost every line to check that they make sense

Mark Towers added 3 commits October 22, 2026 11:39
# Conflicts:
#	python/ray/train/v2/_internal/callbacks/nccl_ras.py
#	python/ray/train/v2/tests/test_nccl_ras_callback.py
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member Author

Closing in favor of a future PR using the health API

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.

1 participant