Unverified Commit fc37187a authored by Xu Jinyang's avatar Xu Jinyang Committed by GitHub
Browse files

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


Signed-off-by: default avatarAuYang <459461160@qq.com>
parent ff365eea
...@@ -9,6 +9,7 @@ from huggingface_hub.utils import HfHubHTTPError, HFValidationError ...@@ -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: ...@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment