From 23e748d1c2c4811fa87cf93e0e6515d47747a768 Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Wed, 10 May 2023 15:58:27 -0400 Subject: [PATCH] clean up and jank windows wheel build --- .circleci/config.yml | 63 +++++--------------- gpt4all-bindings/python/gpt4all/gpt4all.py | 5 +- gpt4all-bindings/python/gpt4all/pyllmodel.py | 3 - gpt4all-bindings/python/setup.py | 24 ++++---- gpt4all-bindings/python/tests/__init__.py | 0 5 files changed, 30 insertions(+), 65 deletions(-) delete mode 100644 gpt4all-bindings/python/tests/__init__.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 2b2d43c6..c32206b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,46 +66,6 @@ jobs: paths: - "*.whl" - # build-linux: - # docker: - # - image: circleci/python:3.8 - # steps: - # - checkout - # - run: - # name: Install dependencies - # command: | - # sudo apt-get update - # sudo apt-get install -y cmake build-essential - # pip install setuptools wheel cmake - # - run: - # name: Install MingW - # command: sudo apt-get install -y mingw-w64 - # - run: - # name: Build C library - # command: | - # git submodule init - # git submodule update - # cd llmodel - # mkdir build - # cd build - # cmake \ - # -DCMAKE_SYSTEM_NAME=Windows \ - # -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \ - # -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ - # -DCMAKE_EXECUTABLE_SUFFIX=".exe" \ - # -DCMAKE_SHARED_LIBRARY_SUFFIX=".dll" \ - # .. - # cmake --build . --parallel - # - run: - # name: Build wheel - # command: | - # cd bindings/python/ - # python setup.py bdist_wheel --plat-name=manylinux1_x86_64 - # - persist_to_workspace: - # root: bindings/python/dist - # paths: - # - "*.whl" - build-windows: executor: name: win/default @@ -135,8 +95,15 @@ jobs: cmake --build . --parallel - run: name: Build wheel + # TODO: As part of this task, we need to move mingw64 binaries into package. + # This is terrible and needs a more robust solution eventually. command: | cd gpt4all-bindings/python + cd gpt4all + mkdir llmodel_DO_NOT_MODIFY + mkdir llmodel_DO_NOT_MODIFY/build/ + cp 'C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\*dll' 'llmodel_DO_NOT_MODIFY/build/' + cd .. python setup.py bdist_wheel --plat-name=win_amd64 - persist_to_workspace: root: gpt4all-bindings/python/dist @@ -156,10 +123,10 @@ jobs: sudo apt-get update sudo apt-get install -y cmake build-essential pip install setuptools wheel twine - # - run: - # name: Upload Python package - # command: | - # twine upload /tmp/workspace/*.whl --username __token__ --password $PYPI_CRED + - run: + name: Upload Python package + command: | + twine upload /tmp/workspace/*.whl --username __token__ --password $PYPI_CRED - store_artifacts: path: /tmp/workspace @@ -167,11 +134,11 @@ workflows: version: 2 build-deploy: jobs: - #- build-linux - #- build-macos + - build-linux + - build-macos - build-windows - store-and-upload-wheels: requires: - build-windows - # - build-linux - # - build-macos + - build-linux + - build-macos diff --git a/gpt4all-bindings/python/gpt4all/gpt4all.py b/gpt4all-bindings/python/gpt4all/gpt4all.py index 871a4b39..a569be94 100644 --- a/gpt4all-bindings/python/gpt4all/gpt4all.py +++ b/gpt4all-bindings/python/gpt4all/gpt4all.py @@ -73,7 +73,7 @@ class GPT4All(): Returns: Model file destination. """ - model_path = model_path.replace("\\", "\\\\") + model_filename = model_name if ".bin" not in model_filename: model_filename += ".bin" @@ -87,6 +87,8 @@ class GPT4All(): except: raise ValueError("Failed to create model download directory at ~/.cache/gpt4all/. \ Please specify download_dir.") + else: + model_path = model_path.replace("\\", "\\\\") if os.path.exists(model_path): model_dest = os.path.join(model_path, model_filename).replace("\\", "\\\\") @@ -178,7 +180,6 @@ class GPT4All(): full_prompt = self._build_prompt(messages, default_prompt_header=default_prompt_header, default_prompt_footer=default_prompt_footer) - if verbose: print(full_prompt) diff --git a/gpt4all-bindings/python/gpt4all/pyllmodel.py b/gpt4all-bindings/python/gpt4all/pyllmodel.py index bfba0468..49ba184e 100644 --- a/gpt4all-bindings/python/gpt4all/pyllmodel.py +++ b/gpt4all-bindings/python/gpt4all/pyllmodel.py @@ -31,9 +31,7 @@ def load_llmodel_library(): # For windows llama_dir = llama_dir.replace("\\", "\\\\") - print(llama_dir) llmodel_dir = llmodel_dir.replace("\\", "\\\\") - print(llmodel_dir) llama_lib = ctypes.CDLL(llama_dir, mode=ctypes.RTLD_GLOBAL) llmodel_lib = ctypes.CDLL(llmodel_dir) @@ -80,7 +78,6 @@ llmodel.llmodel_prompt.argtypes = [ctypes.c_void_p, RecalculateCallback, ctypes.POINTER(LLModelPromptContext)] - class LLModel: """ Base class and universal wrapper for GPT4All language models diff --git a/gpt4all-bindings/python/setup.py b/gpt4all-bindings/python/setup.py index 1c93b3c3..3d0f335b 100644 --- a/gpt4all-bindings/python/setup.py +++ b/gpt4all-bindings/python/setup.py @@ -36,19 +36,19 @@ def copy_prebuilt_C_lib(src_dir, dest_dir, dest_build_dir): os.mkdir(dest_dir) os.mkdir(dest_build_dir) - for dirpath, _, filenames in os.walk(src_dir): - for item in filenames: - # copy over header files to dest dir + for dirpath, _, filenames in os.walk(src_dir): + for item in filenames: + # copy over header files to dest dir + s = os.path.join(dirpath, item) + if item.endswith(".h"): + d = os.path.join(dest_dir, item) + shutil.copy2(s, d) + files_copied += 1 + if item.endswith(lib_ext): s = os.path.join(dirpath, item) - if item.endswith(".h"): - d = os.path.join(dest_dir, item) - shutil.copy2(s, d) - files_copied += 1 - if item.endswith(lib_ext): - s = os.path.join(dirpath, item) - d = os.path.join(dest_build_dir, item) - shutil.copy2(s, d) - files_copied += 1 + d = os.path.join(dest_build_dir, item) + shutil.copy2(s, d) + files_copied += 1 return files_copied diff --git a/gpt4all-bindings/python/tests/__init__.py b/gpt4all-bindings/python/tests/__init__.py deleted file mode 100644 index e69de29b..00000000