This commit is contained in:
2026-06-04 16:09:06 +08:00
parent aacd84da86
commit b8999eef46
+14 -18
View File
@@ -225,12 +225,12 @@ RUN set -ex && \
# --no-build-isolation 可能漏装部分运行时依赖,显式补装
${VENV}/bin/pip install --no-cache-dir regex && \
# ---- 补丁 6:vllm 平台检测 —— torch.version.hip 回退 ----
${VENV}/bin/python -c "
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
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
@@ -238,28 +238,24 @@ new = ''' # amdsmi fallback: also check torch.version.hip
is_rocm = True
except Exception:
pass
return 'vllm.platforms.rocm.RocmPlatform' if is_rocm else None'''
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: __init__.py platform fallback applied.')
else:
print('Patch 6: already applied or pattern not found.')
" && \
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 断开循环导入 ----
${VENV}/bin/python -c "
cat > /tmp/patch7.py << 'PYEOF'
f = '/opt/vllm/vllm/platforms/rocm.py'
c = open(f).read()
# 替换 logger.warning_once( 为 sys.stderr.write(
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: rocm.py logger.warning_once → sys.stderr.write applied.')
else:
print('Patch 7: already applied or pattern not found.')
" && \
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 && \
# 验证 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 元数据