Skip to content

[Train] Add nvidia-smi diagnostics to hang detector - #66229

Merged
matthewdeng merged 11 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/nvidia-smi
Oct 8, 2026
Merged

matthewdeng merged 11 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:hang-detector/nvidia-smi

Conversation

@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member

Description

For the hang detector, it currently has a suite of diagnostics for identifying software based causes for a hang (stack trace, pytorch flight recorder, nccl ras, etc). However, a hang can be caused by both hardware and software like networks or GPU failures. Therefore, this PR adds nvidia-smi -q as a diagnostic tool on confirmations to understand the state of the underlying hardware used during training and save this data at the end.

Related issues

Continuation of #64928

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

@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 hang-detection callback by adding support for capturing per-node nvidia-smi snapshots alongside worker stack traces when a hang is confirmed. It refactors the parallel execution logic into a reusable fan_out_to_workers helper and introduces structured diagnostic uploading. Comprehensive unit and integration tests are also added to verify these diagnostics. The review feedback suggests two valuable improvements: optimizing a list membership check to O(1) by converting not_ready to a set in fan_out_to_workers, and adding an early return in dump_nodes_nvidia_smi if no workers are found to prevent redundant empty uploads.

Comment on lines +550 to +552
_, not_ready = ray.wait(list(refs), num_returns=len(refs), timeout=timeout_s)
for ref, rank in refs.items():
if ref in not_ready:

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.

medium

Checking membership in a list (ref in not_ready) has O(N) time complexity. Converting not_ready to a set before the loop optimizes this to O(1) lookup time, which is more efficient, especially for larger clusters with many workers.

        _, not_ready = ray.wait(list(refs), num_returns=len(refs), timeout=timeout_s)
        not_ready_set = set(not_ready)
        for ref, rank in refs.items():
            if ref in not_ready_set:

@JasonLi1909 JasonLi1909 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! Let's get confirmation from @liulehui that there's no duplication against his work. Otherwise, there are also some conflicts against #66228 so let's decide which implementation we want between the two and merge that one first. We'll also want to measure the memory overhead of this feature similar to #66228.

@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member Author

We'll also want to measure the memory overhead of this feature similar to #66228.

This PR should have no memory overhead as it saved at the end with the data send directly from the node to disk.

Mark Towers and others added 3 commits September 23, 2026 08:26
# 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.

@JasonLi1909 JasonLi1909 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! Currently, the PR captures nvidia-smi at the time of the hang confirmation but by the time the 10 minute timeout is triggered, some useful diagnostic information has expired such as utilization, clocks, power, temperature, and memory use. It would be great if we could also capture nvidia-smi earlier in the hang rather than just at the 10 minute mark. Aside from that, LGTM!


@dataclass
class WorkerDump:
"""One worker's answer to a fan-out diagnostic call.

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.

nit: would be helpful to add some more detail on the existing use cases, nncl ras + nvidia-smi. Maybe rename to WorkerDiagnosticDump or WorkerDiagnosticInfo

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.

Good point, I've updated to DiagnosticResult, this will match Lehui's ProbeResult class

Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member Author

Thanks for the review @JasonLi1909

Currently, the PR captures nvidia-smi at the time of the hang confirmation but by the time the 10 minute timeout is triggered, some useful diagnostic information has expired such as utilization, clocks, power, temperature, and memory use. It would be great if we could also capture nvidia-smi earlier in the hang rather than just at the 10 minute mark.

Yes, agreed. This PR only saves the diagnostics at confirmation, whereas at suspicion might provide more accurate information to when the hang starts. This is also true of the flight-recorder diagnostics. The problem is that there can be multiple concurrent suspicion and suspicions can be resolved over time so we need a method to save multiple diagnostics at the same time and delete resolved ones. Therefore, I'll add this feature in another PR

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

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 06e5635. Configure here.

error: Optional[str] = None


def fan_out_to_workers(

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 we can add a WorkerGroup/ExecutionGroup.execute_async_with_timeout(fn, *args, timeout_s) to WorkerGroup/ExecutionGroup for this one.

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, certainly can. Would you want be to do that in this PR or subsequent?

return list(dumps.values())


def dump_stack_trace(pyspy_timeout_s: float) -> str:

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.

FYI comment for myself, we can migrate this as a NodeProbe with:
#66536 and #66650

return "\n".join(lines)


def run_nvidia_smi(timeout_s: float) -> Dict[str, Any]:

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.

if we have multiple diagnostics, e.g. nvidia-smi and flight recorder, is it possible that at one time,
nvidia-smi (request_1) fires first, pending, then flight_recorder(request_2) queue for the nvidia-smi run completes since they are using the same worker rpc?
this way the recorder call timeout basically need to take into request_1 timeout as well?

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 don't understand this. Are you saying we should call the diagnostics in parallel or series?

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 think it is more of reliability for multiple diagnostic issue:
IIUC (correct me if I am wrong), consider the below case for Nvidia-smi (A) and flight recorder (B), each timeout is 30s.

t=0     A sent ─────── A still running on the worker ─────────────►
t=30   controller marks A "timed out" and sends B → B waits behind A
t=60   controller marks B "timed out after 30s" (B never started), sends C → C waits

can we handle if A is timing out?

@pseudo-rnd-thoughts pseudo-rnd-thoughts Oct 7, 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.

Interesting point, I hadn't considered that. Yes, we could abort subsequent diagnostic dumps if the first timeouts. Can we do that in future versions?

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.

yeah I think it should be good for future version, one approach I can think of is move the execution of diagnostic to it's own thread, similar to our train_func.
and the nvidia-smi can also be migrate to another process (which is essentially the NodeMonitor), we can address that in that integration I think.

"""The results from a diagnostic (nvidia-smi, py-spy, etc) from a node or worker.

