[to #42322933] interface refine with doc

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9159678
This commit is contained in:
yingda.chen
2022-06-24 23:54:10 +08:00
parent 6991620f59
commit 0acbfe1663
6 changed files with 32 additions and 15 deletions

View File

@@ -1,4 +1,3 @@
import imp
import os
import pickle
import subprocess

View File

@@ -6,3 +6,16 @@ DEFAULT_MODELSCOPE_GROUP = 'damo'
MODEL_ID_SEPARATOR = '/'
LOGGER_NAME = 'ModelScopeHub'
class Licenses(object):
APACHE_V2 = 'Apache License 2.0'
GPL = 'GPL'
LGPL = 'LGPL'
MIT = 'MIT'
class ModelVisibility(object):
PRIVATE = 1
INTERNAL = 3
PUBLIC = 5

View File

@@ -2,7 +2,7 @@
import os.path as osp
from abc import ABC, abstractmethod
from typing import Dict, Union
from typing import Dict, Optional, Union
from modelscope.hub.snapshot_download import snapshot_download
from modelscope.models.builder import build_model
@@ -42,13 +42,18 @@ class Model(ABC):
return input
@classmethod
def from_pretrained(cls, model_name_or_path: str, *model_args, **kwargs):
""" Instantiate a model from local directory or remote model repo
def from_pretrained(cls,
model_name_or_path: str,
revision: Optional[str] = 'master',
*model_args,
**kwargs):
""" Instantiate a model from local directory or remote model repo. Note
that when loading from remote, the model revision can be specified.
"""
if osp.exists(model_name_or_path):
local_model_dir = model_name_or_path
else:
local_model_dir = snapshot_download(model_name_or_path)
local_model_dir = snapshot_download(model_name_or_path, revision)
logger.info(f'initialize model from {local_model_dir}')
cfg = Config.from_file(
osp.join(local_model_dir, ModelFile.CONFIGURATION))

View File

@@ -6,6 +6,7 @@ from typing import List, Optional, Union
from requests import HTTPError
from modelscope.hub.constants import Licenses, ModelVisibility
from modelscope.hub.file_download import model_file_download
from modelscope.hub.snapshot_download import snapshot_download
from modelscope.utils.config import Config
@@ -16,8 +17,8 @@ def create_model_if_not_exist(
api,
model_id: str,
chinese_name: str,
visibility: Optional[int] = 5, # 1-private, 5-public
license: Optional[str] = 'apache-2.0',
visibility: Optional[int] = ModelVisibility.PUBLIC,
license: Optional[str] = Licenses.APACHE_V2,
revision: Optional[str] = 'master'):
exists = True
try: