remove modelscope dependency and add import check

This commit is contained in:
wangxingjun778 2025-01-11 03:08:38 +08:00
parent a63aabcd8e
commit 5303c2bafd
2 changed files with 9 additions and 3 deletions

View File

@ -4,4 +4,3 @@ transformers[sentencepiece]>=4.39.3
protobuf protobuf
pyyaml pyyaml
jinja2 jinja2
modelscope

View File

@ -19,7 +19,12 @@ import mlx.nn as nn
use_modelscope = os.getenv('MLX_USE_MODELSCOPE', 'False').lower() == 'true' use_modelscope = os.getenv('MLX_USE_MODELSCOPE', 'False').lower() == 'true'
if use_modelscope: 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: else:
from huggingface_hub import snapshot_download 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. Path: The path to the model.
""" """
model_path = Path(path_or_hf_repo) model_path = Path(path_or_hf_repo)
os.environ['MLX_USE_MODELSCOPE'] = 'False'
if not model_path.exists(): if not model_path.exists():
try: try:
if use_modelscope: if use_modelscope:
print(f"Downloading model from Modelscope: {path_or_hf_repo}")
model_path = Path( model_path = Path(
snapshot_download( snapshot_download(
model_id=path_or_hf_repo, model_id=path_or_hf_repo,
revision=revision or 'master', revision=revision,
allow_patterns=[ allow_patterns=[
"*.json", "*.json",
"*.safetensors", "*.safetensors",