Skip to content

Add unsloth doctor --gpus multi-GPU preflight and UNSLOTH_DEBUG_DISTRIBUTED - #13884

Merged
danielhanchen merged 13 commits into
mainfrom
dh/unsloth-doctor-gpus
Oct 16, 2026
Merged

danielhanchen merged 13 commits into
mainfrom
dh/unsloth-doctor-gpus

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Multi-GPU problems on consumer and cloud boxes usually show up as a hang at the first collective, or as silently wrong peer copies on hosts with a translating IOMMU. Today the only tool is scripts/p2p_integrity_probe.py, which is aimed at llama.cpp and is not part of the installed package. This adds a preflight that answers "will distributed training work on this machine" before a long job starts.

unsloth doctor --gpus (also python -m unsloth_cli doctor) prints:

  • torch, CUDA or ROCm build, driver and NCCL versions, and every visible GPU with its compute capability, memory and PCI id
  • the NVML topology per GPU pair (PIX / PXB / PHB / NODE / SYS, NVLink, P2P read) when nvidia-ml-py is installed, matched to torch indices by PCI bus id so CUDA_VISIBLE_DEVICES does not scramble it
  • a peer copy integrity check for every ordered pair, using a sentinel-filled destination
  • an all_reduce across all visible GPUs in separate processes with a short collective timeout and a hard deadline, so a hang is reported instead of hanging the doctor, plus the measured bus bandwidth
  • a verdict with hints. If the all_reduce fails or hangs it is retried with NCCL_P2P_DISABLE=1, and the hint says whether that fixed it. Peer copy corruption points to NCCL_P2P_DISABLE=1 and the IOMMU log. PHB / NODE / SYS links without NVLink recommend DDP for LoRA, since it only moves the adapter gradients, over FSDP / ZeRO-3 / tensor parallel.

The exit status is 1 when a problem is found, so it can gate a launch script.

Output on a Kaggle T4x2 (torch 2.14.1, NCCL 2.30.7):

=== Topology (NVML) ===
0<->1  PHB   nvlink=no  p2p_read=no

=== Peer copy integrity ===
0->1  peer_access=yes  ok
1->0  peer_access=yes  ok

=== all_reduce smoke (2 ranks, nccl) ===
ok  busbw 3.94 GB/s (64 MiB fp32)

=== Verdict: OK ===
- GPU pairs [(0, 1)] talk through the PCIe host bridge or the CPU interconnect (PHB / NODE / SYS), with no NVLink. For LoRA prefer DDP: it only all-reduces the small adapter gradients, while FSDP / ZeRO-3 and tensor parallel move the full weights every step over this link.

UNSLOTH_DEBUG_DISTRIBUTED=1 is a single switch for hang debugging. At import unsloth, before any process group exists, it sets TORCH_NCCL_DESYNC_DEBUG=1, TORCH_NCCL_DUMP_ON_TIMEOUT=1, NCCL_DEBUG=INFO and a 2000 entry flight recorder under the name the installed torch reads: TORCH_FR_BUFFER_SIZE on torch 2.8+, TORCH_NCCL_TRACE_BUFFER_SIZE on 2.6 and 2.7 (2.7 defaults the recorder to off). Setting both would make newer torch warn on every rank. Anything the user already set is left alone, and the two buffer names are treated as one setting so an explicit TORCH_NCCL_TRACE_BUFFER_SIZE=0 is respected. Without the flag nothing changes.

Tests (CPU): unsloth_cli/tests/test_doctor_gpus.py runs a real 2-rank gloo all_reduce, a forced hang, every verdict branch, the NVML pair mapping with a fake pynvml and the full command with a faked 2-GPU torch. tests/test_debug_distributed_env.py covers the env switch and checks the hook runs before torch is imported.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-16T07:07:20.170963Z f84eeac New commits
🔒 Security Review ✅ Completed 2026-10-15T16:16:54.182670Z a41a92e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: a41a92e8a9

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

… detection, file-backed rank logs, NVML init for driver; set both flight recorder names

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…l started ranks when a spawn fails, report a torch that fails to load

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…terrupt, require P2P read both ways

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d8a0a8173

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

