fix: guard HIP_PATH and VULKAN_SDK dirs with os.path.exists before add_dll_directory - #158
Merged
JamePeng merged 1 commit intoJul 27, 2026
Conversation
os.add_dll_directory() raises FileNotFoundError [WinError 3] when the directory does not exist, so a stale HIP_PATH or VULKAN_SDK left behind by an uninstalled SDK makes "import llama_cpp" fail outright on Windows. The CUDA_PATH branch above already guards each candidate directory with os.path.exists(); this applies the same pattern to the HIP and Vulkan branches. Valid directories are still added individually, so a partially removed SDK contributes whichever of bin/lib remain instead of raising.
Owner
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows,
os.add_dll_directory()raisesFileNotFoundError: [WinError 3]when the path does not exist. Inllama_cpp/_ctypes_extensions.py, theHIP_PATHandVULKAN_SDKbranches pass their sub-directories straight toos.add_dll_directory()without checking that they exist.The result: a single stale environment variable — left behind by an SDK the user uninstalled, upgraded, or moved — makes
import llama_cppfail outright, even though the backend in question isn't used at all. A CUDA build dies because of a leftover Vulkan variable.Reported by a user running a CUDA (cu128) wheel who had a leftover
VULKAN_SDKpointing at a deleted folder:Minimal repro on any Windows box:
Because it fires during module import, the traceback points at the loader rather than the user's environment, so it tends to get reported as a broken wheel or a broken install.
Solution
Apply the pattern the
CUDA_PATHbranch directly above already uses: build each candidate path, and only callos.add_dll_directory()whenos.path.exists()is true.This also handles partially-removed SDKs gracefully — each directory is tested individually, so if only
binsurvives it still gets added instead of the whole import raising.No behaviour change for users with a valid SDK: every directory that exists today is still registered.
Notes
CUDA_PATHblock, kept stylistically consistent with it.HIP_PATHbranch has the identical issue and is fixed the same way.