Skip to content

fix: AMD multi-GPU detection and misleading error message in tokenizer_utils.py - #4450

Closed
GoldenGrapeGentleman wants to merge 3 commits into
unslothai:mainfrom
GoldenGrapeGentleman:fix/tokenizer-amd-multigpu
Closed

GoldenGrapeGentleman wants to merge 3 commits into
unslothai:mainfrom
GoldenGrapeGentleman:fix/tokenizer-amd-multigpu

Conversation

@GoldenGrapeGentleman

Copy link
Copy Markdown
Contributor

Problem

The memory check injected into SFTTrainer/DPOTrainer/KTOTrainer.train() has two bugs on AMD ROCm hosts:

  1. Silent multi-GPU bypass: nvidia-smi is absent on AMD systems, so the memory array a stays as np.array([0.]). The multi-GPU guard ((a - PRE_CHECK) >= 1).sum() > 1 is always False on AMD, regardless of actual GPU count.

  2. Misleading error message: "We do not support AMD / Intel machines yet" appears in source code. On a properly installed ROCm system, torch.cuda.is_available() returns True so this error is never raised — but it causes confusion and discourages AMD users.

Fix

In the nvidia-smi except block, after confirming a GPU is present, populate a via torch.cuda.memory_reserved() — which works on ROCm via HIP — giving one entry per visible GPU. The multi-GPU check then correctly fires on AMD multi-GPU configurations.

Update the error message to guide AMD users to install ROCm-enabled PyTorch.

Testing

Verified on 8×AMD MI355X (ROCm 7.1):

  • nvidia-smi not found → falls through to torch.cuda.memory_reserved
  • a.shape = (8,) correctly reflects 8 GPUs ✅
  • Multi-GPU check fires as expected ✅
  • Error message no longer mentions AMD as unsupported ✅

Co-authored-by: billishyahao [email protected]

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

The check injected into SFTTrainer/DPOTrainer/KTOTrainer.train() had
two bugs on AMD ROCm hosts:

1. nvidia-smi is absent on AMD systems, so the memory array 'a' was
   never populated — it stayed as np.array([0.]).  This silently
   bypassed the multi-GPU guard for AMD users even when multiple GPUs
   were active, because ((a - PRE_CHECK) >= 1).sum() > 1 was always
   False regardless of actual GPU usage.

2. The error message 'We do not support AMD / Intel machines yet' is
   misleading: on properly installed ROCm, torch.cuda.is_available()
   returns True so the error is never raised, but the message still
   appears in the source and causes confusion.

Fix: in the nvidia-smi except block, after confirming a GPU is
present, populate 'a' via torch.cuda.memory_reserved() which works
on ROCm via HIP, giving one entry per visible GPU.  The multi-GPU
check then correctly fires on AMD multi-GPU configurations.
Update the error message to guide AMD users to install ROCm PyTorch.

Tested on 8×AMD MI355X (ROCm 7.1):
  - nvidia-smi not found → falls through to torch.cuda.memory_reserved
  - a.shape = (8,) correctly reflects 8 GPUs
  - multi-GPU check fires as expected ✅

Co-authored-by: billishyahao <[email protected]>
@GoldenGrapeGentleman
GoldenGrapeGentleman force-pushed the fix/tokenizer-amd-multigpu branch from aa07010 to fb50daf Compare March 19, 2026 02:43
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

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