[Bugfix] ModelScope is supported when downloading LORA models. (#32844)

Signed-off-by: AuYang <459461160@qq.com>
This commit is contained in:
Xu Jinyang
2026-01-22 16:33:21 +00:00
committed by GitHub
parent ff365eea94
commit fc37187a51
+21 -6
View File
@@ -9,6 +9,7 @@ from huggingface_hub.utils import HfHubHTTPError, HFValidationError
from torch import nn from torch import nn
from transformers import PretrainedConfig from transformers import PretrainedConfig
from vllm import envs
from vllm.config.lora import LoRAConfig from vllm.config.lora import LoRAConfig
from vllm.logger import init_logger from vllm.logger import init_logger
@@ -235,13 +236,27 @@ def get_adapter_absolute_path(lora_path: str) -> str:
if os.path.exists(lora_path): if os.path.exists(lora_path):
return os.path.abspath(lora_path) return os.path.abspath(lora_path)
# If the path does not exist locally, assume it's a Hugging Face repo. # If the path does not exist locally.
if envs.VLLM_USE_MODELSCOPE:
# If using ModelScope, we assume the path is a ModelScope repo.
from modelscope.hub.snapshot_download import InvalidParameter, snapshot_download
from requests import HTTPError
download_fn = lambda: snapshot_download(model_id=lora_path)
download_exceptions = (HTTPError, InvalidParameter)
error_log = "Error downloading the ModelScope model"
else:
# Otherwise, we assume the path is a Hugging Face Hub repo.
download_fn = lambda: huggingface_hub.snapshot_download(repo_id=lora_path)
download_exceptions = (HfHubHTTPError, HFValidationError)
error_log = "Error downloading the HuggingFace model"
try: try:
local_snapshot_path = huggingface_hub.snapshot_download(repo_id=lora_path) local_snapshot_path = download_fn()
except (HfHubHTTPError, HFValidationError): except download_exceptions:
# Handle errors that may occur during the download # Handle errors that may occur during the download.
# Return original path instead of throwing error here # Return original path instead of throwing error here.
logger.exception("Error downloading the HuggingFace model") logger.exception(error_log)
return lora_path return lora_path
return local_snapshot_path return local_snapshot_path