Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for MacOS users encountering model load errors #6227

Merged
merged 61 commits into from
Jul 13, 2024
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c3e0fcf
Merge pull request #4927 from oobabooga/dev
oobabooga Dec 15, 2023
443be39
Merge pull request #4937 from oobabooga/dev
oobabooga Dec 15, 2023
7be0983
Merge pull request #4961 from oobabooga/dev
oobabooga Dec 17, 2023
b28020a
Merge pull request #4980 from oobabooga/dev
oobabooga Dec 18, 2023
781367b
Merge pull request #4988 from oobabooga/dev
oobabooga Dec 19, 2023
71eb744
Merge pull request #5002 from oobabooga/dev
oobabooga Dec 19, 2023
5b791ca
Merge pull request #5005 from oobabooga/dev
oobabooga Dec 19, 2023
c1f78db
Merge pull request #5011 from oobabooga/dev
oobabooga Dec 20, 2023
489f4a2
Merge pull request #5012 from oobabooga/dev
oobabooga Dec 20, 2023
11288d1
Merge pull request #5022 from oobabooga/dev
oobabooga Dec 20, 2023
4b25acf
Merge pull request #5039 from oobabooga/dev
oobabooga Dec 21, 2023
af87609
Merge pull request #5073 from oobabooga/dev
oobabooga Dec 25, 2023
19d1374
Merge pull request #5078 from oobabooga/dev
oobabooga Dec 25, 2023
3fd7073
Merge pull request #5100 from oobabooga/dev
oobabooga Dec 27, 2023
3e3a66e
Merge pull request #5132 from oobabooga/dev
oobabooga Dec 31, 2023
3f28925
Merge pull request #5152 from oobabooga/dev
oobabooga Jan 2, 2024
c54d1da
Merge pull request #5163 from oobabooga/dev
oobabooga Jan 4, 2024
8ea3f31
Merge pull request #5181 from oobabooga/dev
oobabooga Jan 5, 2024
e169993
Merge pull request #5195 from oobabooga/dev
oobabooga Jan 7, 2024
ad1ff53
Merge pull request #5199 from oobabooga/dev
oobabooga Jan 7, 2024
2dc8db8
Merge pull request #5220 from oobabooga/dev
oobabooga Jan 10, 2024
61e4bfe
Merge pull request #5253 from oobabooga/dev
oobabooga Jan 14, 2024
d8c3a5b
Merge pull request #5266 from oobabooga/dev
oobabooga Jan 14, 2024
1343aa3
Merge pull request #5347 from oobabooga/dev
oobabooga Jan 22, 2024
837bd88
Merge pull request #5348 from oobabooga/dev
oobabooga Jan 22, 2024
e7a760e
Merge pull request #5379 from oobabooga/dev
oobabooga Jan 26, 2024
4f3fdf1
Merge pull request #5404 from oobabooga/dev
oobabooga Jan 30, 2024
a329db0
Merge pull request #5452 from oobabooga/dev
oobabooga Feb 6, 2024
0f134bf
Merge pull request #5453 from oobabooga/dev
oobabooga Feb 6, 2024
dc6adef
Merge pull request #5496 from oobabooga/dev
oobabooga Feb 14, 2024
771c592
Merge pull request #5502 from oobabooga/dev
oobabooga Feb 14, 2024
dd46229
Merge pull request #5530 from oobabooga/dev
oobabooga Feb 17, 2024
7838075
Merge pull request #5534 from oobabooga/dev
oobabooga Feb 17, 2024
d6bb6e7
Merge pull request #5549 from oobabooga/dev
oobabooga Feb 19, 2024
ba85271
Merge pull request #5574 from oobabooga/dev
oobabooga Feb 25, 2024
60f3d87
Merge pull request #5617 from oobabooga/dev
oobabooga Mar 3, 2024
992affe
Merge pull request #5641 from oobabooga/dev
oobabooga Mar 6, 2024
aa0da07
Merge pull request #5655 from oobabooga/dev
oobabooga Mar 7, 2024
1934cb6
Merge pull request #5680 from oobabooga/dev
oobabooga Mar 11, 2024
7cf1402
Merge pull request #5716 from oobabooga/dev
oobabooga Mar 17, 2024
1a7c027
Merge pull request #5772 from oobabooga/dev
oobabooga Mar 29, 2024
5b91dbb
Merge pull request #5810 from oobabooga/dev
oobabooga Apr 5, 2024
65099dc
Merge pull request #5822 from oobabooga/dev
oobabooga Apr 7, 2024
91a7370
Merge pull request #5823 from oobabooga/dev
oobabooga Apr 7, 2024
26d822f
Merge pull request #5848 from oobabooga/dev
oobabooga Apr 12, 2024
a4b732c
Merge pull request #5887 from oobabooga/dev
oobabooga Apr 19, 2024
ad12236
Merge pull request #5927 from oobabooga/dev
oobabooga Apr 24, 2024
81f603d
Merge pull request #5959 from oobabooga/dev
oobabooga Apr 29, 2024
8f12fb0
Merge pull request #5970 from oobabooga/dev
oobabooga May 1, 2024
9ac5287
Merge pull request #5996 from oobabooga/dev
oobabooga May 8, 2024
abe5ddc
Merge pull request #6027 from oobabooga/dev
oobabooga May 19, 2024
4820ae9
Merge pull request #6118 from oobabooga/dev
oobabooga Jun 13, 2024
6915c50
Merge pull request #6166 from oobabooga/dev
oobabooga Jun 27, 2024
2f71515
Make dependabot target the dev branch
oobabooga Jun 28, 2024
363efe5
Merge pull request #6199 from oobabooga/dev
oobabooga Jul 5, 2024
3315d00
Merge pull request #6200 from oobabooga/dev
oobabooga Jul 5, 2024
e813b32
Merge pull request #6203 from oobabooga/dev
oobabooga Jul 5, 2024
d01c68f
Merge pull request #6224 from oobabooga/dev
oobabooga Jul 11, 2024
d9476d6
Fix for MacOS users - 'already loaded' error on model load
InvectorGator Jul 12, 2024
526bda8
Alternative solution
oobabooga Jul 13, 2024
f19d201
Format
oobabooga Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 34 additions & 52 deletions modules/llama_cpp_python_hijack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import platform
from typing import Sequence

