|
| 1 | +#!/bin/bash |
| 2 | +set -uxo pipefail |
| 3 | + |
| 4 | +# we will need to download test models off HF hub |
| 5 | +unset HF_HUB_OFFLINE |
| 6 | + |
| 7 | +export HTTP_PORT=8080 |
| 8 | +export GRPC_PORT=8033 |
| 9 | + |
| 10 | + |
| 11 | +function wait_for(){ |
| 12 | + trap "" ERR # we don't care about errors in this function |
| 13 | + |
| 14 | + name=$1 |
| 15 | + shift |
| 16 | + command=$@ |
| 17 | + |
| 18 | + max_retries=10 |
| 19 | + until $command ; do |
| 20 | + echo "Waiting for $name to be up (retries_left=$max_retries)..." |
| 21 | + sleep 30 |
| 22 | + max_retries=$((max_retries-1)) |
| 23 | + if [[ max_retries -le 0 ]]; then |
| 24 | + echo "Timed out waiting for $name server" >&2 |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + done |
| 28 | +} |
| 29 | + |
| 30 | +# stop the server on any errors |
| 31 | +trap 'kill -9 $server_pid && exit 1' ERR |
| 32 | + |
| 33 | +# spin up the OpenAPI server in the background |
| 34 | +python -m vllm.entrypoints.openai.api_server --port $HTTP_PORT & |
| 35 | +server_pid=$! |
| 36 | +server_url="http://localhost:$HTTP_PORT" |
| 37 | + |
| 38 | +wait_for "http server" curl --verbose --connect-timeout 1 --fail-with-body --no-progress-meter "${server_url}/health" |
| 39 | + |
| 40 | +curl -v --no-progress-meter --fail-with-body \ |
| 41 | + "${server_url}/v1/models" | python -m json.tool || \ |
| 42 | + |
| 43 | +curl -v --no-progress-meter --fail-with-body \ |
| 44 | + --header "Content-Type: application/json" \ |
| 45 | + --data '{ |
| 46 | + "prompt": "A red fedora symbolizes ", |
| 47 | + "model": "facebook/opt-125m" |
| 48 | +}' \ |
| 49 | + "${server_url}/v1/completions" | python -m json.tool |
| 50 | + |
| 51 | +echo "OpenAI API success" && kill -9 $server_pid |
| 52 | + |
| 53 | + |
| 54 | +# spin up the grpc server in the background |
| 55 | +python -m vllm_tgis_adapter --grpc-port $GRPC_PORT & |
| 56 | +server_pid=$! |
| 57 | +server_url="localhost:$GRPC_PORT" |
| 58 | + |
| 59 | +# get grpcurl |
| 60 | +curl --no-progress-meter --location --output /tmp/grpcurl.tar.gz \ |
| 61 | + https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz |
| 62 | +tar -xf /tmp/grpcurl.tar.gz --directory /tmp |
| 63 | + |
| 64 | +wait_for "grpc_server" grpc_healthcheck # healthcheck is part of vllm_tgis_adapter |
| 65 | + |
| 66 | +/tmp/grpcurl -v \ |
| 67 | + -plaintext \ |
| 68 | + -use-reflection \ |
| 69 | + -d '{ "requests": [{"text": "A red fedora symbolizes "}]}' \ |
| 70 | + "$server_url" \ |
| 71 | + fmaas.GenerationService/Generate |
| 72 | + |
| 73 | +echo "GRPC API success" && kill -9 $server_pid |
0 commit comments