[Bugfix] ModelScope is supported when downloading LORA models. (#32844)
Signed-off-by: AuYang <459461160@qq.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from huggingface_hub.utils import HfHubHTTPError, HFValidationError
|
||||
from torch import nn
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
from vllm import envs
|
||||
from vllm.config.lora import LoRAConfig
|
||||
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):
|
||||
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:
|
||||
local_snapshot_path = huggingface_hub.snapshot_download(repo_id=lora_path)
|
||||
except (HfHubHTTPError, HFValidationError):
|
||||
# Handle errors that may occur during the download
|
||||
# Return original path instead of throwing error here
|
||||
logger.exception("Error downloading the HuggingFace model")
|
||||
local_snapshot_path = download_fn()
|
||||
except download_exceptions:
|
||||
# Handle errors that may occur during the download.
|
||||
# Return original path instead of throwing error here.
|
||||
logger.exception(error_log)
|
||||
return lora_path
|
||||
|
||||
return local_snapshot_path
|
||||
|
||||
Reference in New Issue
Block a user