Skip to content

[Train] Improve hang detector logging to identify culprit ranks - #66629

Merged
pseudo-rnd-thoughts merged 12 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/culprit-rank
Oct 16, 2026
Merged

pseudo-rnd-thoughts merged 12 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/culprit-rank

Conversation

@pseudo-rnd-thoughts

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

Copy link
Copy Markdown
Member

Description

Improves the Train NCCL hang detector logging of which ranks are mismatches / skewed. Importantly, NCCL RAS used for detection will report the comminicator's rank which might have no relationship to the Ray Train worker ranks.
Therefore, this PR updates the logs to add this contextual information for users.
Not implemented is adding a file for translating the nccl ras rank to the ray train worker ranks for larger debugging.

Using this a example testing script with multiple communicators which after about a minute of compute will hang on one of the communicators. This is the logs for the example script above.

There are a couple of things we can improve.

  • Clarify that the text report is from NCCL RAS
  • Clarify the suspected hang is from the Ray Train hang detector
  • Only print the RAS report once per suspected hang to minimise the log spam
  • Add a short description of the stalled communicator with the Train ranks to help match against the RAS reports ranks (which differ).

Here is the updated log

...
(RayTrainWorker pid=4163, ip=10.0.181.29) Reporting training result 30: TrainingReport(checkpoint=None, metrics={'step': 580, 'pair_loss': 1.0481277704238892}, validation=False) from rank 1 [repeated 12x across cluster]
(RayTrainWorker pid=4163, ip=10.0.181.29) [rank 1] step 580 pair_loss=1.0481 [repeated 12x across cluster]
(TrainController pid=5822) Possible NCCL hang detected! 2 communicator(s) have made no collective progress for 60 seconds while their ranks disagree on how many collectives they have launched. Continuing to monitor, this might be a transient stall. A NCCLHangError will be raised in 120 seconds (24 more polls) if this persists.
(TrainController pid=5822)   - Communicator 0x30f69d63e50d57eb over train ranks 2-3, no progress for 60s. AllReduce launches: 622 by train rank 2; 621 by train rank 3
(TrainController pid=5822)   - Communicator 0x1fe9c6c4ea15d8d9 over train ranks 0-3, no progress for 60s. AllReduce launches: 1245 by train ranks 0-1, 3; 1243 by train rank 2
(TrainController pid=5822) NCCL's own `ncclras` report of the suspected hang (logged once per hang). Its ranks are numbered per communicator, not by Ray Train world rank:
(TrainController pid=5822) NCCL version 2.30.7 compiled with CUDA 12.9
(TrainController pid=5822) CUDA runtime version 12090, driver version 13000
(TrainController pid=5822)
(TrainController pid=5822) Job summary
(TrainController pid=5822) ===========
(TrainController pid=5822)
(TrainController pid=5822)   Nodes  Processes         GPUs  Processes     GPUs
(TrainController pid=5822) (total)   per node  per process    (total)  (total)
(TrainController pid=5822)       1          4            1          4        4
(TrainController pid=5822)
(TrainController pid=5822) Communicators... (0.000s)
(TrainController pid=5822) =============
(TrainController pid=5822)
(TrainController pid=5822) Group     Comms     Nodes     Ranks     Ranks     Ranks    Status  Errors
(TrainController pid=5822)     #  in group  per comm  per node  per comm  in group
(TrainController pid=5822)     0         1         1         4         4         4   RUNNING  MISMATCH
(TrainController pid=5822)     1         1         1         2         2         2   RUNNING  MISMATCH
(TrainController pid=5822)     2         1         1         2         2         2   RUNNING      OK
(TrainController pid=5822)
(TrainController pid=5822) Errors
(TrainController pid=5822) ======
(TrainController pid=5822)
(TrainController pid=5822) Warnings
(TrainController pid=5822) ========
(TrainController pid=5822)
(TrainController pid=5822) #0-0 (1fe9c6c4ea15d8d9) MISMATCH
(TrainController pid=5822)   Communicator ranks have different AllReduce operation counts
(TrainController pid=5822)   3 ranks have launched up to operation 1245
(TrainController pid=5822)   Rank 2 has launched up to operation 1243 -- GPU 2 managed by process 4165 on node 10.0.181.29
(TrainController pid=5822)
(TrainController pid=5822) #1-0 (30f69d63e50d57eb) MISMATCH
(TrainController pid=5822)   Communicator ranks have different AllReduce operation counts
(TrainController pid=5822)   Rank 0 has launched up to operation 622 -- GPU 2 managed by process 4165 on node 10.0.181.29
(TrainController pid=5822)   Rank 1 has launched up to operation 621 -- GPU 3 managed by process 4164 on node 10.0.181.29
(RayTrainWorker pid=4165, ip=10.0.181.29) [rank 2] step 620 pair_loss=1.0508 [repeated 11x across cluster]
(RayTrainWorker pid=4165, ip=10.0.181.29) Reporting training result 32: TrainingReport(checkpoint=None, metrics={'step': 620, 'pair_loss': 1.0508112907409668}, validation=False) from rank 2 [repeated 11x across cluster]
(TrainController pid=5822) NCCL hang still suspected! 2 communicator(s) have made no progress. A NCCLHangError will be raised in 90 seconds (18 more polls) if this persists.
(TrainController pid=5822)   - Communicator 0x30f69d63e50d57eb over train ranks 2-3, no progress for 90s. AllReduce launches: 622 by train rank 2; 621 by train rank 3
(TrainController pid=5822)   - Communicator 0x1fe9c6c4ea15d8d9 over train ranks 0-3, no progress for 90s. AllReduce launches: 1245 by train ranks 0-1, 3; 1243 by train rank 2
(TrainController pid=5822) NCCL hang still suspected! 2 communicator(s) have made no progress. A NCCLHangError will be raised in 60 seconds (12 more polls) if this persists.
(TrainController pid=5822)   - Communicator 0x30f69d63e50d57eb over train ranks 2-3, no progress for 120s. AllReduce launches: 622 by train rank 2; 621 by train rank 3
(TrainController pid=5822)   - Communicator 0x1fe9c6c4ea15d8d9 over train ranks 0-3, no progress for 120s. AllReduce launches: 1245 by train ranks 0-1, 3; 1243 by train rank 2
(TrainController pid=5822) NCCL hang still suspected! 2 communicator(s) have made no progress. A NCCLHangError will be raised in 30 seconds (6 more polls) if this persists.
(TrainController pid=5822)   - Communicator 0x30f69d63e50d57eb over train ranks 2-3, no progress for 150s. AllReduce launches: 622 by train rank 2; 621 by train rank 3
(TrainController pid=5822)   - Communicator 0x1fe9c6c4ea15d8d9 over train ranks 0-3, no progress for 150s. AllReduce launches: 1245 by train ranks 0-1, 3; 1243 by train rank 2
(TrainController pid=5822) [FailurePolicy] RAISE

