I've built the library C:\llama.cpp\build\bin\ggml.dll . Why it cannot be loaded in…
- User
I've built the library C:\llama.cpp\build\bin\ggml.dll . Why it cannot be loaded in Python using CDLL? You're running in PowerShell, so you can use
dumpbinif needed, and useGet-Commandto check what other tools we have, or suggest me to install other tools. Assistant
I will check if the file exists and look for available tools like
dumpbinto analyze the DLL.Assistant
I will verify the architecture of both the DLL and your Python environment, and check the DLL's dependencies to see if anything is missing.
Assistant
I have identified that
ggml.dlldepends on several other DLLs (ggml-cpu.dll,ggml-blas.dll,ggml-cuda.dll,ggml-base.dll). I will now check if these dependencies are present in the same directory.Assistant
The
ggml.dllfile exists, but it depends on several other DLLs (ggml-base.dll,ggml-blas.dll,ggml-cpu.dll,ggml-cuda.dll) located in the same folder. Since Python 3.8, Windows does not automatically search the DLL's directory for its dependencies.I will verify this fix by attempting to load the DLL with the directory added to the search path.
Assistant
Even with the directory added, the DLL fails to load, which suggests a missing dependency for one of the other DLLs (likely
ggml-cuda.dllneeding CUDA libraries).I will now check the dependencies of
ggml-cuda.dllto confirm if CUDA libraries are required and missing from the system path.Assistant
ggml-cuda.dllrequirescublas64_13.dll, a CUDA library. If this file isn't in your system PATH, the entire load chain fails.I will search for
cublas64_13.dllto see if it's available on your system.- User
Use
where.exerather thanwherein PowerShell Assistant
I will use
where.exeto search forcublas64_13.dlland check your environment variables for CUDA paths.Assistant
I've located
cublas64_13.dllin two places: your PyTorch installation and the CUDA toolkit directory. I'll now attempt to loadggml.dllby adding both thebuild\binand CUDA toolkit directories to the DLL search path.Assistant
It's still failing, likely because
ggml.dllor its dependencies require additional DLLs. I'll check the dependencies ofllama.dll,ggml-base.dll, andggml-blas.dllto identify any other missing files.Assistant
I've found another dependency:
ggml-blas.dllneedslibopenblas.dll. I'll usewhere.exeto see if it's on your system.Assistant
I found
libopenblas.dllinC:\openblas64\bin. Now, I'll try loadingggml.dllin Python again, making sure to include that directory, the CUDA toolkit, and thebuild\bindirectory in the DLL search path.Assistant
It worked! The
ggml.dllwouldn't load because its dependencies,cublas64_13.dll(CUDA) andlibopenblas.dll(OpenBLAS), weren't in Python's DLL search path.On Windows with Python 3.8+, you need to use
os.add_dll_directory()for each path containing a required DLL before callingctypes.CDLL().pythonimport os import ctypes # Add directories containing dependencies os.add_dll_directory(r'C:\llama.cpp\build\bin') os.add_dll_directory(r'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\x64') os.add_dll_directory(r'C:\openblas64\bin') # Now load the DLL ggml = ctypes.CDLL(r'C:\llama.cpp\build\bin\ggml.dll')