From 5303c2bafdd445ed73c6a6c22cb5ddef67beb2e3 Mon Sep 17 00:00:00 2001 From: wangxingjun778 Date: Sat, 11 Jan 2025 03:08:38 +0800 Subject: [PATCH] remove modelscope dependency and add import check --- llms/mlx_lm/requirements.txt | 1 - llms/mlx_lm/utils.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/llms/mlx_lm/requirements.txt b/llms/mlx_lm/requirements.txt index 049bdcc9..72e1ef89 100644 --- a/llms/mlx_lm/requirements.txt +++ b/llms/mlx_lm/requirements.txt @@ -4,4 +4,3 @@ transformers[sentencepiece]>=4.39.3 protobuf pyyaml jinja2 -modelscope diff --git a/llms/mlx_lm/utils.py b/llms/mlx_lm/utils.py index 103160ce..07f0db5e 100644 --- a/llms/mlx_lm/utils.py +++ b/llms/mlx_lm/utils.py @@ -19,7 +19,12 @@ import mlx.nn as nn use_modelscope = os.getenv('MLX_USE_MODELSCOPE', 'False').lower() == 'true' if use_modelscope: - from modelscope import snapshot_download + try: + from modelscope import snapshot_download + except ImportError: + raise ImportError( + "Please run `pip install modelscope` to activate the ModelScope." + ) else: from huggingface_hub import snapshot_download @@ -160,14 +165,16 @@ def get_model_path(path_or_hf_repo: str, revision: Optional[str] = None) -> Path Path: The path to the model. """ model_path = Path(path_or_hf_repo) + os.environ['MLX_USE_MODELSCOPE'] = 'False' if not model_path.exists(): try: if use_modelscope: + print(f"Downloading model from Modelscope: {path_or_hf_repo}") model_path = Path( snapshot_download( model_id=path_or_hf_repo, - revision=revision or 'master', + revision=revision, allow_patterns=[ "*.json", "*.safetensors",