| 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 | |
| 9 | DOCKER_BINARY=${DOCKER_BINARY:-docker} |
| 10 | DOCKER_OPTS=${DOCKER_OPTS:-} |
| 11 | LLAMA_CHECKPOINT_DIR=${LLAMA_CHECKPOINT_DIR:-} |
| 12 | |
| 13 | set -euo pipefail |
| 14 | |
| 15 | RED='\033[0;31m' |
| 16 | NC='\033[0m' # No Color |
| 17 | |
| 18 | error_handler() { |
| 19 | echo "Error occurred in script at line: ${1}" >&2 |
| 20 | exit 1 |
| 21 | } |
| 22 | |
| 23 | trap 'error_handler ${LINENO}' ERR |
| 24 | |
| 25 | if [ $# -lt 3 ]; then |
| 26 | echo "Usage: $0 <build_name> <yaml_config> <port> <other_args...>" |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | build_name="$1" |
| 31 | docker_image="llamastack-$build_name" |
| 32 | shift |
| 33 | |
| 34 | yaml_config="$1" |
| 35 | shift |
| 36 | |
| 37 | port="$1" |
| 38 | shift |
| 39 | |
| 40 | set -x |
| 41 | |
| 42 | if [ -n "$LLAMA_CHECKPOINT_DIR" ]; then |
| 43 | $DOCKER_BINARY run $DOCKER_OPTS -it \ |
| 44 | -p $port:$port \ |
| 45 | -v "$yaml_config:/app/config.yaml" \ |
| 46 | -v "$LLAMA_CHECKPOINT_DIR:/root/.llama" \ |
| 47 | --gpus=all \ |
| 48 | $docker_image \ |
| 49 | python -m llama_stack.distribution.server.server \ |
| 50 | --yaml_config /app/config.yaml \ |
| 51 | --port $port "$@" |
| 52 | fi |
| 53 | |
| 54 | if [ -z "$LLAMA_CHECKPOINT_DIR" ]; then |
| 55 | $DOCKER_BINARY run $DOCKER_OPTS -it \ |
| 56 | -p $port:$port \ |
| 57 | -v "$yaml_config:/app/config.yaml" \ |
| 58 | $docker_image \ |
| 59 | python -m llama_stack.distribution.server.server \ |
| 60 | --yaml_config /app/config.yaml \ |
| 61 | --port $port "$@" |
| 62 | fi |