Skip to content

Commit a47de06

Browse files
committed
Force only 1 llama-cpp-python version at a time for now
1 parent f243b4c commit a47de06

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: modules/llama_cpp_python_hijack.py

+17
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,47 @@
77
from modules.cache_utils import process_llamacpp_cache
88

99

10+
imported_module = None
11+
12+
1013
def llama_cpp_lib():
14+
global imported_module
15+
1116
return_lib = None
1217

1318
if shared.args.cpu:
19+
if imported_module and imported_module != 'llama_cpp':
20+
raise Exception(f"Cannot import 'llama_cpp' because '{imported_module}' is already imported. See issue #1575 in llama-cpp-python. Please restart the server before attempting to use a different version of llama-cpp-python.")
1421
try:
1522
return_lib = importlib.import_module('llama_cpp')
23+
imported_module = 'llama_cpp'
1624
except:
1725
pass
1826

1927
if shared.args.tensorcores and return_lib is None:
28+
if imported_module and imported_module != 'llama_cpp_cuda_tensorcores':
29+
raise Exception(f"Cannot import 'llama_cpp_cuda_tensorcores' because '{imported_module}' is already imported. See issue #1575 in llama-cpp-python. Please restart the server before attempting to use a different version of llama-cpp-python.")
2030
try:
2131
return_lib = importlib.import_module('llama_cpp_cuda_tensorcores')
32+
imported_module = 'llama_cpp_cuda_tensorcores'
2233
except:
2334
pass
2435

2536
if return_lib is None:
37+
if imported_module and imported_module != 'llama_cpp_cuda':
38+
raise Exception(f"Cannot import 'llama_cpp_cuda' because '{imported_module}' is already imported. See issue #1575 in llama-cpp-python. Please restart the server before attempting to use a different version of llama-cpp-python.")
2639
try:
2740
return_lib = importlib.import_module('llama_cpp_cuda')
41+
imported_module = 'llama_cpp_cuda'
2842
except:
2943
pass
3044

3145
if return_lib is None and not shared.args.cpu:
46+
if imported_module and imported_module != 'llama_cpp':
47+
raise Exception(f"Cannot import 'llama_cpp' because '{imported_module}' is already imported. See issue #1575 in llama-cpp-python. Please restart the server before attempting to use a different version of llama-cpp-python.")
3248
try:
3349
return_lib = importlib.import_module('llama_cpp')
50+
imported_module = 'llama_cpp'
3451
except:
3552
pass
3653

0 commit comments

Comments
 (0)