Attributes:
rank: The worker's 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.

does rank need to be an attribute of the DiagnosticResult itself? Seems like the caller will have its own definition based on whether it's node or worker diagnostic.

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.

Good point, I think it was helpful before but isn't anymore, will remove

Comment on lines +537 to +538
value: What the diagnostic function returned, or ``None`` if it didn't.
error: Why this diagnostic has no value, or ``None`` when it does.

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.

Should this be a union instead?

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.

It certainly could but I would vote to keep as its easier to read and understand, particularly downstream.
I don't want to have to do if isinstance(diagnostic_result.value, Exception): ...

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.

Kk it's a nit but just wanted to guard against the possibility of both being set or both being not set.

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.

Agreed, it would be nice to prevent with a dataclass __post_init__ check


rank: int
value: Optional[Any] = None
error: Optional[str] = None

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.

Would generally recommend keeping this as a typed Error object rather than the string, so that downstream consumers have the flexibility to parse the error and do logic based on the error type.

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.

This is purely internal as an intermediate state from the diagnostic health check function on each worker to saving the result to a file. For @liulehui work that would make more sense where a user might want to reason about it

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 do think there's still value even if it's internal, just for general maintainability/extensibility. If keeping as a string just make sure to mention in the docstring that this should be a human readable string that describes the error?

"""

rank: int
value: Optional[Any] = None

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.

Is there any better typing for what this value can be? Can it be any object or does it need to be a string or serializable or something else?

@pseudo-rnd-thoughts pseudo-rnd-thoughts Oct 7, 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.

The value needs to be written to a file however it might have intermediate data which is combined at dump, sadly not. I thought we might be able to restrict to a string

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.

Ah I see.

Comment on lines +641 to +644
Returns:
A dict ``{"ok": bool, ...}``. On success ``stdout`` holds the report.
On failure ``reason`` says why there is none.
"""

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.

Any particular reason for returning a dict rather than create a dataclass to represent this return value?

@pseudo-rnd-thoughts pseudo-rnd-thoughts Oct 7, 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.

Complexity. I want to keep this simple. For @liulehui work which will be more public facing and other users might want to build on some of the diagnostics then yes that would certainly be more helpful.

This implementation is currently a single-file very self-contained solution compared to @liulehui more comprehensive solution.

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 actually think it's more simple to just create a dataclass similar to DiagnosticResult. Makes it easier for developers to understand the contract and the consumer code can directly access attributes rather than unassigned string lookup.

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.

Good point, I'll look at a dataclass for this.

Mark Towers added 2 commits October 7, 2026 16:52
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@matthewdeng
matthewdeng merged commit 6ee33e5 into ray-project:master Oct 8, 2026
6 checks passed
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.

4 participants