Files
mineru-rocm/docker/scripts/patch_vllm_platform.py
T
2026-06-04 16:16:30 +08:00

57 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""vllm 平台检测补丁
问题 1:amdsmi 不可用时 platform 回退到 torch.version.hip
问题 2:rocm.py 中 logger.warning_once() 导致循环导入
"""
import os
VLLM_DIR = '/opt/vllm/vllm'
def patch6_init_platform_fallback():
"""补丁 6:platforms/__init__.py —— torch.version.hip 兜底"""
f = os.path.join(VLLM_DIR, '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\n"
" if not is_rocm:\n"
" try:\n"
" import torch\n"
" if torch.version.hip is not None:\n"
" is_rocm = True\n"
" except Exception:\n"
" pass\n"
" 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.')
def patch7_rocm_break_import_cycle():
"""补丁 7:platforms/rocm.py —— logger.warning_once → sys.stderr.write"""
f = os.path.join(VLLM_DIR, '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: rocm.py circular import broken.')
else:
print('Patch 7: already applied or pattern not found.')
def main():
patch6_init_platform_fallback()
patch7_rocm_break_import_cycle()
print('vllm platform patches done.')
if __name__ == '__main__':
main()