Skip to content

Commit 8b7b59d

Browse files
committed
pip install as non-root
1 parent 5115edc commit 8b7b59d

3 files changed

Lines changed: 63 additions & 7 deletions

File tree

benchmarks/benchmark_lib.sh

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,36 @@ PY
3737
}
3838

3939
# Wrapper for user installs that works without root
40+
# Wrapper for installs that works without root and inside virtualenvs
4041
_pip_user_install() {
4142
_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
4370
}
4471

4572
# Patch flashinfer cubin_loader in a user overlay instead of system site
@@ -186,9 +213,20 @@ run_benchmark_serving() {
186213
fi
187214
done
188215

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
192230

193231
local extra_tokenizer_args=()
194232
if [[ -n "$tokenizer" ]]; then
@@ -328,7 +366,25 @@ run_lm_eval() {
328366
esac
329367
done
330368

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+
332388
_patch_lm_eval
333389

334390
local openai_server_base="http://0.0.0.0:${port}"

runners/launch_mi300x-amd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ${GROUP_ARGS} \
3232
-v $HF_HUB_CACHE_MOUNT:$HF_HUB_CACHE \
3333
-v $GITHUB_WORKSPACE:/workspace/ -w /workspace/ \
3434
-e HF_TOKEN -e HF_HUB_CACHE -e MODEL -e TP -e CONC -e MAX_MODEL_LEN -e PORT=$PORT \
35-
-e ISL -e OSL -e PYTHONPYCACHEPREFIX=/tmp/pycache/ -e RANDOM_RANGE_RATIO -e RESULT_FILENAME -e RUN_EVAL \
35+
-e ISL -e OSL -e PYTHONPYCACHEPREFIX=/tmp/pycache/ -e RANDOM_RANGE_RATIO -e RESULT_FILENAME -e RUN_EVAL -e BENCH_SERVING_DIR \
3636
-e USER=$(id -un) -e LOGNAME=$(id -un) -e USERNAME=$(id -un) \
3737
-e TORCHINDUCTOR_CACHE_DIR=/workspace/.cache/torchinductor \
3838
-e HOME=/workspace -e XDG_CACHE_HOME=/workspace/.cache -e PIP_CACHE_DIR=/workspace/.cache/pip -e PYTHONUSERBASE=/workspace/.local \

runners/launch_mi300x-cr.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ${GROUP_ARGS} \
3232
-v $HF_HUB_CACHE_MOUNT:$HF_HUB_CACHE \
3333
-v $GITHUB_WORKSPACE:/workspace/ -w /workspace/ \
3434
-e HF_TOKEN -e HF_HUB_CACHE -e MODEL -e TP -e CONC -e MAX_MODEL_LEN -e PORT=$PORT \
35-
-e ISL -e OSL -e PYTHONPYCACHEPREFIX=/tmp/pycache/ -e RANDOM_RANGE_RATIO -e RESULT_FILENAME -e RUN_EVAL \
35+
-e ISL -e OSL -e PYTHONPYCACHEPREFIX=/tmp/pycache/ -e RANDOM_RANGE_RATIO -e RESULT_FILENAME -e RUN_EVAL -e BENCH_SERVING_DIR \
3636
-e USER=$(id -un) -e LOGNAME=$(id -un) -e USERNAME=$(id -un) \
3737
-e TORCHINDUCTOR_CACHE_DIR=/workspace/.cache/torchinductor \
3838
-e HOME=/workspace -e XDG_CACHE_HOME=/workspace/.cache -e PIP_CACHE_DIR=/workspace/.cache/pip -e PYTHONUSERBASE=/workspace/.local \

0 commit comments

Comments
 (0)