x
This commit is contained in:
@@ -29,14 +29,14 @@ def patch6_init_platform_fallback():
|
|||||||
f = os.path.join(VLLM_DIR, 'platforms', '__init__.py')
|
f = os.path.join(VLLM_DIR, 'platforms', '__init__.py')
|
||||||
lines = open(f).read().splitlines(keepends=True)
|
lines = open(f).read().splitlines(keepends=True)
|
||||||
|
|
||||||
marker = "'vllm.platforms.rocm.RocmPlatform'"
|
# 兼容单/双引号两种写法(vllm 不同版本可能不同)
|
||||||
return_idx = None
|
return_idx = None
|
||||||
for i, ln in enumerate(lines):
|
for i, ln in enumerate(lines):
|
||||||
if marker in ln and 'return' in ln:
|
if 'RocmPlatform' in ln and 'return' in ln and 'is_rocm' in ln:
|
||||||
return_idx = i
|
return_idx = i
|
||||||
break
|
break
|
||||||
if return_idx is None:
|
if return_idx is None:
|
||||||
print('Patch 6: return statement with RocmPlatform not found; skipping.')
|
print('Patch 6: RocmPlatform return statement not found; skipping.')
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'torch.version.hip is not None' in ''.join(lines):
|
if 'torch.version.hip is not None' in ''.join(lines):
|
||||||
@@ -207,50 +207,27 @@ def ensure_vllm_installed():
|
|||||||
|
|
||||||
|
|
||||||
def install_sitecustomize_force_rocm():
|
def install_sitecustomize_force_rocm():
|
||||||
"""安装 sitecustomize.py 运行时兜底:每个 Python 进程启动时,
|
"""已弃用:sitecustomize 时机问题(current_platform 是 lazy init,
|
||||||
若 current_platform 落到 UnspecifiedPlatform 但 torch 检测到 ROCm/HIP,
|
sitecustomize 触发提前 resolve 时补丁 6 尚未应用)导致兜底无效。
|
||||||
则强制替换为 RocmPlatform 实例。
|
保留空壳仅为兼容旧调用,实际不做任何事。
|
||||||
|
平台检测统一由补丁 6(rocm_platform_plugin torch.version.hip 兜底)解决。
|
||||||
vllm main 的 is_rocm 检测依赖 amdsmi,ROCm 7.2 容器内 amdsmi 缺失,
|
|
||||||
补丁 6 的 torch.version.hip 兜底理论上已够,但子进程加载时序、
|
|
||||||
环境差异等可能导致检测仍失败。本 sitecustomize 作为最后一道兜底,
|
|
||||||
确保任何 worker 进程都能拿到 device_type='cuda' 的平台。
|
|
||||||
"""
|
"""
|
||||||
|
# 清理历史遗留的 sitecustomize 片段(幂等)
|
||||||
site_packages = sysconfig.get_paths().get('purelib')
|
site_packages = sysconfig.get_paths().get('purelib')
|
||||||
if not site_packages:
|
if site_packages:
|
||||||
print('Patch 8: cannot locate site-packages; skipping sitecustomize.')
|
sc = os.path.join(site_packages, 'sitecustomize.py')
|
||||||
return
|
marker = '# mineru-rocm: force rocm platform'
|
||||||
sc = os.path.join(site_packages, 'sitecustomize.py')
|
if os.path.exists(sc) and marker in open(sc).read():
|
||||||
|
# 重写文件,移除我们的片段
|
||||||
marker = '# mineru-rocm: force rocm platform'
|
c = open(sc).read()
|
||||||
existing = ''
|
# 片段从 marker 行开始到文件末尾
|
||||||
if os.path.exists(sc):
|
idx = c.find(marker)
|
||||||
existing = open(sc).read()
|
# 回退到 marker 前的换行
|
||||||
if marker in existing:
|
while idx > 0 and c[idx - 1] == '\n':
|
||||||
print('Patch 8: sitecustomize force-rocm already installed.')
|
idx -= 1
|
||||||
return
|
c = c[:idx].rstrip() + '\n'
|
||||||
|
open(sc, 'w').write(c)
|
||||||
snippet = (
|
print('Patch 8: removed legacy sitecustomize force-rocm snippet.')
|
||||||
f"\n{marker}\n"
|
|
||||||
"try:\n"
|
|
||||||
" import torch as _t\n"
|
|
||||||
" if getattr(_t.version, 'hip', None) is not None:\n"
|
|
||||||
" import vllm.platforms as _vp\n"
|
|
||||||
" _cp = getattr(_vp, 'current_platform', None)\n"
|
|
||||||
" if _cp is not None and type(_cp).__name__ == 'UnspecifiedPlatform':\n"
|
|
||||||
" from vllm.platforms.rocm import RocmPlatform as _RP\n"
|
|
||||||
" _rp = _RP()\n"
|
|
||||||
" # vllm main 用模块级 __setattr__ 接管 current_platform 赋值\n"
|
|
||||||
" try:\n"
|
|
||||||
" _vp.current_platform = _rp\n"
|
|
||||||
" except Exception:\n"
|
|
||||||
" _vp._current_platform = _rp\n"
|
|
||||||
"except Exception:\n"
|
|
||||||
" pass\n"
|
|
||||||
)
|
|
||||||
with open(sc, 'a') as fp:
|
|
||||||
fp.write(snippet)
|
|
||||||
print(f'Patch 8: sitecustomize force-rocm appended to {sc}.')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user