This commit is contained in:
2026-06-04 16:16:30 +08:00
parent b8999eef46
commit d784664b91
2 changed files with 59 additions and 32 deletions
+3 -32
View File
@@ -224,38 +224,8 @@ RUN set -ex && \
cd /opt/vllm && ${VENV}/bin/pip install --no-cache-dir -e . --no-build-isolation && \
# --no-build-isolation 可能漏装部分运行时依赖,显式补装
${VENV}/bin/pip install --no-cache-dir regex && \
# ---- 补丁 6:vllm 平台检测 —— torch.version.hip 回退 ----
cat > /tmp/patch6.py << 'PYEOF'
import re
f = '/opt/vllm/vllm/platforms/__init__.py'
c = open(f).read()
old = " return 'vllm.platforms.rocm.RocmPlatform' if is_rocm else None"
new = """ # amdsmi fallback: also check torch.version.hip
if not is_rocm:
try:
import torch
if torch.version.hip is not None:
is_rocm = True
except Exception:
pass
return 'vllm.platforms.rocm.RocmPlatform' if is_rocm else None"""
c2 = c.replace(old, new)
if c2 != c: open(f, 'w').write(c2); print('Patch 6 applied.')
else: print('Patch 6 already applied.')
PYEOF
${VENV}/bin/python /tmp/patch6.py && \
# ---- 补丁 7:vllm rocm.py 断开循环导入 ----
cat > /tmp/patch7.py << 'PYEOF'
f = '/opt/vllm/vllm/platforms/rocm.py'
c = open(f).read()
old = 'logger.warning_once('
new = 'import sys as _sys\n _sys.stderr.write('
c2 = c.replace(old, new)
if c2 != c: open(f, 'w').write(c2); print('Patch 7 applied.')
else: print('Patch 7 already applied.')
PYEOF
${VENV}/bin/python /tmp/patch7.py && \
rm -f /tmp/patch6.py /tmp/patch7.py && \
# 应用 vllm 平台检测补丁(独立脚本,避免 Dockerfile 解析问题)
${VENV}/bin/python /opt/patch_vllm_platform.py && \
# 验证 PyTorch 没被 vllm 依赖覆盖
${VENV}/bin/python -c "import torch; v=torch.__version__; assert 'rocm' in v, f'PyTorch overwritten by vllm deps: {v}'; print('PyTorch OK:', v)" && \
# 先重装 ROCm PyTorch 覆盖可能的 CUDA 版,再清理 CUDA triton 元数据
@@ -273,6 +243,7 @@ PYEOF
# ===========================================================================
COPY scripts/apply_mineru_patches.py /opt/apply_mineru_patches.py
COPY scripts/cache_warmer.py /opt/cache_warmer.py
COPY scripts/patch_vllm_platform.py /opt/patch_vllm_platform.py
# ===========================================================================
# 阶段 9:安装 MinerU + RDNA 适配补丁