Repository navigation
[Train] Add nvidia-smi diagnostics to hang detector - #66229
matthewdeng merged 11 commits into
Conversation
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
There was a problem hiding this comment.
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.
| _, not_ready = ray.wait(list(refs), num_returns=len(refs), timeout=timeout_s) | ||
| for ref, rank in refs.items(): | ||
| if ref in not_ready: |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
This PR should have no memory overhead as it saved at the end with the data send directly from the node to disk. |
# 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]>
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
nit: would be helpful to add some more detail on the existing use cases, nncl ras + nvidia-smi. Maybe rename to WorkerDiagnosticDump or WorkerDiagnosticInfo
There was a problem hiding this comment.
Good point, I've updated to DiagnosticResult, this will match Lehui's ProbeResult class
Signed-off-by: Mark Towers <[email protected]>
|
Thanks for the review @JasonLi1909
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 |
Signed-off-by: Mark Towers <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit 06e5635. Configure here.
…ang-detector/nvidia-smi
| error: Optional[str] = None | ||
|
|
||
|
|
||
| def fan_out_to_workers( |
There was a problem hiding this comment.
I wonder if we can add a WorkerGroup/ExecutionGroup.execute_async_with_timeout(fn, *args, timeout_s) to WorkerGroup/ExecutionGroup for this one.
There was a problem hiding this comment.
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: |
| return "\n".join(lines) | ||
|
|
||
|
|
||
| def run_nvidia_smi(timeout_s: float) -> Dict[str, Any]: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I don't understand this. Are you saying we should call the diagnostics in parallel or series?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good point, I think it was helpful before but isn't anymore, will remove
| value: What the diagnostic function returned, or ``None`` if it didn't. | ||
| error: Why this diagnostic has no value, or ``None`` when it does. |
There was a problem hiding this comment.
Should this be a union instead?
There was a problem hiding this comment.
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): ...
There was a problem hiding this comment.
Kk it's a nit but just wanted to guard against the possibility of both being set or both being not set.
There was a problem hiding this comment.
Agreed, it would be nice to prevent with a dataclass __post_init__ check
|
|
||
| rank: int | ||
| value: Optional[Any] = None | ||
| error: Optional[str] = None |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| Returns: | ||
| A dict ``{"ok": bool, ...}``. On success ``stdout`` holds the report. | ||
| On failure ``reason`` says why there is none. | ||
| """ |
There was a problem hiding this comment.
Any particular reason for returning a dict rather than create a dataclass to represent this return value?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good point, I'll look at a dataclass for this.
Signed-off-by: Mark Towers <[email protected]>
Signed-off-by: Mark Towers <[email protected]>

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