python: fix CalledProcessError on Intel Macs since v2.8.0 (#3045)

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-10-09 09:13:33 -04:00 committed by GitHub
parent 8e3108fe1f
commit a59ec91369
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 42 deletions

View File

@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed ### Changed
- Rebase llama.cpp on latest upstream as of September 26th ([#2998](https://github.com/nomic-ai/gpt4all/pull/2998)) - Rebase llama.cpp on latest upstream as of September 26th ([#2998](https://github.com/nomic-ai/gpt4all/pull/2998))
- Change the error message when a message is too long ([#3004](https://github.com/nomic-ai/gpt4all/pull/3004)) - Change the error message when a message is too long ([#3004](https://github.com/nomic-ai/gpt4all/pull/3004))
- Fix CalledProcessError on Intel Macs since v2.8.0 ([#3045](https://github.com/nomic-ai/gpt4all/pull/3045))
## [2.8.2] - 2024-08-14 ## [2.8.2] - 2024-08-14

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import ctypes import ctypes
import os import os
import platform import platform
import re
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
@ -28,17 +27,26 @@ if TYPE_CHECKING:
EmbeddingsType = TypeVar('EmbeddingsType', bound='list[Any]') EmbeddingsType = TypeVar('EmbeddingsType', bound='list[Any]')
cuda_found: bool = False
# TODO(jared): use operator.call after we drop python 3.10 support
def _operator_call(obj, /, *args, **kwargs):
return obj(*args, **kwargs)
# Detect Rosetta 2 # Detect Rosetta 2
if platform.system() == "Darwin" and platform.processor() == "i386": @_operator_call
if subprocess.run( def check_rosetta() -> None:
"sysctl -n sysctl.proc_translated".split(), check=True, capture_output=True, text=True, if platform.system() == "Darwin" and platform.processor() == "i386":
).stdout.strip() == "1": p = subprocess.run("sysctl -n sysctl.proc_translated".split(), capture_output=True, text=True)
if p.returncode == 0 and p.stdout.strip() == "1":
raise RuntimeError(textwrap.dedent("""\ raise RuntimeError(textwrap.dedent("""\
Running GPT4All under Rosetta is not supported due to CPU feature requirements. Running GPT4All under Rosetta is not supported due to CPU feature requirements.
Please install GPT4All in an environment that uses a native ARM64 Python interpreter. Please install GPT4All in an environment that uses a native ARM64 Python interpreter.
""").strip()) """).strip())
# Check for C++ runtime libraries # Check for C++ runtime libraries
if platform.system() == "Windows": if platform.system() == "Windows":
try: try:
@ -53,7 +61,11 @@ if platform.system() == "Windows":
"""), file=sys.stderr) """), file=sys.stderr)
def _load_cuda(rtver: str, blasver: str) -> None: @_operator_call
def find_cuda() -> None:
global cuda_found
def _load_cuda(rtver: str, blasver: str) -> None:
if platform.system() == "Linux": if platform.system() == "Linux":
cudalib = f"lib/libcudart.so.{rtver}" cudalib = f"lib/libcudart.so.{rtver}"
cublaslib = f"lib/libcublas.so.{blasver}" cublaslib = f"lib/libcublas.so.{blasver}"
@ -65,10 +77,8 @@ def _load_cuda(rtver: str, blasver: str) -> None:
ctypes.CDLL(os.path.join(cuda_runtime.__path__[0], cudalib), mode=ctypes.RTLD_GLOBAL) ctypes.CDLL(os.path.join(cuda_runtime.__path__[0], cudalib), mode=ctypes.RTLD_GLOBAL)
ctypes.CDLL(os.path.join(cublas.__path__[0], cublaslib), mode=ctypes.RTLD_GLOBAL) ctypes.CDLL(os.path.join(cublas.__path__[0], cublaslib), mode=ctypes.RTLD_GLOBAL)
# Find CUDA libraries from the official packages
# Find CUDA libraries from the official packages if platform.system() in ("Linux", "Windows"):
cuda_found = False
if platform.system() in ("Linux", "Windows"):
try: try:
from nvidia import cuda_runtime, cublas from nvidia import cuda_runtime, cublas
except ImportError: except ImportError:
@ -121,6 +131,7 @@ class LLModelPromptContext(ctypes.Structure):
("context_erase", ctypes.c_float), ("context_erase", ctypes.c_float),
] ]
class LLModelGPUDevice(ctypes.Structure): class LLModelGPUDevice(ctypes.Structure):
_fields_ = [ _fields_ = [
("backend", ctypes.c_char_p), ("backend", ctypes.c_char_p),
@ -131,6 +142,7 @@ class LLModelGPUDevice(ctypes.Structure):
("vendor", ctypes.c_char_p), ("vendor", ctypes.c_char_p),
] ]
# Define C function signatures using ctypes # Define C function signatures using ctypes
llmodel.llmodel_model_create.argtypes = [ctypes.c_char_p] llmodel.llmodel_model_create.argtypes = [ctypes.c_char_p]
llmodel.llmodel_model_create.restype = ctypes.c_void_p llmodel.llmodel_model_create.restype = ctypes.c_void_p
@ -540,7 +552,6 @@ class LLModel:
ctypes.c_char_p(), ctypes.c_char_p(),
) )
def prompt_model_streaming( def prompt_model_streaming(
self, prompt: str, prompt_template: str, callback: ResponseCallbackType = empty_response_callback, **kwargs self, prompt: str, prompt_template: str, callback: ResponseCallbackType = empty_response_callback, **kwargs
) -> Iterable[str]: ) -> Iterable[str]:

View File

@ -8,7 +8,6 @@ import os
import platform import platform
import re import re
import sys import sys
import time
import warnings import warnings
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path from pathlib import Path