Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Find libamdhip64 by versioned name when the plain name is missing
YanissAmz13f0ab48321d
diff --git a/exllamav3/modules/attention_fn/qsa_prefill_hip.py b/exllamav3/modules/attention_fn/qsa_prefill_hip.pyindex db80fc2..562fef1 100644--- a/exllamav3/modules/attention_fn/qsa_prefill_hip.py+++ b/exllamav3/modules/attention_fn/qsa_prefill_hip.py@@ -1,6 +1,7 @@"""Loader for qsa_prefill.hip (one wave per (row, kv head)). Same call shape as qsa_prefill.qsa_prefill_attend (fp16, shared or per-row block table)."""import ctypes, hashlib, os, re, shutil, subprocessimport torch+from exllamav3.util.hip_lib import find_hip_runtime_SRC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "qsa_prefill.hip")_state = {}@@ -49,8 +50,8 @@ def hsaco_stats(path):def _load(defs = ""):if defs in _state: return _state[defs]cache = compile_hsaco(defs, torch.cuda.get_device_properties(0).gcnArchName.split(":")[0])- p = os.path.join(os.path.dirname(torch.__file__), "lib", "libamdhip64.so")- if not os.path.isfile(p): # the copy torch already loaded+ p = find_hip_runtime()+ if p is None: # the copy torch already loadedp = next(l.split()[-1] for l in open("/proc/self/maps") if "libamdhip64" in l)lib = ctypes.CDLL(p)torch.cuda.init()diff --git a/exllamav3/modules/ple_fn/ple_hip.py b/exllamav3/modules/ple_fn/ple_hip.pyindex 045f021..5f57e9b 100644--- a/exllamav3/modules/ple_fn/ple_hip.py+++ b/exllamav3/modules/ple_fn/ple_hip.py@@ -2,6 +2,7 @@# hipcc genco (cached by source hash), launched through torch's libamdhip64 on the current stream.import ctypes, hashlib, os, shutil, subprocessimport torch+from exllamav3.util.hip_lib import load_hip_runtime_SRC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ple_hip.hip")_state = {}@@ -42,7 +43,7 @@ def _load():if "fns" in _state:return _state["fns"]cache = compile_hsaco(torch.cuda.get_device_properties(0).gcnArchName.split(":")[0])- lib = ctypes.CDLL(os.path.join(os.path.dirname(torch.__file__), "lib", "libamdhip64.so"))+ lib = load_hip_runtime()torch.cuda.init()mod = ctypes.c_void_p()if lib.hipModuleLoad(ctypes.byref(mod), cache.encode()) != 0:diff --git a/exllamav3/util/hip_lib.py b/exllamav3/util/hip_lib.pynew file mode 100644index 0000000..d6dab64--- /dev/null+++ b/exllamav3/util/hip_lib.py@@ -0,0 +1,37 @@+# Find torch's bundled HIP runtime. Stable wheels ship libamdhip64.so; nightly ROCm wheels ship only versioned+# names (libamdhip64.so.7, libamdhip64.so.7.1.2 ...). Plain name first, then the versioned ones, highest first.++import ctypes, glob, os, re, sys++_NAME = "libamdhip64.so"+_logged = set()+++def _version_key(path: str):+ return tuple(int(x) for x in re.findall(r"\d+", os.path.basename(path)[len(_NAME):]))+++def find_hip_runtime(lib_dir: str | None = None) -> str | None:+ """Path of libamdhip64 inside lib_dir (default: <torch>/lib), or None when there is none."""+ if lib_dir is None:+ import torch+ lib_dir = os.path.join(os.path.dirname(torch.__file__), "lib")+ plain = os.path.join(lib_dir, _NAME)+ if os.path.isfile(plain):+ return plain+ versioned = [p for p in glob.glob(os.path.join(lib_dir, _NAME + ".*")) if os.path.isfile(p)+ and re.fullmatch(r"(\.\d+)+", os.path.basename(p)[len(_NAME):])]+ if not versioned:+ return None+ best = max(versioned, key = _version_key)+ if best not in _logged:+ _logged.add(best)+ print(f"hip_lib: {_NAME} not found in {lib_dir}, using {os.path.basename(best)}", file = sys.stderr, flush = True)+ return best+++def load_hip_runtime(lib_dir: str | None = None) -> ctypes.CDLL:+ path = find_hip_runtime(lib_dir)+ if path is None:+ raise OSError(f"no {_NAME} or {_NAME}.<version> in {lib_dir or 'the torch lib directory'}")+ return ctypes.CDLL(path)diff --git a/exllamav3/vendor/fla/hip/gdn_fused_h_hip.py b/exllamav3/vendor/fla/hip/gdn_fused_h_hip.pyindex d843a18..672ac72 100644--- a/exllamav3/vendor/fla/hip/gdn_fused_h_hip.py+++ b/exllamav3/vendor/fla/hip/gdn_fused_h_hip.py@@ -4,6 +4,7 @@import ctypes, hashlib, os, shutil, subprocessimport torch+from exllamav3.util.hip_lib import load_hip_runtime_SRC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "gdn_fused_h.hip")_state = {}@@ -41,7 +42,7 @@ def _load(defs=""):if defs in _state:return _state[defs]cache = _compile(defs, torch.cuda.get_device_properties(0).gcnArchName.split(":")[0])- lib = ctypes.CDLL(os.path.join(os.path.dirname(torch.__file__), "lib", "libamdhip64.so"))+ lib = load_hip_runtime()torch.cuda.init()mod, fn = ctypes.c_void_p(), ctypes.c_void_p()if lib.hipModuleLoad(ctypes.byref(mod), cache.encode()) != 0:diff --git a/exllamav3/vendor/fla/hip/kda_fused_h_hip.py b/exllamav3/vendor/fla/hip/kda_fused_h_hip.pyindex 0e5eb98..09d90a3 100644--- a/exllamav3/vendor/fla/hip/kda_fused_h_hip.py+++ b/exllamav3/vendor/fla/hip/kda_fused_h_hip.py@@ -4,6 +4,7 @@import ctypes, hashlib, os, shutil, subprocessimport torch+from exllamav3.util.hip_lib import load_hip_runtime_SRC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "kda_fused_h.hip")_state = {}@@ -41,7 +42,7 @@ def _load(defs=""):if defs in _state:return _state[defs]cache = _compile(defs, torch.cuda.get_device_properties(0).gcnArchName.split(":")[0])- lib = ctypes.CDLL(os.path.join(os.path.dirname(torch.__file__), "lib", "libamdhip64.so"))+ lib = load_hip_runtime()torch.cuda.init()mod, fn = ctypes.c_void_p(), ctypes.c_void_p()if lib.hipModuleLoad(ctypes.byref(mod), cache.encode()) != 0:diff --git a/tests/test_hip_lib.py b/tests/test_hip_lib.pynew file mode 100644index 0000000..950a926--- /dev/null+++ b/tests/test_hip_lib.py@@ -0,0 +1,48 @@+import importlib.util, io, os, contextlib+from pathlib import Path++_spec = importlib.util.spec_from_file_location(+ "hip_lib", Path(__file__).parent.parent / "exllamav3" / "util" / "hip_lib.py")+hip_lib = importlib.util.module_from_spec(_spec)+_spec.loader.exec_module(hip_lib)+++def _touch(d, *names):+ for n in names:+ (d / n).write_bytes(b"")+++def _find(d):+ err = io.StringIO()+ with contextlib.redirect_stderr(err):+ return hip_lib.find_hip_runtime(str(d)), err.getvalue()+++def test_plain_name_wins_and_is_silent(tmp_path):+ _touch(tmp_path, "libamdhip64.so", "libamdhip64.so.7")+ path, log = _find(tmp_path)+ assert path == str(tmp_path / "libamdhip64.so") and log == ""+++def test_versioned_fallback_picks_highest_and_logs_once(tmp_path):+ _touch(tmp_path, "libamdhip64.so.6", "libamdhip64.so.7", "libamdhip64.so.7.1.2", "libamdhip64.so.10",+ "libamdhip64.so.bak", "libamdhip64.so.7.txt")+ path, log = _find(tmp_path)+ assert path == str(tmp_path / "libamdhip64.so.10")+ assert log.count("\n") == 1 and "libamdhip64.so.10" in log+ assert _find(tmp_path)[1] == "" # already reported+++def test_dotted_versions_sort_numerically(tmp_path):+ _touch(tmp_path, "libamdhip64.so.7", "libamdhip64.so.7.1.2", "libamdhip64.so.7.1.10")+ assert _find(tmp_path)[0] == str(tmp_path / "libamdhip64.so.7.1.10")+++def test_none_when_absent_and_load_raises(tmp_path):+ assert _find(tmp_path)[0] is None+ try:+ hip_lib.load_hip_runtime(str(tmp_path))+ except OSError:+ pass+ else:+ raise AssertionError("expected OSError")