From 50c52d7d5f281761d979d09cba30f12c7b5b2604 Mon Sep 17 00:00:00 2001 From: chenjw28 <792430652@qq.com> Date: Wed, 10 Jun 2026 10:52:32 +0800 Subject: [PATCH] x --- docker/.env | 20 ++++++ docker/Dockerfile | 24 +++---- docker/docker-compose.yml | 134 +++++++++++++++++++++----------------- 3 files changed, 106 insertions(+), 72 deletions(-) create mode 100644 docker/.env diff --git a/docker/.env b/docker/.env new file mode 100644 index 0000000..03950b5 --- /dev/null +++ b/docker/.env @@ -0,0 +1,20 @@ +# Docker 环境变量(按需修改) +# 复制为 .env 后使用: cp env.example .env + +# ---- GPU 架构(按你的显卡修改)---- +# gfx1201 = RX 9070 / 9070 XT / 9070 GRE +# gfx1200 = RX 9060 XT / 9060 XT LP +# gfx1100 = RX 7900 XTX / XT / GRE +# gfx1101 = RX 7800 XT / 7700 XT +# gfx1030 = RX 6950 / 6900 / 6800 系列 +ARCH=gfx1201 + +# ---- 目录挂载 ---- +INPUT_DIR=./data/input +OUTPUT_DIR=./data/output +MODEL_DIR=./data/models +MIOPEN_CACHE=./data/miopen + +# ---- 模型下载源 ---- +# huggingface(默认,需科学上网)或 modelscope(国内可用) +MINERU_MODEL_SOURCE=modelscope diff --git a/docker/Dockerfile b/docker/Dockerfile index e22f80e..8641a08 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,7 +15,7 @@ ARG TORCH_INDEX=https://download.pytorch.org/whl/rocm7.2 ARG GIT_PROXY=http://127.0.0.1:8118 # -- 国内镜像 ---------------------------------------------------------------- -ARG PIP_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple +ARG PIP_INDEX=https://mirrors.aliyun.com/pypi/simple # -- 环境变量 --------------------------------------------------------------- ENV DEBIAN_FRONTEND=noninteractive \ @@ -95,10 +95,10 @@ RUN python${PYTHON_VER} -m venv ${VENV} && \ mkdir -p /root/.pip && \ echo "[global]" > /root/.pip/pip.conf && \ echo "index-url = ${PIP_INDEX}" >> /root/.pip/pip.conf && \ - ${VENV}/bin/pip install --no-cache-dir -U pip setuptools wheel && \ + ${VENV}/bin/pip install -U pip setuptools wheel && \ # PyTorch ROCm wheels 在海外 CDN,通过代理下载 export http_proxy=${GIT_PROXY} https_proxy=${GIT_PROXY} && \ - ${VENV}/bin/pip install --no-cache-dir --pre \ + ${VENV}/bin/pip install --pre \ torch==2.11.0+rocm7.2 \ torchvision \ pytorch-triton-rocm \ @@ -120,7 +120,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # =========================================================================== RUN if [ -d /opt/rocm/share/amd_smi ]; then \ cp -r /opt/rocm/share/amd_smi /opt/amd_smi && \ - cd /opt/amd_smi && ${VENV}/bin/pip install --no-cache-dir . --no-build-isolation && \ + cd /opt/amd_smi && ${VENV}/bin/pip install . --no-build-isolation && \ echo "amdsmi installed."; \ else \ echo "amdsmi source not found, skipping."; \ @@ -132,8 +132,8 @@ RUN if [ -d /opt/rocm/share/amd_smi ]; then \ COPY aiter/ /opt/aiter/ COPY flash-attention/ /opt/flash-attention/ RUN set -ex && \ - ${VENV}/bin/pip install --no-cache-dir -e /opt/aiter && \ - ${VENV}/bin/pip install --no-cache-dir --no-build-isolation -e /opt/flash-attention && \ + ${VENV}/bin/pip install -e /opt/aiter && \ + ${VENV}/bin/pip install --no-build-isolation -e /opt/flash-attention && \ ${VENV}/bin/python -c "import torch; v=torch.__version__; assert 'rocm' in v, f'PyTorch overwritten: {v}'; print('PyTorch OK:', v)" # =========================================================================== @@ -141,7 +141,7 @@ RUN set -ex && \ # =========================================================================== COPY vllm/ /opt/vllm/ RUN set -ex && \ - ${VENV}/bin/pip install --no-cache-dir -U \ + ${VENV}/bin/pip install -U \ "setuptools>=77.0.3" setuptools_scm setuptools_rust wheel && \ cd /opt/vllm && \ if [ -f csrc/mamba/mamba_ssm/selective_scan.h ]; then \ @@ -277,12 +277,12 @@ COPY scripts/cache_warmer.py /opt/cache_warmer.py # 阶段 8b:安装 vllm + 平台补丁 + 验证 # =========================================================================== RUN set -ex && \ - cd /opt/vllm && ${VENV}/bin/pip install --no-cache-dir -e . --no-build-isolation && \ - ${VENV}/bin/pip install --no-cache-dir regex && \ + cd /opt/vllm && ${VENV}/bin/pip install -e . --no-build-isolation && \ + ${VENV}/bin/pip install regex && \ ${VENV}/bin/python /opt/patch_vllm_platform.py && \ ${VENV}/bin/python -c "import torch; v=torch.__version__; assert 'rocm' in v, f'PyTorch overwritten: {v}'; print('PyTorch OK:', v)" && \ ${VENV}/bin/pip uninstall -y triton triton-rocm 2>/dev/null; \ - ${VENV}/bin/pip install --no-cache-dir --force-reinstall \ + ${VENV}/bin/pip install --force-reinstall \ torch==2.11.0+rocm7.2 torchvision pytorch-triton-rocm \ --index-url ${TORCH_INDEX} && \ ${VENV}/bin/python -c "import vllm; print('vllm import OK:', vllm.__version__)" && \ @@ -292,13 +292,13 @@ RUN set -ex && \ # 阶段 9:安装 MinerU + RDNA 适配补丁 + PyTorch 恢复 # =========================================================================== RUN set -ex && \ - ${VENV}/bin/pip install --no-cache-dir 'mineru[core]' && \ + ${VENV}/bin/pip install 'mineru[core]' && \ ${VENV}/bin/python /opt/apply_mineru_patches.py && \ # mineru[core] 会把 ROCm PyTorch 替换成 CUDA 版 + 安装 CUDA triton # 必须先卸载 CUDA triton,再装回 ROCm 版 ${VENV}/bin/pip uninstall -y triton triton-rocm 2>/dev/null; \ export http_proxy=${GIT_PROXY} https_proxy=${GIT_PROXY} && \ - ${VENV}/bin/pip install --no-cache-dir --force-reinstall \ + ${VENV}/bin/pip install --force-reinstall \ torch==2.11.0+rocm7.2 torchvision pytorch-triton-rocm \ --index-url ${TORCH_INDEX} && \ ${VENV}/bin/python -c "import triton.language; print('triton OK')" && \ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d73dd5a..39eb531 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,41 +4,7 @@ # ============================================================================= services: - # --- CLI 模式(默认)--- - mineru: - image: mineru-rocm:7.2.1 - build: - context: . - dockerfile: Dockerfile - network: host - args: - ARCH: gfx1201 - GIT_PROXY: http://127.0.0.1:8118 - profiles: ["cli"] - container_name: mineru-rocm - stdin_open: true - tty: true - ipc: host - devices: - - /dev/kfd - - /dev/dri - security_opt: - - seccomp=unconfined - group_add: - - video - environment: - - MINERU_MODEL_SOURCE=${MINERU_MODEL_SOURCE:-huggingface} - - HF_HUB_CACHE=${HF_HUB_CACHE:-/opt/models/huggingface} - - MODELSCOPE_CACHE=${MODELSCOPE_CACHE:-/opt/models/modelscope} - volumes: - - ${INPUT_DIR:-./data/input}:/data/input:ro - - ${OUTPUT_DIR:-./data/output}:/data/output - - ${MODEL_DIR:-./data/models}:/opt/models - - ${MIOPEN_CACHE:-./data/miopen}:/root/.cache/miopen - command: bash - restart: "no" - - # --- WebUI(Gradio)--- + # --- WebUI 前端 --- gradio: image: mineru-rocm:7.2.1 profiles: ["gradio"] @@ -48,13 +14,6 @@ services: ipc: host ports: - "10002:7860" - devices: - - /dev/kfd - - /dev/dri - security_opt: - - seccomp=unconfined - group_add: - - video environment: - MINERU_MODEL_SOURCE=${MINERU_MODEL_SOURCE:-huggingface} - HF_HUB_CACHE=${HF_HUB_CACHE:-/opt/models/huggingface} @@ -63,33 +22,88 @@ services: - ${INPUT_DIR:-./data/input}:/data/input:ro - ${OUTPUT_DIR:-./data/output}:/data/output - ${MODEL_DIR:-./data/models}:/opt/models - - ${MIOPEN_CACHE:-./data/miopen}:/root/.cache/miopen - command: ["mineru-gradio --server-name 0.0.0.0 --server-port 7860"] + command: + [ + "mineru-gradio", + "--server-name", "0.0.0.0", + "--server-port", "7860", + "--api-url", "http://mineru-router:8000", + ] + depends_on: + - router - # --- API 服务 --- - api: + # --- 双卡 Worker(GPU 算力,无 profile,始终可用)--- + worker0: image: mineru-rocm:7.2.1 - profiles: ["api"] - container_name: mineru-api + container_name: mineru-worker0 + stdin_open: true + tty: true + ipc: host + devices: + - /dev/kfd + - /dev/dri + security_opt: + - seccomp=unconfined + group_add: + - video + environment: + - HIP_VISIBLE_DEVICES=0 + - MINERU_MODEL_SOURCE=${MINERU_MODEL_SOURCE:-huggingface} + - HF_HUB_CACHE=${HF_HUB_CACHE:-/opt/models/huggingface} + - MODELSCOPE_CACHE=${MODELSCOPE_CACHE:-/opt/models/modelscope} + volumes: + - ${INPUT_DIR:-./data/input}:/data/input:ro + - ${OUTPUT_DIR:-./data/output}:/data/output + - ${MODEL_DIR:-./data/models}:/opt/models + - ${MIOPEN_CACHE:-./data/miopen}:/root/.cache/miopen + command: ["mineru-api", "--host", "0.0.0.0", "--port", "8001"] + + worker1: + image: mineru-rocm:7.2.1 + container_name: mineru-worker1 + stdin_open: true + tty: true + ipc: host + devices: + - /dev/kfd + - /dev/dri + security_opt: + - seccomp=unconfined + group_add: + - video + environment: + - HIP_VISIBLE_DEVICES=1 + - MINERU_MODEL_SOURCE=${MINERU_MODEL_SOURCE:-huggingface} + - HF_HUB_CACHE=${HF_HUB_CACHE:-/opt/models/huggingface} + - MODELSCOPE_CACHE=${MODELSCOPE_CACHE:-/opt/models/modelscope} + volumes: + - ${INPUT_DIR:-./data/input}:/data/input:ro + - ${OUTPUT_DIR:-./data/output}:/data/output + - ${MODEL_DIR:-./data/models}:/opt/models + - ${MIOPEN_CACHE:-./data/miopen}:/root/.cache/miopen + command: ["mineru-api", "--host", "0.0.0.0", "--port", "8002"] + + router: + image: mineru-rocm:7.2.1 + container_name: mineru-router stdin_open: true tty: true ipc: host ports: - "8000:8000" - devices: - - /dev/kfd - - /dev/dri - security_opt: - - seccomp=unconfined - group_add: - - video environment: - MINERU_MODEL_SOURCE=${MINERU_MODEL_SOURCE:-huggingface} - - HF_HUB_CACHE=${HF_HUB_CACHE:-/opt/models/huggingface} - - MODELSCOPE_CACHE=${MODELSCOPE_CACHE:-/opt/models/modelscope} volumes: - ${INPUT_DIR:-./data/input}:/data/input:ro - ${OUTPUT_DIR:-./data/output}:/data/output - - ${MODEL_DIR:-./data/models}:/opt/models - - ${MIOPEN_CACHE:-./data/miopen}:/root/.cache/miopen - command: ["mineru-api --host 0.0.0.0 --port 8000"] + command: + [ + "mineru-router", + "--api-urls", + "http://mineru-worker0:8001,http://mineru-worker1:8002", + "--host", "0.0.0.0", + "--port", "8000", + ] + depends_on: + - worker0 + - worker1