main
sh 86 lines 2.15 KB
Raw
1 #!/bin/bash
2 # This file demonstrates the KV cache event publishing
3 # We will launch a vllm instances configured to publish KV cache
4 # events and launch a simple subscriber to log those events.
5
6 set -xe
7
8 echo "🚧🚧 Warning: The usage of KV cache events is experimental and subject to change 🚧🚧"
9 sleep 1
10
11 MODEL_NAME=${HF_MODEL_NAME:-meta-llama/Meta-Llama-3.1-8B-Instruct}
12
13 # Trap the SIGINT signal (triggered by Ctrl+C)
14 trap 'cleanup' INT
15
16 # Cleanup function
17 cleanup() {
18 echo "Caught Ctrl+C, cleaning up..."
19 # Cleanup commands
20 pgrep python | xargs kill -9
21 pkill -f python
22 echo "Cleanup complete. Exiting."
23 exit 0
24 }
25
26 export VLLM_HOST_IP=$(hostname -I | awk '{print $1}')
27
28 # a function that waits vLLM server to start
29 wait_for_server() {
30 local port=$1
31 timeout 1200 bash -c "
32 until curl -s localhost:${port}/v1/completions > /dev/null; do
33 sleep 1
34 done" && return 0 || return 1
35 }
36
37 vllm serve "$MODEL_NAME" \
38 --port 8100 \
39 --max-model-len 100 \
40 --enforce-eager \
41 --gpu-memory-utilization 0.8 \
42 --trust-remote-code \
43 --kv-events-config \
44 '{"enable_kv_cache_events": true, "publisher": "zmq", "topic": "kv-events"}' &
45
46 wait_for_server 8100
47
48 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
49
50 python3 "$SCRIPT_DIR/kv_events_subscriber.py" &
51 sleep 1
52
53 # serve two example requests
54 output1=$(curl -X POST -s http://localhost:8100/v1/completions \
55 -H "Content-Type: application/json" \
56 -d '{
57 "model": "'"$MODEL_NAME"'",
58 "prompt": "Explain quantum computing in simple terms a 5-year-old could understand.",
59 "max_tokens": 80,
60 "temperature": 0
61 }')
62
63 output2=$(curl -X POST -s http://localhost:8100/v1/completions \
64 -H "Content-Type: application/json" \
65 -d '{
66 "model": "'"$MODEL_NAME"'",
67 "prompt": "Explain quantum computing in simple terms a 50-year-old could understand.",
68 "max_tokens": 80,
69 "temperature": 0
70 }')
71
72 # Cleanup commands
73 pkill -9 -u "$USER" -f python
74 pkill -9 -u "$USER" -f vllm
75
76 sleep 1
77
78 echo "Cleaned up"
79
80 # Print the outputs of the curl requests
81 echo ""
82 echo "Output of first request: $output1"
83 echo "Output of second request: $output2"
84
85 echo "🎉🎉 Successfully finished 2 test requests! 🎉🎉"
86 echo ""