Skip to content

[Train] Add flight recorder to nccl hang detector - #66203

Merged
matthewdeng merged 23 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/flight-recorder
Oct 13, 2026
Merged

matthewdeng merged 23 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/flight-recorder

Conversation

@pseudo-rnd-thoughts

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Description

Flight recorder is a pytorch feature that records metadata on collectives that are run on each ranks like shape, dtype, etc and helps users diagnose collective related issues like hangs. Therefore, this PR integrates the flight recorder into the NCCL hang detector as a diagnostic tool.

The flight recorder is armed through the env-var then the buffer can be dumped at any point through _dump_fr_trace_json. On confirmation we dump all the buffers and save each rank's data to different file. To explore is saving the buffers on suspicion to prevent other communicators to override the hanging communicator on the same rank.

This is the last diagnostic PR for the hang detector (stack trace, nvidia-smi, ras-history and flight recorder), therefore, I've rewritten the testing script to combine the separate diagnostic tests into parameterized tests

Related issues

Continuation of #64928

Mark Towers added 3 commits September 16, 2026 10:48
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts pseudo-rnd-thoughts added train Ray Train Related Issue go add ONLY when ready to merge, run all tests labels Sep 16, 2026
@pseudo-rnd-thoughts
pseudo-rnd-thoughts marked this pull request as ready for review September 18, 2026 14:03
@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner September 18, 2026 14:03

@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 adds PyTorch Flight Recorder diagnostics collection alongside worker stack traces when a NCCL hang is detected. It introduces a parallel fan-out mechanism to collect these diagnostics from all workers and upload them to the experiment's storage directory. The review feedback identifies a potential AttributeError in dump_flight_recorder because _dump_fr_trace_json() can return a str instead of bytes in some PyTorch versions. It is recommended to conditionally decode the trace data only if it is a bytes object, and to update the unit tests to verify both return types.

@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 and others added 4 commits September 18, 2026 17:29
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]>
@github-actions

github-actions Bot commented Oct 3, 2026

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 3, 2026
…order

# Conflicts:
#	python/ray/train/v2/_internal/callbacks/nccl_ras.py
#	python/ray/train/v2/tests/test_nccl_ras_callback.py
#	python/ray/train/v2/tests/test_nccl_ras_hang_detection.py
@pseudo-rnd-thoughts pseudo-rnd-thoughts removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Oct 5, 2026

@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 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 060d625. Configure here.

Mark Towers and others added 10 commits October 6, 2026 10:55
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
…order

# 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]>
…order

# Conflicts:
#	python/ray/train/v2/tests/test_nccl_ras_callback.py
Signed-off-by: Mark Towers <[email protected]>
Mark Towers added 3 commits October 8, 2026 22:05
# Conflicts:
#	python/ray/train/v2/_internal/callbacks/nccl_ras.py
#	python/ray/train/v2/tests/test_nccl_ras_callback.py
#	python/ray/train/v2/tests/test_nccl_ras_hang_detection.py
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@matthewdeng
matthewdeng merged commit 0a31bd0 into ray-project:master Oct 13, 2026
6 checks passed
pseudo-rnd-thoughts pushed a commit to pseudo-rnd-thoughts/ray that referenced this pull request Oct 16, 2026
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]>
pseudo-rnd-thoughts pushed a commit that referenced this pull request Nov 4, 2026
…#67794)

## Problem

- The NCCL hang detector dumps a hung worker's stack with an
unprivileged `py-spy dump --pid <pid> --native`.
- In containers with restricted ptrace that call always fails. The dump
then has no native frames, so it cannot show where NCCL is blocked.
- py-spy reports: `Permission Denied: Try running again with elevated
permissions by going 'sudo env "PATH=$PATH" !!'`
- Verified on an Anyscale worker: `CapEff: 0000000000000000`,
`/proc/sys/kernel/yama/ptrace_scope` is `1`, so a child py-spy cannot
trace its parent.
- The `ray` user there has passwordless sudo, and `sudo env PATH=$PATH
py-spy dump --pid <pid> --native` succeeds with native frames.

