kikocis/llama-stack public
Changesets · Branches · Tags · Compare
| Changeset | 6527984cb4642900648fdd6b3e7829e62315c7bb3a1188dbfba84d2c9e93b0d1 |
|---|---|
| Author | Ashwin Bharambe <ashwin.bharambe@gmail.com> · 2024-09-24 14:18 -07:00 |
| Committer | Ashwin Bharambe <ashwin.bharambe@gmail.com> · 2024-09-24 14:18 -07:00 |
| Parents | 148d094ca6bd |
4 files changed
modified llama_stack/distribution/build.py +14 −3
| @@ -66,6 +66,14 @@ | ||
| 66 | 66 | if provider_spec.docker_image: |
| 67 | 67 | raise ValueError("A stack's dependencies cannot have a docker image") |
| 68 | 68 | |
| 69 | + special_deps = [] | |
| 70 | + deps = [] | |
| 71 | + for package in package_deps.pip_packages: | |
| 72 | + if "--no-deps" in package or "--index-url" in package: | |
| 73 | + special_deps.append(package) | |
| 74 | + else: | |
| 75 | + deps.append(package) | |
| 76 | + | |
| 69 | 77 | if build_config.image_type == ImageType.docker.value: |
| 70 | 78 | script = pkg_resources.resource_filename( |
| 71 | 79 | "llama_stack", "distribution/build_container.sh" |
| @@ -75,7 +83,7 @@ | ||
| 75 | 83 | build_config.name, |
| 76 | 84 | package_deps.docker_image, |
| 77 | 85 | str(build_file_path), |
| 78 | - " ".join(package_deps.pip_packages), | |
| 86 | + " ".join(deps), | |
| 79 | 87 | ] |
| 80 | 88 | else: |
| 81 | 89 | script = pkg_resources.resource_filename( |
| @@ -84,14 +92,17 @@ | ||
| 84 | 92 | args = [ |
| 85 | 93 | script, |
| 86 | 94 | build_config.name, |
| 87 | - " ".join(package_deps.pip_packages), | |
| 95 | + " ".join(deps), | |
| 88 | 96 | ] |
| 89 | 97 | |
| 98 | + if special_deps: | |
| 99 | + args.append("#".join(special_deps)) | |
| 100 | + | |
| 90 | 101 | return_code = run_with_pty(args) |
| 91 | 102 | if return_code != 0: |
| 92 | 103 | cprint( |
| 93 | 104 | f"Failed to build target {build_config.name} with return code {return_code}", |
| 94 | 105 | color="red", |
| 95 | 106 | ) |
| 96 | - | |
| 107 | + | |
| 97 | 108 | return return_code |
modified llama_stack/distribution/build_conda_env.sh +22 −9
| @@ -17,14 +17,16 @@ | ||
| 17 | 17 | echo "Using llama-models-dir=$LLAMA_MODELS_DIR" |
| 18 | 18 | fi |
| 19 | 19 | |
| 20 | -set -euo pipefail | |
| 21 | - | |
| 22 | -if [ "$#" -ne 2 ]; then | |
| 23 | - echo "Usage: $0 <distribution_type> <build_name> <pip_dependencies>" >&2 | |
| 20 | +if [ "$#" -lt 2 ]; then | |
| 21 | + echo "Usage: $0 <distribution_type> <build_name> <pip_dependencies> [<special_pip_deps>]" >&2 | |
| 24 | 22 | echo "Example: $0 <distribution_type> mybuild 'numpy pandas scipy'" >&2 |
| 25 | 23 | exit 1 |
| 26 | 24 | fi |
| 27 | 25 | |
| 26 | +special_pip_deps="$3" | |
| 27 | + | |
| 28 | +set -euo pipefail | |
| 29 | + | |
| 28 | 30 | build_name="$1" |
| 29 | 31 | env_name="llamastack-$build_name" |
| 30 | 32 | pip_dependencies="$2" |
| @@ -43,6 +45,7 @@ | ||
| 43 | 45 | ensure_conda_env_python310() { |
| 44 | 46 | local env_name="$1" |
| 45 | 47 | local pip_dependencies="$2" |
| 48 | + local special_pip_deps="$3" | |
| 46 | 49 | local python_version="3.10" |
| 47 | 50 | |
| 48 | 51 | # Check if conda command is available |
| @@ -78,7 +81,12 @@ | ||
| 78 | 81 | if [ -n "$TEST_PYPI_VERSION" ]; then |
| 79 | 82 | # these packages are damaged in test-pypi, so install them first |
| 80 | 83 | $CONDA_PREFIX/bin/pip install fastapi libcst |
| 81 | - $CONDA_PREFIX/bin/pip install --extra-index-url https://test.pypi.org/simple/ llama-models==$TEST_PYPI_VERSION llama-stack==$TEST_PYPI_VERSION $pip_dependencies | |
| 84 | + $CONDA_PREFIX/bin/pip install --extra-index-url https://test.pypi.org/simple/ \ | |
| 85 | + llama-models==$TEST_PYPI_VERSION llama-stack==$TEST_PYPI_VERSION \ | |
| 86 | + $pip_dependencies | |
| 87 | + if [ -n "$special_pip_deps" ]; then | |
| 88 | + $CONDA_PREFIX/bin/pip install --no-deps "$special_pip_deps" | |
| 89 | + fi | |
| 82 | 90 | else |
| 83 | 91 | # Re-installing llama-stack in the new conda environment |
| 84 | 92 | if [ -n "$LLAMA_STACK_DIR" ]; then |
| @@ -105,11 +113,16 @@ | ||
| 105 | 113 | fi |
| 106 | 114 | |
| 107 | 115 | # Install pip dependencies |
| 108 | - if [ -n "$pip_dependencies" ]; then | |
| 109 | - printf "Installing pip dependencies: $pip_dependencies\n" | |
| 110 | - $CONDA_PREFIX/bin/pip install $pip_dependencies | |
| 116 | + printf "Installing pip dependencies\n" | |
| 117 | + $CONDA_PREFIX/bin/pip install $pip_dependencies | |
| 118 | + if [ -n "$special_pip_deps" ]; then | |
| 119 | + IFS='#' read -ra parts <<< "$special_pip_deps" | |
| 120 | + for part in "${parts[@]}"; do | |
| 121 | + echo "$part" | |
| 122 | + $CONDA_PREFIX/bin/pip install $part | |
| 123 | + done | |
| 111 | 124 | fi |
| 112 | 125 | fi |
| 113 | 126 | } |
| 114 | 127 | |
| 115 | -ensure_conda_env_python310 "$env_name" "$pip_dependencies" | |
| 128 | +ensure_conda_env_python310 "$env_name" "$pip_dependencies" "$special_pip_deps" |
modified llama_stack/distribution/build_container.sh +14 −5
| @@ -4,12 +4,16 @@ | ||
| 4 | 4 | LLAMA_STACK_DIR=${LLAMA_STACK_DIR:-} |
| 5 | 5 | TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-} |
| 6 | 6 | |
| 7 | -if [ "$#" -ne 4 ]; then | |
| 8 | - echo "Usage: $0 <build_name> <docker_base> <pip_dependencies> | |
| 9 | - echo "Example: $0 my-fastapi-app python:3.9-slim 'fastapi uvicorn' | |
| 7 | +if [ "$#" -lt 4 ]; then | |
| 8 | + echo "Usage: $0 <build_name> <docker_base> <pip_dependencies> [<special_pip_deps>]" >&2 | |
| 9 | + echo "Example: $0 my-fastapi-app python:3.9-slim 'fastapi uvicorn' " >&2 | |
| 10 | 10 | exit 1 |
| 11 | 11 | fi |
| 12 | 12 | |
| 13 | +special_pip_deps="$5" | |
| 14 | + | |
| 15 | +set -euo pipefail | |
| 16 | + | |
| 13 | 17 | build_name="$1" |
| 14 | 18 | image_name="llamastack-$build_name" |
| 15 | 19 | docker_base=$2 |
| @@ -21,8 +25,6 @@ | ||
| 21 | 25 | GREEN='\033[0;32m' |
| 22 | 26 | NC='\033[0m' # No Color |
| 23 | 27 | |
| 24 | -set -euo pipefail | |
| 25 | - | |
| 26 | 28 | SCRIPT_DIR=$(dirname "$(readlink -f "$0")") |
| 27 | 29 | REPO_DIR=$(dirname $(dirname "$SCRIPT_DIR")) |
| 28 | 30 | DOCKER_BINARY=${DOCKER_BINARY:-docker} |
| @@ -85,6 +87,13 @@ | ||
| 85 | 87 | add_to_docker "RUN pip install $pip_dependencies" |
| 86 | 88 | fi |
| 87 | 89 | |
| 90 | +if [ -n "$special_pip_deps" ]; then | |
| 91 | + IFS='#' read -ra parts <<< "$special_pip_deps" | |
| 92 | + for part in "${parts[@]}"; do | |
| 93 | + add_to_docker "RUN pip install $part" | |
| 94 | + done | |
| 95 | +fi | |
| 96 | + | |
| 88 | 97 | add_to_docker <<EOF |
| 89 | 98 | |
| 90 | 99 | # This would be good in production but for debugging flexibility lets not add it right now |
modified llama_stack/providers/registry/memory.py +15 −1
| @@ -8,11 +8,25 @@ | ||
| 8 | 8 | |
| 9 | 9 | from llama_stack.distribution.datatypes import * # noqa: F403 |
| 10 | 10 | |
| 11 | + | |
| 11 | 12 | EMBEDDING_DEPS = [ |
| 12 | 13 | "blobfile", |
| 13 | 14 | "chardet", |
| 14 | 15 | "pypdf", |
| 15 | - "sentence-transformers", | |
| 16 | + "tqdm", | |
| 17 | + "numpy", | |
| 18 | + "scikit-learn", | |
| 19 | + "scipy", | |
| 20 | + "nltk", | |
| 21 | + "sentencepiece", | |
| 22 | + "transformers", | |
| 23 | + # this happens to work because special dependencies are always installed last | |
| 24 | + # so if there was a regular torch installed first, this would be ignored | |
| 25 | + # we need a better way to do this to identify potential conflicts, etc. | |
| 26 | + # for now, this lets us significantly reduce the size of the container which | |
| 27 | + # does not have any "local" inference code (and hence does not need GPU-enabled torch) | |
| 28 | + "torch --index-url https://download.pytorch.org/whl/cpu", | |
| 29 | + "sentence-transformers --no-deps", | |
| 16 | 30 | ] |
| 17 | 31 | |
| 18 | 32 |