Add IS_ROCM hardware flag and fix AMD error message
Add IS_ROCM flag to hardware.py detect_hardware() (set when torch.version.hip is present, DeviceType stays CUDA). Export IS_ROCM from __init__.py. Add "rocm" key to get_package_versions(). Replace "We do not support AMD" error in tokenizer_utils.py with a helpful message pointing to ROCm installation docs. Co-authored-by: Daniel Han <danielhanchen@gmail.com>
This commit is contained in:
parent
062e25fe7b
commit
450f5de507
3 changed files with 19 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ from .hardware import (
|
|||
DeviceType,
|
||||
DEVICE,
|
||||
CHAT_ONLY,
|
||||
IS_ROCM,
|
||||
detect_hardware,
|
||||
get_device,
|
||||
is_apple_silicon,
|
||||
|
|
@ -49,6 +50,7 @@ __all__ = [
|
|||
"DeviceType",
|
||||
"DEVICE",
|
||||
"CHAT_ONLY",
|
||||
"IS_ROCM",
|
||||
"detect_hardware",
|
||||
"get_device",
|
||||
"is_apple_silicon",
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class DeviceType(str, Enum):
|
|||
|
||||
DEVICE: Optional[DeviceType] = None
|
||||
CHAT_ONLY: bool = True # No CUDA GPU -> GGUF chat only (Mac, CPU-only, etc.)
|
||||
IS_ROCM: bool = False # True when running on AMD ROCm (HIP) -- display/logging only
|
||||
|
||||
|
||||
# ========== Detection ==========
|
||||
|
|
@ -85,10 +86,11 @@ def detect_hardware() -> DeviceType:
|
|||
2. MLX (Apple Silicon via MLX framework)
|
||||
3. CPU (fallback)
|
||||
"""
|
||||
global DEVICE, CHAT_ONLY
|
||||
CHAT_ONLY = True # reset -- only CUDA sets it to False
|
||||
global DEVICE, CHAT_ONLY, IS_ROCM
|
||||
CHAT_ONLY = True # reset -- only CUDA/ROCm sets it to False
|
||||
IS_ROCM = False
|
||||
|
||||
# --- CUDA: try PyTorch ---
|
||||
# --- CUDA / ROCm: try PyTorch ---
|
||||
if _has_torch():
|
||||
import torch
|
||||
|
||||
|
|
@ -96,7 +98,14 @@ def detect_hardware() -> DeviceType:
|
|||
DEVICE = DeviceType.CUDA
|
||||
CHAT_ONLY = False
|
||||
device_name = torch.cuda.get_device_properties(0).name
|
||||
print(f"Hardware detected: CUDA — {device_name}")
|
||||
|
||||
# Distinguish AMD ROCm (HIP) from NVIDIA CUDA for display purposes.
|
||||
# DeviceType stays CUDA since torch.cuda.* works on ROCm via HIP.
|
||||
if getattr(torch.version, "hip", None) is not None:
|
||||
IS_ROCM = True
|
||||
print(f"Hardware detected: ROCm (HIP {torch.version.hip}) -- {device_name}")
|
||||
else:
|
||||
print(f"Hardware detected: CUDA -- {device_name}")
|
||||
return DEVICE
|
||||
|
||||
# --- XPU: Intel GPU ---
|
||||
|
|
@ -315,13 +324,15 @@ def get_package_versions() -> Dict[str, Optional[str]]:
|
|||
except PackageNotFoundError:
|
||||
versions[name] = None
|
||||
|
||||
# CUDA toolkit version bundled with torch
|
||||
# GPU runtime version bundled with torch
|
||||
try:
|
||||
import torch
|
||||
|
||||
versions["cuda"] = getattr(torch.version, "cuda", None)
|
||||
versions["rocm"] = getattr(torch.version, "hip", None)
|
||||
except Exception:
|
||||
versions["cuda"] = None
|
||||
versions["rocm"] = None
|
||||
|
||||
return versions
|
||||
|
||||
|
|
|
|||
|
|
@ -1103,7 +1103,7 @@ def patch_sft_trainer_tokenizer():
|
|||
" a = np.array([int(x.decode('utf-8'))/1024 for x in a])\n"
|
||||
"except:\n"
|
||||
" if not torch.cuda.is_available():\n"
|
||||
" raise RuntimeError('Unsloth: We do not support AMD / Intel machines yet - it is a work in progress!')\n"
|
||||
" raise RuntimeError('Unsloth: No GPU detected. AMD ROCm users: install ROCm-enabled PyTorch -- see https://docs.unsloth.ai/get-started/install-and-update/amd')\n"
|
||||
"if ((a - PRE_CHECK) >= 1).sum() > 1:\n"
|
||||
" raise RuntimeError('Unsloth currently does not support multi GPU setups - but we are working on it!')\n"
|
||||
"for _ in range(3):\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue