ROCm HW support
This commit is contained in:
@@ -39,6 +39,26 @@ class KVCacheMiss(ModelBackendError):
|
||||
"""
|
||||
|
||||
|
||||
def _torch_cuda_is_executable(torch_module: Any) -> bool:
|
||||
"""Return True only when this process can actually execute a CUDA/HIP op.
|
||||
|
||||
On ROCm, ``torch.cuda.is_available()`` can be true for an AMD GPU even when
|
||||
the installed PyTorch wheel has no runnable kernels for that GPU target.
|
||||
Loading weights onto such a device can segfault in native code, so the model
|
||||
backend must use the same executable-device check as startup hardware
|
||||
detection rather than trusting inventory alone.
|
||||
"""
|
||||
try:
|
||||
if not torch_module.cuda.is_available():
|
||||
return False
|
||||
probe = torch_module.empty((1,), device="cuda")
|
||||
probe += 1
|
||||
torch_module.cuda.synchronize()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TensorPayload:
|
||||
body: bytes
|
||||
@@ -209,7 +229,7 @@ class TorchModelShard:
|
||||
) from exc
|
||||
|
||||
self.torch = torch
|
||||
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
self.device = torch.device("cuda" if _torch_cuda_is_executable(torch) else "cpu")
|
||||
load_source = str(cache_dir) if cache_dir is not None and (cache_dir / "config.json").exists() else model_id
|
||||
quant_config, dtype, uses_quantized_weights = _model_load_plan(
|
||||
AutoConfig,
|
||||
|
||||
Reference in New Issue
Block a user