Browse Source

fix task to model; handle exception

master
jiangyu.xzy 3 years ago
parent
commit
60af6b701b
3 changed files with 11 additions and 8 deletions
  1. +8
    -5
      modelscope/hub/utils/utils.py
  2. +1
    -1
      modelscope/pipelines/base.py
  3. +2
    -2
      modelscope/trainers/trainer.py

+ 8
- 5
modelscope/hub/utils/utils.py View File

@@ -92,9 +92,12 @@ def file_integrity_validation(file_path, expected_sha256):
def create_library_statistics(method: str, def create_library_statistics(method: str,
name: str, name: str,
cn_name: Optional[str]): cn_name: Optional[str]):
path = f'{get_endpoint()}/api/v1/statistics/library'
headers = {'user-agent': ModelScopeConfig.get_user_agent()}
params = {"Method": method, "Name": name, "CnName": cn_name}
r = requests.post(path, params=params, headers=headers)
r.raise_for_status()
try:
path = f'{get_endpoint()}/api/v1/statistics/library'
headers = {'user-agent': ModelScopeConfig.get_user_agent()}
params = {"Method": method, "Name": name, "CnName": cn_name}
r = requests.post(path, params=params, headers=headers)
r.raise_for_status()
except Exception:
pass
return return

+ 1
- 1
modelscope/pipelines/base.py View File

@@ -152,7 +152,7 @@ class Pipeline(ABC):
**kwargs) -> Union[Dict[str, Any], Generator]: **kwargs) -> Union[Dict[str, Any], Generator]:
# model provider should leave it as it is # model provider should leave it as it is
# modelscope library developer will handle this function # modelscope library developer will handle this function
model_name = self.cfg.task
model_name = self.cfg.model.type
create_library_statistics("pipeline", model_name, None) create_library_statistics("pipeline", model_name, None)
# place model to cpu or gpu # place model to cpu or gpu
if (self.model or (self.has_multiple_models and self.models[0])): if (self.model or (self.has_multiple_models and self.models[0])):


+ 2
- 2
modelscope/trainers/trainer.py View File

@@ -437,7 +437,7 @@ class EpochBasedTrainer(BaseTrainer):


def train(self, checkpoint_path=None, *args, **kwargs): def train(self, checkpoint_path=None, *args, **kwargs):
self._mode = ModeKeys.TRAIN self._mode = ModeKeys.TRAIN
model_name = self.cfg.task
model_name = self.cfg.model.type
create_library_statistics("train", model_name, None) create_library_statistics("train", model_name, None)


if self.train_dataset is None: if self.train_dataset is None:
@@ -459,7 +459,7 @@ class EpochBasedTrainer(BaseTrainer):
self.train_loop(self.train_dataloader) self.train_loop(self.train_dataloader)


def evaluate(self, checkpoint_path=None): def evaluate(self, checkpoint_path=None):
model_name = self.cfg.task
model_name = self.cfg.model.type
create_library_statistics("evaluate", model_name, None) create_library_statistics("evaluate", model_name, None)
if checkpoint_path is not None and os.path.isfile(checkpoint_path): if checkpoint_path is not None and os.path.isfile(checkpoint_path):
from modelscope.trainers.hooks import CheckpointHook from modelscope.trainers.hooks import CheckpointHook


Loading…
Cancel
Save