Repository navigation
Expand file tree
/
Copy pathkaggle_vllm.sh
More file actions
148 lines (126 loc) · 5.8 KB
/
Copy pathkaggle_vllm.sh
File metadata and controls
148 lines (126 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
# scripts/kaggle_vllm.sh
# End-to-end vLLM serving and evaluation script for Kaggle GPU instances (T4 / P100).
# Serves Qwen2.5-7B-Instruct-AWQ with native Hermes tool calling over an OpenAI-compatible API.
set -euo pipefail
MODEL_ID="Qwen/Qwen2.5-7B-Instruct-AWQ"
HOST="0.0.0.0"
PORT="8000"
BASE_URL="http://127.0.0.1:${PORT}/v1"
API_KEY="dummy"
SERVER_LOG="vllm_server.log"
echo "================================================================================"
echo " DEVCONTEXT KAGGLE vLLM BENCHMARK RUNNER"
echo " Model: ${MODEL_ID} (4-bit AWQ)"
echo " Endpoint: ${BASE_URL}"
echo "================================================================================"
# -----------------------------------------------------------------------------
# 1. Restore previous cache from attached Kaggle dataset if available
# -----------------------------------------------------------------------------
mkdir -p .llm_cache results
if [ -d "/kaggle/input" ]; then
echo "[Step 1/7] Checking for attached cache dataset in /kaggle/input..."
CACHE_SRC=$(find /kaggle/input -type d -name ".llm_cache" 2>/dev/null | head -n 1 || true)
if [ -n "$CACHE_SRC" ]; then
echo " Found attached cache at: $CACHE_SRC"
cp -rn "$CACHE_SRC"/* .llm_cache/ 2>/dev/null || true
COUNT=$(find .llm_cache -name "*.json" | wc -l)
echo " Restored ${COUNT} cached LLM responses. Timed-out runs will resume instantly."
else
echo " No previous cache dataset attached. Starting with clean cache."
fi
fi
# -----------------------------------------------------------------------------
# 2. Environment & Dependency Setup
# -----------------------------------------------------------------------------
echo "[Step 2/7] Installing / verifying vLLM and OpenAI SDK..."
python3 -m pip install -q --upgrade pip
python3 -m pip install -q "vllm>=0.6.0" "openai>=1.0.0" "mcp>=2.0.0" "pytest>=8.0"
python3 -m pip install -q -e .
# -----------------------------------------------------------------------------
# 3. Start vLLM OpenAI-Compatible Server
# -----------------------------------------------------------------------------
echo "[Step 3/7] Launching vLLM OpenAI server in background..."
echo " Flags: --quantization awq --enable-auto-tool-choice --tool-call-parser hermes"
# Kill any lingering process on port 8000
fuser -k "${PORT}/tcp" 2>/dev/null || true
vllm serve "$MODEL_ID" \
--host "$HOST" \
--port "$PORT" \
--quantization awq \
--enable-auto-tool-choice \
--tool-call-parser hermes \
--max-model-len 8192 \
--gpu-memory-utilization 0.88 \
--trust-remote-code \
--dtype float16 \
> "$SERVER_LOG" 2>&1 &
VLLM_PID=$!
echo " Server started with PID ${VLLM_PID}. Logging to ${SERVER_LOG}."
# -----------------------------------------------------------------------------
# 4. Health Check Polling
# -----------------------------------------------------------------------------
echo "[Step 4/7] Waiting for /health check to respond (timeout 360s)..."
MAX_WAIT=360
ELAPSED=0
HEALTHY=0
while [ $ELAPSED -lt $MAX_WAIT ]; do
if ! kill -0 $VLLM_PID 2>/dev/null; then
echo "ERROR: vLLM process exited unexpectedly. Tail of ${SERVER_LOG}:"
tail -n 60 "$SERVER_LOG"
exit 1
fi
if curl -s -f "http://127.0.0.1:${PORT}/health" >/dev/null 2>&1; then
HEALTHY=1
echo " vLLM server is healthy and ready! (took ${ELAPSED}s)"
break
fi
sleep 5
ELAPSED=$((ELAPSED + 5))
echo " Waiting for model weights to load... (${ELAPSED}s / ${MAX_WAIT}s)"
done
if [ $HEALTHY -ne 1 ]; then
echo "ERROR: Timed out waiting for /health. Tail of ${SERVER_LOG}:"
tail -n 60 "$SERVER_LOG"
kill $VLLM_PID 2>/dev/null || true
exit 1
fi
# -----------------------------------------------------------------------------
# 5. Export DevContext Environment & Verify /models
# -----------------------------------------------------------------------------
echo "[Step 5/7] Configuring DevContext environment..."
export DEVCONTEXT_BASE_URL="$BASE_URL"
export DEVCONTEXT_API_KEY="$API_KEY"
export DEVCONTEXT_MODEL="$MODEL_ID"
echo "Querying endpoint models via eval.py --list-models:"
python3 eval.py --list-models
# -----------------------------------------------------------------------------
# 6. Run Benchmark Evaluations (3 runs on test split)
# -----------------------------------------------------------------------------
echo "[Step 6/7] Running strict test-split benchmark (3 runs per method)..."
for METHOD in llm_raw agent agent_verified; do
echo "================================================================================"
echo " Running Method: ${METHOD} (3 runs, test split)"
echo "================================================================================"
python3 eval.py \
--method "$METHOD" \
--runs 3 \
--split test \
--json "results/${METHOD}.json"
done
# -----------------------------------------------------------------------------
# 7. Persist Artifacts & Clean Up
# -----------------------------------------------------------------------------
echo "[Step 7/7] Persisting results and cache to /kaggle/working..."
if [ -d "/kaggle/working" ]; then
mkdir -p /kaggle/working/results /kaggle/working/.llm_cache
cp -r results/* /kaggle/working/results/ 2>/dev/null || true
cp -r .llm_cache/* /kaggle/working/.llm_cache/ 2>/dev/null || true
echo " Artifacts copied successfully. Downloadable via Kaggle Working Directory."
fi
echo "Gracefully stopping vLLM server (PID ${VLLM_PID})..."
kill "$VLLM_PID" 2>/dev/null || true
wait "$VLLM_PID" 2>/dev/null || true
echo "================================================================================"
echo " BENCHMARK COMPLETE! Results stored in results/"
echo "================================================================================"