typer.echo(f"ROCm (HIP) {info['hip']}")
else:
typer.echo(f"CUDA (torch build) {info['cuda']}")
typer.echo(f"driver {driver_version(pynvml) or 'unknown'}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Select the driver probe by GPU backend

When info["hip"] identifies a supported ROCm installation, this still invokes driver_version(), which only queries NVIDIA NVML and nvidia-smi. Consequently an AMD-only host always reports driver unknown, while a mixed AMD/NVIDIA host can report the unrelated NVIDIA driver as though it belongs to the ROCm devices; choose a ROCm-specific query or clearly omit this NVIDIA-only field in that branch.

Useful? React with 👍 / 👎.

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.

On ROCm the line already reads "driver unknown" when NVML has nothing to report, which is accurate rather than misleading; a mixed AMD and NVIDIA host is not a configuration torch can use for one training job, so a ROCm-specific driver query adds nothing to the verdict.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d6eee289d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +178 to +180
if not uuid.startswith(("GPU-", "MIG-")):
uuid = "GPU-" + uuid
handles.append(pynvml.nvmlDeviceGetHandleByUUID(uuid.encode()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve bare MIG UUIDs with the MIG prefix

On PyTorch 2.6/2.7 with CUDA MIG devices, the PCI fields are absent and this fallback is used, but str(_CudaDeviceProperties.uuid) is a bare UUID because PyTorch formats the raw CUuuid bytes without retaining the device kind (PyTorch binding). CUDA returns the subscribed MIG instance's UUID in MIG mode, while NVML distinguishes GPU and MIG identifiers (CUDA documentation, NVML documentation); unconditionally prepending GPU- therefore makes nvmlDeviceGetHandleByUUID miss the MIG instance and disables the entire topology table. Match against NVML UUIDs or retry the bare UUID with MIG- before declaring topology unavailable.

Useful? React with 👍 / 👎.

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.

MIG instances do not support peer-to-peer and are not used for multi-GPU NCCL training, which is what this table is for; on that path the topology section degrades to unavailable without affecting the verdict.

…be crashes, bound rank reaping; debug env: no writes once a process group exists

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: c2e987518a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit e61d529 into main Oct 16, 2026
@danielhanchen
danielhanchen deleted the dh/unsloth-doctor-gpus branch October 16, 2026 10:49
oobabooga pushed a commit to oobabooga/unsloth that referenced this pull request Oct 19, 2026
…-budget metrics across ranks (unslothai#14207)

## Summary

Three follow-ups on opt-in features. Default runs are unchanged.

1. **MFU logging (unslothai#13885).** For packed batches that carry only
`position_ids`, the token count branched on data, which broke `fullgraph
= True` compilation and added a host sync per micro-batch. It is now
computed without a data-dependent branch. Also adds an H200 NVL entry at
835.5 dense TFLOPS (half of NVIDIA's 1,671 with-sparsity figure); it was
being measured against the H200 SXM peak.
2. **NCCL INFO logs under `UNSLOTH_DEBUG_DISTRIBUTED` (unslothai#13884).**
Importing unsloth_zoo sets `NCCL_DEBUG=WARN` whenever a logging or
compile-debug switch is on, so the debug flag lost the NCCL INFO logs it
asks for. With `UNSLOTH_DEBUG_DISTRIBUTED` set, unsloth now saves
`NCCL_DEBUG` before that import and restores it after.
3. **Token-budget split metrics across ranks (unslothai#13878).** Logged accuracy
and entropy from split chunks were averaged per rank. Each chunk is now
weighted by its token count summed across ranks. The decision to merge
is folded into the existing chunk-count collective, so every rank merges
or none do: no extra collective and no chance of one rank waiting on
another.

## Tests

| File | main | this PR |
|---|---|---|
| `tests/test_mfu_logging.py` | 2 failed | pass |
| `tests/test_debug_distributed_env.py` | 2 failed (real zoo import) |
pass |
| `tests/test_token_budget_metrics_distributed.py` (2 gloo ranks) | 3
failed | pass |

53 passed in total.

## Not covered here

- No real multi-rank NCCL run; the distributed tests use gloo.
- The H200 NVL device-name string is assumed to contain "H200 NVL".
- A `NCCL_DEBUG` you export yourself is still overwritten when the debug
flag is off; that needs a change in unsloth_zoo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant