Skip to content

Commit

Permalink
Update Mac (M1/M2) one click installers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathanraj-Sharma committed Mar 6, 2024
1 parent dadcb9a commit a3cb88a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
25 changes: 22 additions & 3 deletions dev_installers/mac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@ This document provide the details to build one click installers for MacOS. To ma

- Clone `h2ogpt` from https://github.com/h2oai/h2ogpt.git
- Create conda environment and installer all required dependencies, consult [build_mac_installer.sh](build_mac_installer.sh) for more details.
- Run below commands to build the installer
- Run below commands to build the spec file for installer, replace the `--name` appropriately depending on whether building for CPU only or with MPS (GPU) support
```shell
cd h2ogpt
pyinstaller ./dev_installers/mac/mac_run_app.py -D -w --name=h2ogpt-osx-m1-cpu-debug --hiddenimport=h2ogpt --collect-all=h2ogpt --noconfirm --recursive-copy-metadata=transformers --collect-data=langchain --collect-data=gradio_client --collect-all=gradio --path=${CONDA_PREFIX}/python3.10/site-packages --collect-all=sentencepiece --add-data=./Tesseract-OCR:Tesseract-OCR --add-data=./poppler:poppler
pyi-makespec mac_run_app.py -F --name=h2ogpt-osx-m1-cpu \
--hidden-import=h2ogpt \
--collect-all=h2ogpt \
--recursive-copy-metadata=transformers \
--collect-data=langchain \
--collect-data=gradio_client \
--collect-all=gradio \
--collect-all=sentencepiece \
--collect-all=gradio_pdf \
--collect-all=llama_cpp \
--collect-all=tiktoken_ext \
--add-data=../../Tesseract-OCR:Tesseract-OCR \
--add-data=../../poppler:poppler
```

- Edit the `h2ogpt-osx-m1-cpu.spec` and/or `h2ogpt-osx-m1-gpu.spec` and add below code block to `Analysis()`, to explicitly tell PyInstaller to collect all `.py` modules from listed dependencies.
```
module_collection_mode={
'gradio' : 'py',
'gradio_pdf' : 'py',
},
```
- Run `pyinstaller h2ogpt-osx-m1-cpu.spec` to build the installer.
### Deployment Mode

- Clone `h2ogpt` from https://github.com/h2oai/h2ogpt.git
Expand Down
24 changes: 14 additions & 10 deletions dev_installers/mac/build_mac_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ then
echo "conda could not be found, need conda to continue!"
exit 1
fi
conda env remove -n h2ogpt-mac2
conda create -n h2ogpt-mac2 python=3.10 rust -y
conda activate h2ogpt-mac2

# Remove old Tesseract and poppler deps
rm -rf ./Tesseract-OCR poppler

conda env remove -n h2ogpt-mac
conda create -n h2ogpt-mac python=3.10 rust -y
conda activate h2ogpt-mac

pip install --upgrade pip
python -m pip install --upgrade setuptools
Expand All @@ -27,21 +31,21 @@ pip install -r reqs_optional/requirements_optional_doctr.txt -c reqs_optional/re
# Optional: for supporting unstructured package
python -m nltk.downloader all

# Required for CPU: LLaMa/GPT4All:
# For MPS support
if [ -z "$BUILD_MPS" ]
then
echo "BUILD_MPS is not set, skipping MPS specific configs..."
pip uninstall llama-cpp-python -y
CMAKE_ARGS="-DLLAMA_METAL=off" FORCE_CMAKE=1 pip install -r reqs_optional/requirements_optional_llamacpp_gpt4all.txt -c reqs_optional/reqs_constraints.txt --no-cache-dir
else
if [ "$BUILD_MPS" = "1" ]
then
echo "BUILD_MPS is set to 1, running MPS specific configs..."
pip uninstall llama-cpp-python -y
export CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1
CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1 pip install -r reqs_optional/requirements_optional_llamacpp_gpt4all.txt -c reqs_optional/reqs_constraints.txt --no-cache-dir
fi
fi

# Required for CPU: LLaMa/GPT4All:
pip install -r reqs_optional/requirements_optional_gpt4all.txt -c reqs_optional/reqs_constraints.txt --no-cache-dir
pip install librosa -c reqs_optional/reqs_constraints.txt

# Install PyInstaller
Expand All @@ -58,7 +62,7 @@ make clean dist
pip install ./dist/h2ogpt*.whl

# Build Mac Installer
# below command is used to build current .spec file replace it whenever use new configs
# below command is used to build current .spec file from project root, replace it whenever use new configs
#pyi-makespec mac_run_app.py -F --name=h2ogpt-osx-m1-cpu \
# --hidden-import=h2ogpt \
# --collect-all=h2ogpt \
Expand All @@ -70,8 +74,8 @@ pip install ./dist/h2ogpt*.whl
# --collect-all=gradio_pdf \
# --collect-all=llama_cpp \
# --collect-all=tiktoken_ext \
# --add-data=./Tesseract-OCR:Tesseract-OCR \
# --add-data=./poppler:poppler
# --add-data=../../Tesseract-OCR:Tesseract-OCR \
# --add-data=../../poppler:poppler

# add below argument to Analysis() call in h2ogpt-osx-m1-cpu.spec file
#module_collection_mode={
Expand Down
12 changes: 11 additions & 1 deletion dev_installers/mac/h2ogpt-osx-m1-gpu.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ tmp_ret = collect_all('gradio')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('sentencepiece')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('gradio_pdf')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('llama_cpp')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('tiktoken_ext')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]


a = Analysis(
['./mac_run_app.py'],
['mac_run_app.py'],
pathex=[],
binaries=binaries,
datas=datas,
Expand All @@ -28,6 +34,10 @@ a = Analysis(
runtime_hooks=[],
excludes=[],
noarchive=False,
module_collection_mode={
'gradio' : 'py',
'gradio_pdf' : 'py',
},
)
pyz = PYZ(a.pure)

Expand Down

0 comments on commit a3cb88a

Please sign in to comment.