Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
fix(rocm): prefer system LLVM runtime on native Linux (#7448)
Willow Lopez77971d0debd0
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 47e46405beb..f76afce9f4a 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -309,6 +309,15 @@ def _native_linux_system_rocm_lib_dirs(binary_dir: str = "") -> "list[str]":os.path.join(d, "libhsa-runtime64.so.1")):out.append(d)+ # ROCm keeps LLVM's versioned runtime under <root>/lib/llvm, so a+ # lib64 host still finds it under lib. Probe both and keep them+ # ahead of the bundle, else system libamd_comgr binds to the+ # bundle's incompatible libLLVM.so.*.+ for _sub in (lib_sub, "lib"):+ llvm_lib = os.path.join(base, _sub, "llvm", "lib")+ if llvm_lib not in seen and os.path.isdir(llvm_lib):+ seen.add(llvm_lib)+ out.append(llvm_lib)return outdiff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.pyindex 529b90c3e37..dd64d74d7d3 100644--- a/studio/install_llama_prebuilt.py+++ b/studio/install_llama_prebuilt.py@@ -4807,6 +4807,15 @@ def _native_linux_system_rocm_lib_dirs(binary_dir: str = "") -> list[str]:os.path.join(d, "libhsa-runtime64.so.1")):out.append(d)+ # ROCm keeps LLVM's versioned runtime under <root>/lib/llvm, so a+ # lib64 host still finds it under lib. Probe both and keep them+ # ahead of the bundle, else system libamd_comgr binds to the+ # bundle's incompatible libLLVM.so.*.+ for _sub in (lib_sub, "lib"):+ llvm_lib = os.path.join(base, _sub, "llvm", "lib")+ if llvm_lib not in seen and os.path.isdir(llvm_lib):+ seen.add(llvm_lib)+ out.append(llvm_lib)return outdiff --git a/tests/studio/install/test_rocm_native_linux_lib_dirs.py b/tests/studio/install/test_rocm_native_linux_lib_dirs.pyindex 9b95af88b01..39663bbc196 100644--- a/tests/studio/install/test_rocm_native_linux_lib_dirs.py+++ b/tests/studio/install/test_rocm_native_linux_lib_dirs.py@@ -124,7 +124,12 @@ def _call(tmp_path factory branches on it, so a session-wide patch breaks the fixture ona Windows test host."""with patch.object(sys, "platform", platform):- with patch("os.path.exists", _fake_exists(present)):+ # isdir too: the llvm probe requires a directory, so a fake host that only+ # answers exists() would report every nested llvm dir as missing.+ with (+ patch("os.path.exists", _fake_exists(present)),+ patch("os.path.isdir", _fake_exists(present)),+ ):return _norm(impl(str(bundle)))@@ -260,6 +265,78 @@ class TestNativeLinuxRootResolution:for where, impl in _impls().items():assert self._run(impl, bundle_dir, present) == ["/opt/rocm/lib64"], where+ def test_nested_llvm_runtime_follows_system_rocm_lib(self, bundle_dir):+ """#7446: libamd_comgr depends on ROCm's versioned LLVM runtime, which is+ installed below lib/llvm/lib rather than directly in lib."""+ present = {+ "/dev/kfd",+ "/opt/rocm/lib/libhsa-runtime64.so",+ "/opt/rocm/lib/llvm/lib",+ }+ for where, impl in _impls().items():+ assert self._run(impl, bundle_dir, present) == [+ "/opt/rocm/lib",+ "/opt/rocm/lib/llvm/lib",+ ], where++ def test_lib64_host_still_finds_llvm_under_lib(self, bundle_dir):+ """ROCm puts LLVM under <root>/lib/llvm even where HSA lives in lib64, so+ deriving the llvm dir from the HSA dir alone would miss it and leave+ libamd_comgr binding to the bundle's libLLVM."""+ present = {+ "/dev/kfd",+ "/opt/rocm/lib64/libhsa-runtime64.so",+ "/opt/rocm/lib/llvm/lib",+ }+ for where, impl in _impls().items():+ assert self._run(impl, bundle_dir, present) == [+ "/opt/rocm/lib64",+ "/opt/rocm/lib/llvm/lib",+ ], where++ def test_lib64_host_prefers_its_own_llvm_dir_when_both_exist(self, bundle_dir):+ present = {+ "/dev/kfd",+ "/opt/rocm/lib64/libhsa-runtime64.so",+ "/opt/rocm/lib64/llvm/lib",+ "/opt/rocm/lib/llvm/lib",+ }+ for where, impl in _impls().items():+ assert self._run(impl, bundle_dir, present) == [+ "/opt/rocm/lib64",+ "/opt/rocm/lib64/llvm/lib",+ "/opt/rocm/lib/llvm/lib",+ ], where++ def test_llvm_path_that_is_a_file_is_not_prepended(self, tmp_path, bundle_dir):+ """Real filesystem: the serve-time caller joins these straight into+ LD_LIBRARY_PATH without an is-dir filter, so a non-directory must not+ reach it."""+ root = tmp_path / "rocm"+ (root / "lib").mkdir(parents = True)+ (root / "lib" / "libhsa-runtime64.so").write_text("")+ (root / "lib" / "llvm").mkdir()+ (root / "lib" / "llvm" / "lib").write_text("not a directory")+ real_exists = os.path.exists+ # Pin both device nodes: a WSL test host really has /dev/dxg, which would+ # take the WSL early-return and make this pass for the wrong reason.+ pinned = {"/dev/kfd": True, "/dev/dxg": False}++ def _exists(p):+ return pinned.get(str(p), None) if str(p) in pinned else real_exists(p)++ # A test host may itself have a real /opt/rocm (the default candidate), so+ # assert on the bogus entry rather than on the whole list.+ for where, impl in _impls().items():+ with (+ patch.object(sys, "platform", "linux"),+ patch.dict(os.environ, {"ROCM_PATH": str(root)}, clear = True),+ patch("os.path.exists", _exists),+ ):+ out = impl(str(bundle_dir))+ assert str(root / "lib") in out, where+ assert str(root / "lib" / "llvm" / "lib") not in out, where+def test_lib_precedes_lib64_when_both_exist(self, bundle_dir):present = {"/dev/kfd",