From e3ea35454739a1c70df9d436b630e306fcab8691 Mon Sep 17 00:00:00 2001 From: Mug <> Date: Wed, 5 Apr 2023 14:23:01 +0200 Subject: [PATCH 1/5] Allow local llama library usage --- llama_cpp/llama_cpp.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llama_cpp/llama_cpp.py b/llama_cpp/llama_cpp.py index 41055bd..8105f18 100644 --- a/llama_cpp/llama_cpp.py +++ b/llama_cpp/llama_cpp.py @@ -18,9 +18,12 @@ def _load_shared_library(lib_base_name): # Construct the paths to the possible shared library names _base_path = pathlib.Path(__file__).parent.resolve() + _local_path = pathlib.Path.cwd() # Searching for the library in the current directory under the name "libllama" (default name # for llamacpp) and "llama" (default name for this repo) _lib_paths = [ + _local_path / f"./lib{lib_base_name}{lib_ext}", + _local_path / f"./{lib_base_name}{lib_ext}", _base_path / f"lib{lib_base_name}{lib_ext}", _base_path / f"{lib_base_name}{lib_ext}" ] From 76131d5bb812ad3a84b73134d8356285be4eb297 Mon Sep 17 00:00:00 2001 From: Mug <> Date: Mon, 10 Apr 2023 17:00:35 +0200 Subject: [PATCH 2/5] Use environment variable for library override --- llama_cpp/llama_cpp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llama_cpp/llama_cpp.py b/llama_cpp/llama_cpp.py index 8105f18..e937148 100644 --- a/llama_cpp/llama_cpp.py +++ b/llama_cpp/llama_cpp.py @@ -18,16 +18,16 @@ def _load_shared_library(lib_base_name): # Construct the paths to the possible shared library names _base_path = pathlib.Path(__file__).parent.resolve() - _local_path = pathlib.Path.cwd() # Searching for the library in the current directory under the name "libllama" (default name # for llamacpp) and "llama" (default name for this repo) _lib_paths = [ - _local_path / f"./lib{lib_base_name}{lib_ext}", - _local_path / f"./{lib_base_name}{lib_ext}", _base_path / f"lib{lib_base_name}{lib_ext}", _base_path / f"{lib_base_name}{lib_ext}" ] + if ("LLAMA_LIB" in os.environ): + _lib_paths = [pathlib.Path(os.environ["LLAMA_LIB"]).resolve()] + # Add the library directory to the DLL search path on Windows (if needed) if sys.platform == "win32" and sys.version_info >= (3, 8): os.add_dll_directory(str(_base_path)) From cf339c9b3c4bc3588b313a07713af3dd5c3e3724 Mon Sep 17 00:00:00 2001 From: Mug <> Date: Mon, 10 Apr 2023 17:06:58 +0200 Subject: [PATCH 3/5] Better custom library debugging --- llama_cpp/llama_cpp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/llama_cpp/llama_cpp.py b/llama_cpp/llama_cpp.py index ab18d98..de37ff9 100644 --- a/llama_cpp/llama_cpp.py +++ b/llama_cpp/llama_cpp.py @@ -26,6 +26,7 @@ def _load_shared_library(lib_base_name): ] if ("LLAMA_LIB" in os.environ): + lib_base_name = os.environ["LLAMA_LIB"] _lib_paths = [pathlib.Path(os.environ["LLAMA_LIB"]).resolve()] # Add the library directory to the DLL search path on Windows (if needed) From ee71ce8ab73edd07f4c136208d1871e512123f56 Mon Sep 17 00:00:00 2001 From: Mug <> Date: Mon, 10 Apr 2023 17:12:25 +0200 Subject: [PATCH 4/5] Make windows users happy (hopefully) --- llama_cpp/llama_cpp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llama_cpp/llama_cpp.py b/llama_cpp/llama_cpp.py index de37ff9..0c0581f 100644 --- a/llama_cpp/llama_cpp.py +++ b/llama_cpp/llama_cpp.py @@ -27,7 +27,9 @@ def _load_shared_library(lib_base_name): if ("LLAMA_LIB" in os.environ): lib_base_name = os.environ["LLAMA_LIB"] - _lib_paths = [pathlib.Path(os.environ["LLAMA_LIB"]).resolve()] + _lib = pathlib.Path(lib_base_name) + _base_path = _lib.parent.resolve() + _lib_paths = [_lib.resolve()] # Add the library directory to the DLL search path on Windows (if needed) if sys.platform == "win32" and sys.version_info >= (3, 8): From 2559e5af9b049737c9f83a96eb3218ed82281846 Mon Sep 17 00:00:00 2001 From: Mug <> Date: Mon, 10 Apr 2023 17:27:17 +0200 Subject: [PATCH 5/5] Changed the environment variable name into "LLAMA_CPP_LIB" --- llama_cpp/llama_cpp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama_cpp/llama_cpp.py b/llama_cpp/llama_cpp.py index 0c0581f..8a5869c 100644 --- a/llama_cpp/llama_cpp.py +++ b/llama_cpp/llama_cpp.py @@ -25,8 +25,8 @@ def _load_shared_library(lib_base_name): _base_path / f"{lib_base_name}{lib_ext}" ] - if ("LLAMA_LIB" in os.environ): - lib_base_name = os.environ["LLAMA_LIB"] + if ("LLAMA_CPP_LIB" in os.environ): + lib_base_name = os.environ["LLAMA_CPP_LIB"] _lib = pathlib.Path(lib_base_name) _base_path = _lib.parent.resolve() _lib_paths = [_lib.resolve()]