@pseudo-rnd-thoughts
pseudo-rnd-thoughts requested a review from a team as a code owner October 1, 2026 15:41
@pseudo-rnd-thoughts pseudo-rnd-thoughts added train Ray Train Related Issue go add ONLY when ready to merge, run all tests labels Oct 1, 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 enhances the NCCL RAS callback in Ray Train to map stalled communicator ranks back to their corresponding Ray Train workers using host and PID information. This allows for more detailed logging of hung ranks and populates worker failures in NCCLHangError. The review feedback highlights several robustness improvements, including handling potential ValueError exceptions when calculating skews or formatting logs with empty collections, preventing TypeError if a PID is null in the JSON, and avoiding false-positive worker matches when fallback PIDs are used.

Mark Towers added 3 commits October 8, 2026 21:54
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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4c4a190. Configure here.

Mark Towers added 4 commits October 9, 2026 14:32
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]>
if worker.distributed_context is None:
continue
world_rank = worker.distributed_context.world_rank
by_process[(worker.metadata.node_ip, worker.metadata.pid)] = world_rank

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.

I sometimes confused by the metadata.node_ip and node_id..
is it possible that 2 ray nodes on the same physical node hence 1 node ip -> 2 node id? will it break this mapping?

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.

Great question, I hadn't thought about it before. Researching it, heres what I've found:node_id names a Ray node (one raylet), and node_ip is the network address that raylet advertises. Therefore, you can have two node IDs behind one IP.
This can only happen if the user configures their Docker container or KubeRay to use the same IP for different containers which raylet will dislike already.

In our translation function, this could only be a problem if the following are all true at the same time

  1. Two Ray nodes share one IP where the user specifies custom hosts
  2. Each node has its own PID namespace.
  3. Two training workers end up with the same pid.

except Exception: # noqa: BLE001
logger.exception(
"NCCL RAS hang detection hit an unexpected error, therefore, "
"The Ray Train hang detector hit an unexpected error, therefore, "

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.

maybe "Ray Train NCCL RAS Hang Detector" in case later we have other hang detect logic?

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.

Yes, good point will update across the PR

return DiagnosticResult(value=proc.stdout)


def translate_ras_ranks_to_train(

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.

I wonder if this mapping is valueble to be added in controller/worker group,
basically, given that we have a single controller, the controller itself should keep a world_rank -> ras rank mapping, (is the ras rank equal the train run context local rank? )

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.

on a another question, what will happen for the below scenarios, e.g. we have 2 node, each node has 4 GPUs.

ScalingConfig(num_workers=2, resources_per_worker={"GPU": 4})`
ScalingConfig(num_workers=4, resources_per_worker={"GPU": 2})`
ScalingConfig(num_workers=8, resources_per_worker={"GPU": 1})`

In terms of ras rank to world rank mapping, will there be any difference? is it based on CUDA_VISIBLE_DEVICES?

@pseudo-rnd-thoughts pseudo-rnd-thoughts Oct 13, 2026 •

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.

is the ras rank equal the train run context local rank?

Not necessarily is my understanding. The RAS rank is per communicator but should normally align as you have a world communicator across all ranks for coordination. However, we have no control on how NCCL assigns ranks compared to our Train worker ranks.
Therefore, I don't think we should have a table in the controller for worker rank to ras rank.

For the second question. There are two ways the multi-GPU configs behave differently:

  1. Model parallelism means that a one process uses multiple GPUs through NCCL. For us this happens when a single worker has multiple GPUs in its resource bundle. In this case, multiple GPUs would be tied to the same worker ranks. I'm checking if this would cause a weird logging issue
  2. If an individual worker spawns child processes like a Ray serve server that itself owns its GPUs which wouldn't have a worker rank that matches it.

I hope that answers your questions

Mark Towers added 4 commits October 13, 2026 12:49
…prit-rank

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]>

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

thanks for putting it out!

@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit 804929e into ray-project:master Oct 16, 2026
6 checks passed
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.

2 participants