diff --git a/docker/scripts/entrypoint.sh b/docker/scripts/entrypoint.sh index 58a42a1..e395fe8 100644 --- a/docker/scripts/entrypoint.sh +++ b/docker/scripts/entrypoint.sh @@ -9,9 +9,15 @@ SCRIPTS_DIR=/opt/scripts echo "[entrypoint] running patches..." -# vllm 平台补丁 +# vllm 平台补丁(非致命:非 GPU 容器可能失败) if [ -f ${SCRIPTS_DIR}/patch_vllm_platform.py ]; then + set +e ${VENV}/bin/python ${SCRIPTS_DIR}/patch_vllm_platform.py + vllm_rc=$? + set -e + if [ $vllm_rc -ne 0 ]; then + echo "[entrypoint] patch_vllm_platform.py exited with $vllm_rc (non-fatal for router/gradio)" + fi fi # MinerU 推理补丁 diff --git a/docker/scripts/patch_vllm_platform.py b/docker/scripts/patch_vllm_platform.py index 788a232..a9b0c4a 100644 --- a/docker/scripts/patch_vllm_platform.py +++ b/docker/scripts/patch_vllm_platform.py @@ -85,6 +85,9 @@ def ensure_vllm_dist_info(): vLLM 平台检测会通过 importlib.metadata 查询 vllm 分发元数据/entry points。 如果只靠 PYTHONPATH 导入源码,没有 dist-info,就会出现: "The vLLM package was not found...",并可能得到 UnspecifiedPlatform。 + + 注意:仅当 rocm_platform_plugin 函数实际存在时才注册 entry_point, + 否则 vLLM 会因 AttributeError 回退到 UnspecifiedPlatform。 """ try: import vllm @@ -112,11 +115,25 @@ def ensure_vllm_dist_info(): fp.write('vllm\n') with open(os.path.join(dist_info, 'INSTALLER'), 'w') as fp: fp.write('mineru-rocm-runtime\n') - with open(os.path.join(dist_info, 'entry_points.txt'), 'w') as fp: - fp.write( + + # 仅当 rocm_platform_plugin 实际存在时才注册,避免 vLLM 加载失败 + entry_points = '' + try: + from vllm.platforms.rocm import rocm_platform_plugin # noqa: F401 + entry_points += ( '[vllm.platform_plugins]\n' 'rocm = vllm.platforms.rocm:rocm_platform_plugin\n' ) + print('rocm_platform_plugin found, registering entry point.') + except (ImportError, AttributeError, SystemExit, KeyboardInterrupt): + print('WARNING: rocm_platform_plugin not found in vllm.platforms.rocm; ' + 'skipping entry_point registration.') + except BaseException as e: + print(f'WARNING: rocm_platform_plugin check failed ({type(e).__name__}: {e}); ' + 'skipping entry_point registration.') + + with open(os.path.join(dist_info, 'entry_points.txt'), 'w') as fp: + fp.write(entry_points) with open(os.path.join(dist_info, 'RECORD'), 'w') as fp: fp.write('') print(f'vllm dist-info ensured: {dist_info}') @@ -161,17 +178,18 @@ def main(): ensure_vllm_dist_info() import vllm from vllm.platforms import current_platform - print(f'vllm runtime import OK: {vllm.__version__}, platform={type(current_platform).__name__}') - if type(current_platform).__name__ == 'UnspecifiedPlatform': - raise RuntimeError( - 'vLLM platform detection returned UnspecifiedPlatform; ' - 'ROCm backend is not usable. Check amdsmi, /dev/kfd, /dev/dri, ' + platform_name = type(current_platform).__name__ + print(f'vllm runtime import OK: {vllm.__version__}, platform={platform_name}') + if platform_name == 'UnspecifiedPlatform': + print( + 'WARNING: vLLM platform detection returned UnspecifiedPlatform. ' + 'This is expected on containers without GPU access (router/gradio). ' + 'On worker containers, check: amdsmi, /dev/kfd, /dev/dri, ' 'and vllm.platform_plugins metadata.' ) except Exception: - print('ERROR: vllm runtime import failed after platform patches:') + print('WARNING: vllm runtime import failed after platform patches (non-fatal):') traceback.print_exc() - raise print('vllm platform patches done.')