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

feat: create bash library to handle install/run/test of python backends #2286

Merged
merged 5 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/python/autogptq/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ backend_pb2_grpc.py backend_pb2.py:

.PHONY: clean
clean: protogen-clean
rm -rf venv
rm -rf venv __pycache__
93 changes: 0 additions & 93 deletions backend/python/autogptq/autogptq.yml

This file was deleted.

File renamed without changes.
34 changes: 3 additions & 31 deletions backend/python/autogptq/install.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
#!/bin/bash
set -ex
set -e

BUILD_ISOLATION_FLAG=""
source $(dirname $0)/../common/libbackend.sh

MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"

uv venv ${MY_DIR}/venv
source ${MY_DIR}/venv/bin/activate

if [ -f "requirements-install.txt" ]; then
# If we have a requirements-install.txt, it means that a package does not properly declare it's build time
# dependencies per PEP-517, so we have to set up the proper build environment ourselves, and then install
# the package without build isolation
BUILD_ISOLATION_FLAG="--no-build-isolation"
uv pip install --requirement ${MY_DIR}/requirements-install.txt
fi
uv pip install ${BUILD_ISOLATION_FLAG} --requirement ${MY_DIR}/requirements.txt

if [ -f "requirements-${BUILD_TYPE}.txt" ]; then
uv pip install ${BUILD_ISOLATION_FLAG} --requirement ${MY_DIR}/requirements-${BUILD_TYPE}.txt
fi

if [ -d "/opt/intel" ]; then
# Intel GPU: If the directory exists, we assume we are using the Intel image
# https://github.com/intel/intel-extension-for-pytorch/issues/538
if [ -f "requirements-intel.txt" ]; then
uv pip install ${BUILD_ISOLATION_FLAG} --index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ --requirement ${MY_DIR}/requirements-intel.txt
fi
fi

if [ "$PIP_CACHE_PURGE" = true ] ; then
pip cache purge
fi
installRequirements
10 changes: 2 additions & 8 deletions backend/python/autogptq/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#!/bin/bash
source $(dirname $0)/../common/libbackend.sh

##
## A bash script wrapper that runs the autogptq server

MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"

source $MY_DIR/venv/bin/activate

python $MY_DIR/autogptq.py $@
startBackend $@
16 changes: 3 additions & 13 deletions backend/python/autogptq/test.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash
##
## A bash script wrapper that runs python unittests
set -e

MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
source $(dirname $0)/../common/libbackend.sh

source $MY_DIR/venv/bin/activate

if [ -f "${MY_DIR}/test.py" ]; then
pushd ${MY_DIR}
python -m unittest test.py
popd
else
echo "ERROR: No tests defined for backend!"
exit 1
fi
runUnittests
2 changes: 1 addition & 1 deletion backend/python/bark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ backend_pb2_grpc.py backend_pb2.py:

.PHONY: clean
clean: protogen-clean
rm -rf venv
rm -rf venv __pycache__
File renamed without changes.
34 changes: 3 additions & 31 deletions backend/python/bark/install.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
#!/bin/bash
set -ex
set -e

BUILD_ISOLATION_FLAG=""
source $(dirname $0)/../common/libbackend.sh

MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"

uv venv ${MY_DIR}/venv
source ${MY_DIR}/venv/bin/activate

if [ -f "requirements-install.txt" ]; then
# If we have a requirements-install.txt, it means that a package does not properly declare it's build time
# dependencies per PEP-517, so we have to set up the proper build environment ourselves, and then install
# the package without build isolation
BUILD_ISOLATION_FLAG="--no-build-isolation"
uv pip install --requirement ${MY_DIR}/requirements-install.txt
fi
uv pip install ${BUILD_ISOLATION_FLAG} --requirement ${MY_DIR}/requirements.txt

if [ -f "requirements-${BUILD_TYPE}.txt" ]; then
uv pip install ${BUILD_ISOLATION_FLAG} --requirement ${MY_DIR}/requirements-${BUILD_TYPE}.txt
fi

if [ -d "/opt/intel" ]; then
# Intel GPU: If the directory exists, we assume we are using the Intel image
# https://github.com/intel/intel-extension-for-pytorch/issues/538
if [ -f "requirements-intel.txt" ]; then
uv pip install ${BUILD_ISOLATION_FLAG} --index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ --requirement ${MY_DIR}/requirements-intel.txt
fi
fi

if [ "$PIP_CACHE_PURGE" = true ] ; then
pip cache purge
fi
installRequirements
10 changes: 2 additions & 8 deletions backend/python/bark/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#!/bin/bash
source $(dirname $0)/../common/libbackend.sh

##
## A bash script wrapper that runs the ttsbark server

MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"

source $MY_DIR/venv/bin/activate

python $MY_DIR/ttsbark.py $@
startBackend $@
2 changes: 1 addition & 1 deletion backend/python/bark/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
"""
This method sets up the gRPC service by starting the server
"""
self.service = subprocess.Popen(["python3", "ttsbark.py", "--addr", "localhost:50051"])
self.service = subprocess.Popen(["python3", "backend.py", "--addr", "localhost:50051"])
time.sleep(10)

def tearDown(self) -> None:
Expand Down
16 changes: 3 additions & 13 deletions backend/python/bark/test.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash
##
## A bash script wrapper that runs python unittests
set -e

MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
source $(dirname $0)/../common/libbackend.sh

source $MY_DIR/venv/bin/activate

if [ -f "${MY_DIR}/test.py" ]; then
pushd ${MY_DIR}
python -m unittest test.py
popd
else
echo "ERROR: No tests defined for backend!"
exit 1
fi
runUnittests
21 changes: 0 additions & 21 deletions backend/python/common-env/transformers/Makefile

This file was deleted.

44 changes: 0 additions & 44 deletions backend/python/common-env/transformers/install.sh

This file was deleted.