## Change

- Try the unprivileged py-spy first, as today.
- If it fails and `sudo -n true` succeeds, retry as `sudo -n env
PATH=... py-spy dump --pid <pid> --native` with the same timeout.
- Otherwise fall through to the Python-only dump, with py-spy's own
error message.
- This mirrors `_can_passwordless_sudo` in
`python/ray/dashboard/modules/reporter/profile_manager.py`, run
synchronously.
- `dump_stack_trace` is split into `_run_py_spy(cmd, timeout_s)` and
`_can_passwordless_sudo()`.

```
py-spy dump --native ──fail──> sudo -n true ok? ──yes──> sudo -n env PATH=... py-spy dump --native
                                      └──no──> Python-only dump (as today)
```

## Decisions to confirm

- The sudo check is cached per process, since the hung worker may dump
more than once.
- `sudo -n` is used everywhere so it can never prompt for a password.
- The `sudo -n true` check has a 5 s timeout.
- sudo is not tried when py-spy is not on `PATH`. A missing binary is
not a permission problem.
- The timeout is a budget for the whole dump. The sudo check and retry
only get what the first attempt left, so the fan-out timeout still
holds.

## Related

- Detector PRs by @pseudo-rnd-thoughts: #64928, #66203, #66629, #66627.
- Companion PR #67795 adds thread names to the Python-only fallback; the
two touch different parts of `dump_stack_trace` and apply independently.

Duplicate-work check: `gh pr list -R ray-project/ray --search "nccl_ras
OR hang detector"` and `--search "py-spy sudo"` returned nothing related
(only the unrelated Grafana PRs #66958 and #66810).

Tests: `python -m pytest
python/ray/train/v2/tests/test_nccl_ras_callback.py -v` passes, 120
passed, including four new `dump_stack_trace` sudo tests.

AI assistance (Claude Code) was used for this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Marwan Sarieddine <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
pseudo-rnd-thoughts pushed a commit that referenced this pull request Nov 4, 2026
…mp (#67795)

## Problem

- py-spy is refused on many workers because ptrace is restricted in
containers. Every Anyscale worker is one of them (empty `CapEff`, Yama
`ptrace_scope` 1).
- The Python-only fallback is therefore the dump users actually see.
- It labels each thread with its numeric ident only. The reader has to
infer from the frames which one is Ray Train's
`TrainingThread(train_func)`, which is the `MonitoringThread`, and which
is the actor main thread.
- Current output, from a hung Ray Train worker on Anyscale:

```
# Thread 137667459151424
  File "/usr/lib/python3.12/threading.py", line 1030, in _bootstrap
    self._bootstrap_inner()
```

## Change

- `dump_stack_trace` looks up thread names once through
`threading.enumerate()` and prints the name next to the ident.
- The rest of the dump is unchanged.

```
before:  # Thread 137667459151424
after:   # Thread 137667459151424 (TrainingThread(train_func))
```

## Decisions to confirm

- Threads that are not in `threading.enumerate()` (threads not started
through `threading`, for example C-created ones) are labelled `unknown`.

## Related

- Detector PRs by @pseudo-rnd-thoughts: #64928, #66203, #66629, #66627.
- #67794 (sudo retry for py-spy) touches the same function but not these
lines. The two apply independently.

Duplicate-work check: `gh pr list -R ray-project/ray --search "nccl_ras
OR hang detector"` and a search for "thread name" with "nccl_ras" found
no PR making this change (only the Grafana and user-guide PRs #66958,
#66810, #67068 and the sibling #67794).

Test: `python -m pytest
python/ray/train/v2/tests/test_nccl_ras_callback.py -v` passes, 117
tests. `pre-commit run --files` on both files passes.

AI assistance (Claude Code) was used for this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Marwan Sarieddine <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
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.

3 participants