Repository navigation
[Train] Add export events for the Ray Train NCCL Hang Detector - #66937
pseudo-rnd-thoughts wants to merge 25 commits into
Conversation
Signed-off-by: Mark Towers <[email protected]>
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]>
There was a problem hiding this comment.
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.
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]>
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]>
Signed-off-by: Mark Towers <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
There are 5 total unresolved issues (including 3 from previous reviews).
Reviewed by Cursor Bugbot for commit c1feaaf. Configure here.
| outcome.new_suspicion | ||
| or outcome.periodic_reminder | ||
| or outcome.recovered_comms | ||
| ): |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit c1feaaf. Configure here.
There was a problem hiding this comment.
I did a more holistic upgrade at this time to review almost every line to check that they make sense
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]>
|
Closing in favor of a future PR using the health API |


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_HANGexport 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'scommunicators.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].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
run_id,attempt_idExportTrainRunEventData.idandExportTrainRunAttemptEventData.attempt_idpoll_index,timestamp_mspoll_indexorders an attempt's events (strictly increasing). The export envelope'stimestamponly has one-second resolutiondetector_statusMONITORING/STOPPED/DISABLED. It describes the detector, not the hang: whether a hang is suspected or confirmed is given bycommunicatorsdisabled_reasonDISABLEDonly:RAS_UNAVAILABLE(e.g. thencclrasbinary is missing, which the user can fix in their setup) orINTERNAL_ERROR(a detector bug)ras_text_reportncclras -f textreport, on the first poll of a suspected hang and on its confirmation, capped at 32 KB with the beginning keptdiagnostics_dir<experiment_fs_path>/hang_detector)communicators[]communicator_id,state(SUSPECTED/CONFIRMED),stalled_since_msBoth are proto enums, and the communicator state enum is nested inside
Communicator, so it prints unprefixed in the JSON ("SUSPECTED").stalled_since_msis 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)export_train_nccl_hang.proto, wired intoExportEventasSourceType.EXPORT_TRAIN_NCCL_HANG = 10andtrain_nccl_hang_event_data = 14.EventLogType.TRAIN_NCCL_HANG, which writes to its ownevent_EXPORT_TRAIN_NCCL_HANG.log. Existing readers of theTRAIN_STATEfile 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 modelsTrainNcclHangEventandNcclCommunicator, 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.TrainStateActorkeeps one export logger per enabled source type instead of a singleTRAIN_STATElogger, soEXPORT_TRAIN_RUN,EXPORT_TRAIN_RUN_ATTEMPTandEXPORT_TRAIN_NCCL_HANGcan each be enabled on their own. A newexport_train_nccl_hang_eventmethod 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.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:
CommStallis one record per stalled communicator: frozen-poll count, start time and whether it's confirmed. It replaces thecomm_deadlock_countdict, which stays available as a read-only property for compatibility.PollOutcomedescribes what one poll found: confirmed, suspected (new or reminder) and recovered communicators, plus the text report and diagnostics directories gathered for them.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 raisesNCCLHangError.before_worker_group_shutdownexportsSTOPPEDwhen a communicator is hung. The fatal-ncclraspath and the unexpected-error path both go throughdisable(), which exportsDISABLEDwith the matching reason.