Elffuss BraidHub

kikocis/llama-stack public

3fc339af16ee · 3.6 KiB · executableRawPermalink
1#!/bin/bash
2
3# Copyright (c) Meta Platforms, Inc. and affiliates.
4# All rights reserved.
5#
6# This source code is licensed under the terms described in the LICENSE file in
7# the root directory of this source tree.
8
9LLAMA_MODELS_DIR=${LLAMA_MODELS_DIR:-}
10LLAMA_STACK_DIR=${LLAMA_STACK_DIR:-}
11TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-}
12
13if [ -n "$LLAMA_STACK_DIR" ]; then
14 echo "Using llama-stack-dir=$LLAMA_STACK_DIR"
15fi
16if [ -n "$LLAMA_MODELS_DIR" ]; then
17 echo "Using llama-models-dir=$LLAMA_MODELS_DIR"
18fi
19
20set -euo pipefail
21
22if [ "$#" -ne 2 ]; then
23 echo "Usage: $0 <distribution_type> <build_name> <pip_dependencies>" >&2
24 echo "Example: $0 <distribution_type> mybuild 'numpy pandas scipy'" >&2
25 exit 1
26fi
27
28build_name="$1"
29env_name="llamastack-$build_name"
30pip_dependencies="$2"
31
32# Define color codes
33RED='\033[0;31m'
34GREEN='\033[0;32m'
35NC='\033[0m' # No Color
36
37# this is set if we actually create a new conda in which case we need to clean up
38ENVNAME=""
39
40SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
41source "$SCRIPT_DIR/common.sh"
42
43ensure_conda_env_python310() {
44 local env_name="$1"
45 local pip_dependencies="$2"
46 local python_version="3.10"
47
48 # Check if conda command is available
49 if ! command -v conda &>/dev/null; then
50 printf "${RED}Error: conda command not found. Is Conda installed and in your PATH?${NC}" >&2
51 exit 1
52 fi
53
54 # Check if the environment exists
55 if conda env list | grep -q "^${env_name} "; then
56 printf "Conda environment '${env_name}' exists. Checking Python version...\n"
57
58 # Check Python version in the environment
59 current_version=$(conda run -n "${env_name}" python --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1,2)
60
61 if [ "$current_version" = "$python_version" ]; then
62 printf "Environment '${env_name}' already has Python ${python_version}. No action needed.\n"
63 else
64 printf "Updating environment '${env_name}' to Python ${python_version}...\n"
65 conda install -n "${env_name}" python="${python_version}" -y
66 fi
67 else
68 printf "Conda environment '${env_name}' does not exist. Creating with Python ${python_version}...\n"
69 conda create -n "${env_name}" python="${python_version}" -y
70
71 ENVNAME="${env_name}"
72 # setup_cleanup_handlers
73 fi
74
75 eval "$(conda shell.bash hook)"
76 conda deactivate && conda activate "${env_name}"
77
78 if [ -n "$TEST_PYPI_VERSION" ]; then
79 # these packages are damaged in test-pypi, so install them first
80 pip install fastapi libcst
81 pip install --extra-index-url https://test.pypi.org/simple/ llama-models==$TEST_PYPI_VERSION llama-stack==$TEST_PYPI_VERSION $pip_dependencies
82 else
83 # Re-installing llama-stack in the new conda environment
84 if [ -n "$LLAMA_STACK_DIR" ]; then
85 if [ ! -d "$LLAMA_STACK_DIR" ]; then
86 printf "${RED}Warning: LLAMA_STACK_DIR is set but directory does not exist: $LLAMA_STACK_DIR${NC}\n" >&2
87 exit 1
88 fi
89
90 printf "Installing from LLAMA_STACK_DIR: $LLAMA_STACK_DIR\n"
91 pip install --no-cache-dir -e "$LLAMA_STACK_DIR"
92 else
93 pip install --no-cache-dir llama-stack
94 fi
95
96 if [ -n "$LLAMA_MODELS_DIR" ]; then
97 if [ ! -d "$LLAMA_MODELS_DIR" ]; then
98 printf "${RED}Warning: LLAMA_MODELS_DIR is set but directory does not exist: $LLAMA_MODELS_DIR${NC}\n" >&2
99 exit 1
100 fi
101
102 printf "Installing from LLAMA_MODELS_DIR: $LLAMA_MODELS_DIR\n"
103 pip uninstall -y llama-models
104 pip install --no-cache-dir -e "$LLAMA_MODELS_DIR"
105 fi
106
107 # Install pip dependencies
108 if [ -n "$pip_dependencies" ]; then
109 printf "Installing pip dependencies: $pip_dependencies\n"
110 pip install $pip_dependencies
111 fi
112 fi
113}
114
115ensure_conda_env_python310 "$env_name" "$pip_dependencies"