Compare commits
2 commits
main
...
feature/ro
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8df5d7d176 | ||
|
|
8028c52600 |
3 changed files with 21 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ from .hardware import (
|
||||||
DeviceType,
|
DeviceType,
|
||||||
DEVICE,
|
DEVICE,
|
||||||
CHAT_ONLY,
|
CHAT_ONLY,
|
||||||
|
IS_ROCM,
|
||||||
detect_hardware,
|
detect_hardware,
|
||||||
get_device,
|
get_device,
|
||||||
is_apple_silicon,
|
is_apple_silicon,
|
||||||
|
|
@ -49,6 +50,7 @@ __all__ = [
|
||||||
"DeviceType",
|
"DeviceType",
|
||||||
"DEVICE",
|
"DEVICE",
|
||||||
"CHAT_ONLY",
|
"CHAT_ONLY",
|
||||||
|
"IS_ROCM",
|
||||||
"detect_hardware",
|
"detect_hardware",
|
||||||
"get_device",
|
"get_device",
|
||||||
"is_apple_silicon",
|
"is_apple_silicon",
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class DeviceType(str, Enum):
|
||||||
|
|
||||||
DEVICE: Optional[DeviceType] = None
|
DEVICE: Optional[DeviceType] = None
|
||||||
CHAT_ONLY: bool = True # No CUDA GPU -> GGUF chat only (Mac, CPU-only, etc.)
|
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 ==========
|
# ========== Detection ==========
|
||||||
|
|
@ -85,10 +86,11 @@ def detect_hardware() -> DeviceType:
|
||||||
2. MLX (Apple Silicon via MLX framework)
|
2. MLX (Apple Silicon via MLX framework)
|
||||||
3. CPU (fallback)
|
3. CPU (fallback)
|
||||||
"""
|
"""
|
||||||
global DEVICE, CHAT_ONLY
|
global DEVICE, CHAT_ONLY, IS_ROCM
|
||||||
CHAT_ONLY = True # reset -- only CUDA sets it to False
|
CHAT_ONLY = True # reset -- only CUDA/ROCm sets it to False
|
||||||
|
IS_ROCM = False
|
||||||
|
|
||||||
# --- CUDA: try PyTorch ---
|
# --- CUDA / ROCm: try PyTorch ---
|
||||||
if _has_torch():
|
if _has_torch():
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
|
@ -96,7 +98,16 @@ def detect_hardware() -> DeviceType:
|
||||||
DEVICE = DeviceType.CUDA
|
DEVICE = DeviceType.CUDA
|
||||||
CHAT_ONLY = False
|
CHAT_ONLY = False
|
||||||
device_name = torch.cuda.get_device_properties(0).name
|
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
|
return DEVICE
|
||||||
|
|
||||||
# --- XPU: Intel GPU ---
|
# --- XPU: Intel GPU ---
|
||||||
|
|
@ -315,13 +326,15 @@ def get_package_versions() -> Dict[str, Optional[str]]:
|
||||||
except PackageNotFoundError:
|
except PackageNotFoundError:
|
||||||
versions[name] = None
|
versions[name] = None
|
||||||
|
|
||||||
# CUDA toolkit version bundled with torch
|
# GPU runtime version bundled with torch
|
||||||
try:
|
try:
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
versions["cuda"] = getattr(torch.version, "cuda", None)
|
versions["cuda"] = getattr(torch.version, "cuda", None)
|
||||||
|
versions["rocm"] = getattr(torch.version, "hip", None)
|
||||||
except Exception:
|
except Exception:
|
||||||
versions["cuda"] = None
|
versions["cuda"] = None
|
||||||
|
versions["rocm"] = None
|
||||||
|
|
||||||
return versions
|
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"
|
" a = np.array([int(x.decode('utf-8'))/1024 for x in a])\n"
|
||||||
"except:\n"
|
"except:\n"
|
||||||
" if not torch.cuda.is_available():\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"
|
"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"
|
" raise RuntimeError('Unsloth currently does not support multi GPU setups - but we are working on it!')\n"
|
||||||
"for _ in range(3):\n"
|
"for _ in range(3):\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue