-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add download support for modelscople. #2032
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,12 @@ | |
KAGGLE_PREFIX = "kaggle://" | ||
GS_PREFIX = "gs://" | ||
HF_PREFIX = "hf://" | ||
MODELSCOPE_PREFIX = "modelscope://" | ||
|
||
KAGGLE_SCHEME = "kaggle" | ||
GS_SCHEME = "gs" | ||
HF_SCHEME = "hf" | ||
|
||
MODELSCOPE_SCHEME = "modelscope" | ||
ASSET_DIR = "assets" | ||
TOKENIZER_ASSET_DIR = f"{ASSET_DIR}/tokenizer" | ||
|
||
|
@@ -165,6 +166,39 @@ def get_file(preset, path): | |
raise ValueError(message) | ||
elif scheme in tf_registered_schemes(): | ||
return tf_copy_gfile_to_cache(preset, path) | ||
elif scheme == MODELSCOPE_SCHEME: | ||
try: | ||
from modelscope.hub.snapshot_download import snapshot_download | ||
except: | ||
raise ImportError( | ||
"`from_preset()` requires the `modelscope` package to " | ||
"load from '{preset}'. " | ||
"Please install with `pip install modelscope`." | ||
) | ||
modelscope_handle = preset.removeprefix(MODELSCOPE_SCHEME + "://") | ||
try: | ||
return_path = snapshot_download( | ||
modelscope_handle | ||
)+'/'+path | ||
if os.path.exists(return_path): | ||
return return_path | ||
raise FileNotFoundError( | ||
f"`{return_path}` doesn't exist in preset directory `{preset}`." | ||
) | ||
except HFValidationError as e: | ||
raise ValueError( | ||
"Unexpected ModelScope preset. Hugging Face model handles " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Typo - Hugging Face model handles -> ModelScope |
||
"should have the form 'modelscope://{org}/{model}'. For example, " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: improve error message as - ModelScope handles should follow the format " |
||
f"'modelscope://username/bert_base_en'. Received: preset={preset}." | ||
) from e | ||
except EntryNotFoundError as e: | ||
message = str(e) | ||
if message.find("403 Client Error"): | ||
raise FileNotFoundError( | ||
f"`{path}` doesn't exist in preset directory `{preset}`." | ||
) | ||
else: | ||
raise ValueError(message) | ||
elif scheme == HF_SCHEME: | ||
if huggingface_hub is None: | ||
raise ImportError( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error message can modified as follows
"To load a preset from ModelScope {preset} using
from_preset
, install the ""
modelscope
package with:pip install modelscope
."