feat: migrate transformers backend to uv

Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com>
This commit is contained in:
Chris Jowett 2024-05-03 16:04:03 -05:00
parent 2e951e51c9
commit f8ab0aa16a
No known key found for this signature in database
GPG Key ID: 6E4AA27F6EAB6E2B
5 changed files with 45 additions and 16 deletions

View File

@ -1,6 +1,6 @@
.PHONY: transformers
transformers: protogen
$(MAKE) -C ../common-env/transformers
bash install.sh
.PHONY: run
run: protogen
@ -23,4 +23,8 @@ protogen-clean:
$(RM) backend_pb2_grpc.py backend_pb2.py
backend_pb2_grpc.py backend_pb2.py:
python3 -m grpc_tools.protoc -I../.. --python_out=. --grpc_python_out=. backend.proto
python3 -m grpc_tools.protoc -I../.. --python_out=. --grpc_python_out=. backend.proto
.PHONY: clean
clean: protogen-clean
rm -rf venv

View File

@ -0,0 +1,25 @@
#!/bin/bash
set -ex
MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
python -m venv ${MY_DIR}/venv
source ${MY_DIR}/venv/bin/activate
uv pip install --requirement ${MY_DIR}/requirements.txt
if [ -f "requirements-${BUILD_TYPE}.txt" ]; then
uv pip install --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 --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

View File

@ -0,0 +1,4 @@
transformers>=4.38.2
grpcio==1.63.0
protobuf
torch

View File

@ -1,20 +1,17 @@
#!/bin/bash
##
## A bash script wrapper that runs the transformers server with conda
## A bash script wrapper that runs the GRPC backend
if [ -d "/opt/intel" ]; then
# Assumes we are using the Intel oneAPI container image
# https://github.com/intel/intel-extension-for-pytorch/issues/538
export XPU=1
else
export PATH=$PATH:/opt/conda/bin
# Activate conda environment
source activate transformers
fi
# get the directory where the bash script is located
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
python $DIR/transformers_server.py $@
source $MY_DIR/venv/bin/activate
python $MY_DIR/transformers_server.py $@

View File

@ -1,11 +1,10 @@
#!/bin/bash
##
## A bash script wrapper that runs the transformers server with conda
## A bash script wrapper that runs the tests
# Activate conda environment
source activate transformers
MY_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
# get the directory where the bash script is located
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $MY_DIR/venv/bin/activate
python -m unittest $DIR/test_transformers_server.py
python -m unittest $MY_DIR/test_transformers_server.py