Skip to content

Commit

Permalink
feat(venv): shared env (#3195)
Browse files Browse the repository at this point in the history
* feat(venv): allow to share veenvs

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(vllm): add back flash-attn

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
  • Loading branch information
mudler authored Aug 7, 2024
1 parent 11b2ada commit 66cf38b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
40 changes: 29 additions & 11 deletions backend/python/common/libbackend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@
# source $(dirname $0)/../common/libbackend.sh
#
function init() {
# Name of the backend (directory name)
BACKEND_NAME=${PWD##*/}

# Path where all backends files are
MY_DIR=$(realpath `dirname $0`)

# Build type
BUILD_PROFILE=$(getBuildProfile)

# Environment directory
EDIR=${MY_DIR}

# Allow to specify a custom env dir for shared environments
if [ "x${ENV_DIR}" != "x" ]; then
EDIR=${ENV_DIR}
fi

# If a backend has defined a list of valid build profiles...
if [ ! -z "${LIMIT_TARGETS}" ]; then
isValidTarget=$(checkTargets ${LIMIT_TARGETS})
Expand Down Expand Up @@ -74,13 +87,14 @@ function getBuildProfile() {
# This function is idempotent, so you can call it as many times as you want and it will
# always result in an activated virtual environment
function ensureVenv() {
if [ ! -d "${MY_DIR}/venv" ]; then
uv venv ${MY_DIR}/venv
if [ ! -d "${EDIR}/venv" ]; then
uv venv ${EDIR}/venv
echo "virtualenv created"
fi

if [ "x${VIRTUAL_ENV}" != "x${MY_DIR}/venv" ]; then
source ${MY_DIR}/venv/bin/activate

# Source if we are not already in a Virtual env
if [ "x${VIRTUAL_ENV}" != "x${EDIR}/venv" ]; then
source ${EDIR}/venv/bin/activate
echo "virtualenv activated"
fi

Expand Down Expand Up @@ -113,21 +127,25 @@ function installRequirements() {

# These are the requirements files we will attempt to install, in order
declare -a requirementFiles=(
"${MY_DIR}/requirements-install.txt"
"${MY_DIR}/requirements.txt"
"${MY_DIR}/requirements-${BUILD_TYPE}.txt"
"${EDIR}/requirements-install.txt"
"${EDIR}/requirements.txt"
"${EDIR}/requirements-${BUILD_TYPE}.txt"
)

if [ "x${BUILD_TYPE}" != "x${BUILD_PROFILE}" ]; then
requirementFiles+=("${MY_DIR}/requirements-${BUILD_PROFILE}.txt")
requirementFiles+=("${EDIR}/requirements-${BUILD_PROFILE}.txt")
fi

# if BUILD_TYPE is empty, we are a CPU build, so we should try to install the CPU requirements
if [ "x${BUILD_TYPE}" == "x" ]; then
requirementFiles+=("${MY_DIR}/requirements-cpu.txt")
requirementFiles+=("${EDIR}/requirements-cpu.txt")
fi

requirementFiles+=("${MY_DIR}/requirements-after.txt")
requirementFiles+=("${EDIR}/requirements-after.txt")

if [ "x${BUILD_TYPE}" != "x${BUILD_PROFILE}" ]; then
requirementFiles+=("${EDIR}/requirements-${BUILD_PROFILE}-after.txt")
fi

for reqFile in ${requirementFiles[@]}; do
if [ -f ${reqFile} ]; then
Expand Down
1 change: 1 addition & 0 deletions backend/python/vllm/requirements-cublas11-after.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flash-attn
1 change: 1 addition & 0 deletions backend/python/vllm/requirements-cublas12-after.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flash-attn

0 comments on commit 66cf38b

Please sign in to comment.