|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# .buildkite/run_with_pypi.sh |
| 4 | +# --------------------------- |
| 5 | + |
| 6 | +# Exit on error, exit on unset variable, fail on pipe errors. |
| 7 | +set -euo pipefail |
| 8 | + |
| 9 | +if [ "$#" -eq 0 ]; then |
| 10 | + echo "ERROR: Usage: $0 <command_and_args_to_run_with_pypi...>" |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +ENV_VARS=( |
| 15 | + -e TEST_MODEL="${TEST_MODEL:-}" |
| 16 | + -e MINIMUM_ACCURACY_THRESHOLD="${MINIMUM_ACCURACY_THRESHOLD:-}" |
| 17 | + -e MINIMUM_THROUGHPUT_THRESHOLD="${MINIMUM_THROUGHPUT_THRESHOLD:-}" |
| 18 | + -e TENSOR_PARALLEL_SIZE="${TENSOR_PARALLEL_SIZE:-}" |
| 19 | + -e INPUT_LEN="${INPUT_LEN:-}" |
| 20 | + -e OUTPUT_LEN="${OUTPUT_LEN:-}" |
| 21 | + -e PREFIX_LEN="${PREFIX_LEN:-}" |
| 22 | + -e MAX_MODEL_LEN="${MAX_MODEL_LEN:-}" |
| 23 | + -e MAX_NUM_SEQS="${MAX_NUM_SEQS:-}" |
| 24 | + -e MAX_NUM_BATCHED_TOKENS="${MAX_NUM_BATCHED_TOKENS:-}" |
| 25 | +) |
| 26 | + |
| 27 | +if ! grep -q "^HF_TOKEN=" /etc/environment; then |
| 28 | + gcloud secrets versions access latest --secret=bm-agent-hf-token --quiet | \ |
| 29 | + sudo tee -a /etc/environment > /dev/null <<< "HF_TOKEN=$(cat)" |
| 30 | + echo "Added HF_TOKEN to /etc/environment." |
| 31 | +else |
| 32 | + echo "HF_TOKEN already exists in /etc/environment." |
| 33 | +fi |
| 34 | + |
| 35 | +# shellcheck disable=1091 |
| 36 | +source /etc/environment |
| 37 | + |
| 38 | +if [ -z "${BUILDKITE_COMMIT:-}" ]; then |
| 39 | + echo "ERROR: BUILDKITE_COMMIT environment variable is not set." >&2 |
| 40 | + echo "This script expects BUILDKITE_COMMIT to tag the Docker image." >&2 |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +if [ -z "${MODEL_IMPL_TYPE:-}" ]; then |
| 45 | + MODEL_IMPL_TYPE=flax_nnx |
| 46 | +fi |
| 47 | + |
| 48 | +# Try to cache HF models |
| 49 | +persist_cache_dir="/mnt/disks/persist/models" |
| 50 | + |
| 51 | +if ( mkdir -p "$persist_cache_dir" ); then |
| 52 | + LOCAL_HF_HOME="$persist_cache_dir" |
| 53 | +else |
| 54 | + echo "Error: Failed to create $persist_cache_dir" |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | +DOCKER_HF_HOME="/tmp/hf_home" |
| 58 | + |
| 59 | +# (TODO): Consider creating a remote registry to cache and share between agents. |
| 60 | +# Subsequent builds on the same host should be cached. |
| 61 | + |
| 62 | +# Cleanup of existing containers and images. |
| 63 | +echo "Starting cleanup for vllm-tpu..." |
| 64 | +# Get all unique image IDs for the repository 'vllm-tpu' |
| 65 | +old_images=$(docker images vllm-tpu -q | uniq) |
| 66 | +total_containers="" |
| 67 | + |
| 68 | +if [ -n "$old_images" ]; then |
| 69 | + echo "Found old vllm-tpu images. Checking for dependent containers..." |
| 70 | + # Loop through each image ID and find any containers (running or not) using it. |
| 71 | + for img_id in $old_images; do |
| 72 | + total_containers="$total_containers $(docker ps -a -q --filter "ancestor=$img_id")" |
| 73 | + done |
| 74 | + |
| 75 | + # Remove any found containers |
| 76 | + if [ -n "$total_containers" ]; then |
| 77 | + echo "Removing leftover containers using vllm-tpu image(s)..." |
| 78 | + echo "$total_containers" | xargs -n1 | sort -u | xargs -r docker rm -f |
| 79 | + fi |
| 80 | + |
| 81 | + echo "Removing old vllm-tpu image(s)..." |
| 82 | + docker rmi -f "$old_images" |
| 83 | +else |
| 84 | + echo "No vllm-tpu images found to clean up." |
| 85 | +fi |
| 86 | + |
| 87 | +echo "Pruning old Docker build cache..." |
| 88 | +docker builder prune -f |
| 89 | + |
| 90 | +echo "Cleanup complete." |
| 91 | + |
| 92 | +echo "Installing Python dependencies" |
| 93 | +python3 -m pip install --progress-bar off buildkite-test-collector==0.1.9 |
| 94 | +echo "Python dependencies installed" |
| 95 | + |
| 96 | + |
| 97 | +echo "--- Displaying current disk usage (df -h) ---" |
| 98 | +df -h |
| 99 | +echo "-----------------------------------------------" |
| 100 | + |
| 101 | +IMAGE_NAME="vllm-tpu" |
| 102 | +docker build --no-cache -f docker/Dockerfile.pypi -t "${IMAGE_NAME}:${BUILDKITE_COMMIT}" . |
| 103 | + |
| 104 | +exec docker run \ |
| 105 | + --privileged \ |
| 106 | + --net host \ |
| 107 | + --shm-size=16G \ |
| 108 | + --rm \ |
| 109 | + -v "$LOCAL_HF_HOME":"$DOCKER_HF_HOME" \ |
| 110 | + "${ENV_VARS[@]}" \ |
| 111 | + -e HF_HOME="$DOCKER_HF_HOME" \ |
| 112 | + -e MODEL_IMPL_TYPE="$MODEL_IMPL_TYPE" \ |
| 113 | + -e HF_TOKEN="$HF_TOKEN" \ |
| 114 | + -e VLLM_XLA_CACHE_PATH="$DOCKER_HF_HOME/.cache/jax_cache" \ |
| 115 | + -e VLLM_XLA_CHECK_RECOMPILATION=1 \ |
| 116 | + ${QUANTIZATION:+-e QUANTIZATION="$QUANTIZATION"} \ |
| 117 | + ${NEW_MODEL_DESIGN:+-e NEW_MODEL_DESIGN="$NEW_MODEL_DESIGN"} \ |
| 118 | + ${USE_V6E8_QUEUE:+-e USE_V6E8_QUEUE="$USE_V6E8_QUEUE"} \ |
| 119 | + ${SKIP_ACCURACY_TESTS:+-e SKIP_ACCURACY_TESTS="$SKIP_ACCURACY_TESTS"} \ |
| 120 | + ${VLLM_MLA_DISABLE:+-e VLLM_MLA_DISABLE="$VLLM_MLA_DISABLE"} \ |
| 121 | + "${IMAGE_NAME}:${BUILDKITE_COMMIT}" \ |
| 122 | + "$@" # Pass all script arguments as the command to run in the container |
| 123 | +echo "docker run complete" |
0 commit comments