from tqdm import tqdm
Expand All @@ -13,58 +14,39 @@
def llama_cpp_lib():
global imported_module

def module_to_purpose(module_name):
if module_name == 'llama_cpp':
return 'CPU'
elif module_name == 'llama_cpp_cuda_tensorcores':
return 'tensorcores'
elif module_name == 'llama_cpp_cuda':
return 'default'

return 'unknown'

return_lib = None

if shared.args.cpu:
if imported_module and imported_module != 'llama_cpp':
raise Exception(f"The {module_to_purpose(imported_module)} version of llama-cpp-python is already loaded. Switching to the CPU version currently requires a server restart.")
try:
return_lib = importlib.import_module('llama_cpp')
imported_module = 'llama_cpp'
except:
pass

if shared.args.tensorcores and return_lib is None:
if imported_module and imported_module != 'llama_cpp_cuda_tensorcores':
raise Exception(f"The {module_to_purpose(imported_module)} version of llama-cpp-python is already loaded. Switching to the tensorcores version currently requires a server restart.")
try:
return_lib = importlib.import_module('llama_cpp_cuda_tensorcores')
imported_module = 'llama_cpp_cuda_tensorcores'
except:
pass

if return_lib is None:
if imported_module and imported_module != 'llama_cpp_cuda':
raise Exception(f"The {module_to_purpose(imported_module)} version of llama-cpp-python is already loaded. Switching to the default version currently requires a server restart.")
try:
return_lib = importlib.import_module('llama_cpp_cuda')
imported_module = 'llama_cpp_cuda'
except:
pass

if return_lib is None and not shared.args.cpu:
if imported_module and imported_module != 'llama_cpp':
raise Exception(f"The {module_to_purpose(imported_module)} version of llama-cpp-python is already loaded. Switching to the CPU version currently requires a server restart.")
try:
return_lib = importlib.import_module('llama_cpp')
imported_module = 'llama_cpp'
except:
pass

if return_lib is not None:
monkey_patch_llama_cpp_python(return_lib)

return return_lib
# Determine the platform
is_macos = platform.system() == 'Darwin'

# Define the library names based on the platform
if is_macos:
lib_names = [
(None, 'llama_cpp')
]
else:
lib_names = [
('cpu', 'llama_cpp'),
('tensorcores', 'llama_cpp_cuda_tensorcores'),
(None, 'llama_cpp_cuda'),
(None, 'llama_cpp')
]

for arg, lib_name in lib_names:
should_import = (arg is None or getattr(shared.args, arg))

if should_import:
if imported_module and imported_module != lib_name:
# Conflict detected, raise an exception
raise Exception(f"Cannot import `{lib_name}` because `{imported_module}` is already imported. Switching to a different version of llama-cpp-python currently requires a server restart.")

try:
return_lib = importlib.import_module(lib_name)
imported_module = lib_name
monkey_patch_llama_cpp_python(return_lib)
return return_lib
except ImportError:
continue

return None


def eval_with_progress(self, tokens: Sequence[int]):
Expand Down