|
37 | 37 | } |
38 | 38 |
|
39 | 39 | # Wrapper for user installs that works without root |
| 40 | +# Wrapper for installs that works without root and inside virtualenvs |
40 | 41 | _pip_user_install() { |
41 | 42 | _ensure_user_env |
42 | | - python3 -m pip install --user -q --no-cache-dir "$@" || true |
| 43 | + # Detect if we're inside a virtualenv where --user is forbidden |
| 44 | + local in_venv |
| 45 | + in_venv=$(python3 - <<'PY' |
| 46 | +import sys |
| 47 | +print('1' if (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix or hasattr(sys, 'real_prefix')) else '0') |
| 48 | +PY |
| 49 | + ) |
| 50 | + |
| 51 | + if [ "$in_venv" = "1" ]; then |
| 52 | + # Install into a user-writable target and add to PYTHONPATH |
| 53 | + local pyver target_dir |
| 54 | + pyver=$(python3 - <<'PY' |
| 55 | +import sys |
| 56 | +print(f"{sys.version_info.major}.{sys.version_info.minor}") |
| 57 | +PY |
| 58 | + ) |
| 59 | + target_dir="$PYTHONUSERBASE/lib/python${pyver}/site-packages" |
| 60 | + mkdir -p "$target_dir" || true |
| 61 | + python3 -m pip install -q --no-cache-dir --target "$target_dir" "$@" || true |
| 62 | + case ":${PYTHONPATH:-}:" in |
| 63 | + *":$target_dir:"*) ;; |
| 64 | + *) export PYTHONPATH="$target_dir:${PYTHONPATH:-}" ;; |
| 65 | + esac |
| 66 | + else |
| 67 | + # Normal user install |
| 68 | + python3 -m pip install --user -q --no-cache-dir "$@" || true |
| 69 | + fi |
43 | 70 | } |
44 | 71 |
|
45 | 72 | # Patch flashinfer cubin_loader in a user overlay instead of system site |
@@ -186,9 +213,20 @@ run_benchmark_serving() { |
186 | 213 | fi |
187 | 214 | done |
188 | 215 |
|
189 | | - local BENCH_SERVING_DIR |
190 | | - BENCH_SERVING_DIR=$(mktemp -d /tmp/bmk-XXXXXX) |
191 | | - git clone https://github.com/kimbochen/bench_serving.git "$BENCH_SERVING_DIR" |
| 216 | + # Resolve bench_serving location with fallbacks to avoid hard network dependency |
| 217 | + local BENCH_SERVING_DIR="${BENCH_SERVING_DIR:-}" |
| 218 | + if [[ -n "$BENCH_SERVING_DIR" && -f "$BENCH_SERVING_DIR/benchmark_serving.py" ]]; then |
| 219 | + : |
| 220 | + elif [[ -f "/workspace/benchmarks/bench_serving/benchmark_serving.py" ]]; then |
| 221 | + BENCH_SERVING_DIR="/workspace/benchmarks/bench_serving" |
| 222 | + else |
| 223 | + BENCH_SERVING_DIR=$(mktemp -d /tmp/bmk-XXXXXX) |
| 224 | + if ! git clone https://github.com/kimbochen/bench_serving.git "$BENCH_SERVING_DIR" 2>/dev/null; then |
| 225 | + echo "Warning: Unable to clone bench_serving (no network/DNS). Skipping throughput benchmark." >&2 |
| 226 | + echo "Hint: Provide BENCH_SERVING_DIR or vendor benchmarks/bench_serving/ locally." >&2 |
| 227 | + return 0 |
| 228 | + fi |
| 229 | + fi |
192 | 230 |
|
193 | 231 | local extra_tokenizer_args=() |
194 | 232 | if [[ -n "$tokenizer" ]]; then |
@@ -328,7 +366,25 @@ run_lm_eval() { |
328 | 366 | esac |
329 | 367 | done |
330 | 368 |
|
331 | | - _install_lm_eval_deps |
| 369 | + # Try to import lm_eval first; if missing, attempt install once |
| 370 | + if ! python3 - <<'PY' |
| 371 | +import importlib.util, sys |
| 372 | +sys.exit(0 if importlib.util.find_spec('lm_eval') else 1) |
| 373 | +PY |
| 374 | + ; then |
| 375 | + _install_lm_eval_deps |
| 376 | + fi |
| 377 | + |
| 378 | + # If still missing after attempted install, skip gracefully |
| 379 | + if ! python3 - <<'PY' |
| 380 | +import importlib.util, sys |
| 381 | +sys.exit(0 if importlib.util.find_spec('lm_eval') else 1) |
| 382 | +PY |
| 383 | + ; then |
| 384 | + echo "lm-eval-harness not available; skipping eval step." >&2 |
| 385 | + return 0 |
| 386 | + fi |
| 387 | + |
332 | 388 | _patch_lm_eval |
333 | 389 |
|
334 | 390 | local openai_server_base="http://0.0.0.0:${port}" |
|
0 commit comments