From 70fe0c1d95ee2c8730b18a1872788c9c0b874e7e Mon Sep 17 00:00:00 2001 From: sora <2075279110@qq.com> Date: Wed, 2 Sep 2026 08:08:46 +0000 Subject: [PATCH] Build SciCode sandbox image from local wheels to avoid PyPI timeouts. Co-authored-by: Cursor --- bash/images_load/preload_k3_sandbox_images.sh | 46 ++++++++++++++++++- .../benchmarks/scicode/docker/Dockerfile | 6 ++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/bash/images_load/preload_k3_sandbox_images.sh b/bash/images_load/preload_k3_sandbox_images.sh index fe8c10f..af9de70 100755 --- a/bash/images_load/preload_k3_sandbox_images.sh +++ b/bash/images_load/preload_k3_sandbox_images.sh @@ -7,11 +7,40 @@ # 注意: # - 评测仍在 evalscope 容器里跑,沙箱是宿主机 Docker 再起的子容器 # - SciCode 首次运行还会按内容哈希打 tag,有本地层缓存就不会再拉 Hub +# - 构建时不访问 PyPI:先在宿主机用国内镜像下载 cp311 wheel,再离线 pip install set -euo pipefail PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" SCICODE_DIR="$PROJECT_ROOT/evalscope/evalscope/benchmarks/scicode/docker" +WHEEL_DIR="$SCICODE_DIR/wheels" H5_URL="https://modelscope.cn/datasets/evalscope/SciCode/resolve/master/test_data.h5" +PIP_INDEXES=( + "https://mirrors.aliyun.com/pypi/simple/" + "https://pypi.tuna.tsinghua.edu.cn/simple" +) + +download_wheels() { + mkdir -p "$WHEEL_DIR" + local index + for index in "${PIP_INDEXES[@]}"; do + echo " pip download via $index" + if python3 -m pip download \ + -d "$WHEEL_DIR" \ + -r "$SCICODE_DIR/docker_requirements.txt" \ + --python-version 3.11 \ + --implementation cp \ + --abi cp311 \ + --platform manylinux2014_x86_64 \ + --only-binary=:all: \ + -i "$index" \ + --default-timeout=120; then + return 0 + fi + echo " 该源失败,尝试下一个..." + done + echo "ERROR: 无法下载 SciCode 构建所需的 wheel" + return 1 +} echo "==> 检查基座镜像(已有则跳过 pull)" if docker image inspect python:3.11-slim >/dev/null 2>&1; then @@ -28,8 +57,21 @@ if [ ! -f "$SCICODE_DIR/test_data.h5" ]; then fi ls -lh "$SCICODE_DIR/test_data.h5" -echo "==> docker build scicode-benchmark:latest" -docker build -t scicode-benchmark:latest "$SCICODE_DIR" +echo "==> SciCode: 确保离线 wheel(避免构建时访问 files.pythonhosted.org 超时)" +need_wheels=0 +if [ ! -d "$WHEEL_DIR" ] || [ -z "$(ls -A "$WHEEL_DIR"/*.whl 2>/dev/null || true)" ]; then + need_wheels=1 +else + echo " 已有 wheel,跳过下载" + ls -lh "$WHEEL_DIR" +fi +if [ "$need_wheels" -eq 1 ]; then + download_wheels + ls -lh "$WHEEL_DIR" +fi + +echo "==> docker build scicode-benchmark:latest(离线安装 wheel)" +docker build --network=host -t scicode-benchmark:latest "$SCICODE_DIR" echo "" echo "完成。本地镜像:" diff --git a/evalscope/evalscope/benchmarks/scicode/docker/Dockerfile b/evalscope/evalscope/benchmarks/scicode/docker/Dockerfile index 2f94bc2..7168b08 100644 --- a/evalscope/evalscope/benchmarks/scicode/docker/Dockerfile +++ b/evalscope/evalscope/benchmarks/scicode/docker/Dockerfile @@ -1,9 +1,11 @@ FROM python:3.11-slim COPY docker_requirements.txt . -RUN pip install --no-cache-dir -r docker_requirements.txt +COPY wheels /wheels +RUN pip install --no-cache-dir --no-index --find-links=/wheels -r docker_requirements.txt \ + && rm -rf /wheels WORKDIR /workspace COPY process_data.py test_util.py test_data.h5 /workspace/ -ENV PYTHONPATH="/workspace:${PYTHONPATH}" +ENV PYTHONPATH="/workspace"