From 60af6b701b453fdb09cf1f326f8cfac35fcfa27f Mon Sep 17 00:00:00 2001 From: "jiangyu.xzy" Date: Tue, 1 Nov 2022 11:59:59 +0800 Subject: [PATCH] fix task to model; handle exception --- modelscope/hub/utils/utils.py | 13 ++++++++----- modelscope/pipelines/base.py | 2 +- modelscope/trainers/trainer.py | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modelscope/hub/utils/utils.py b/modelscope/hub/utils/utils.py index 8d5db579..5c915998 100644 --- a/modelscope/hub/utils/utils.py +++ b/modelscope/hub/utils/utils.py @@ -92,9 +92,12 @@ def file_integrity_validation(file_path, expected_sha256): def create_library_statistics(method: str, name: 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 diff --git a/modelscope/pipelines/base.py b/modelscope/pipelines/base.py index a56ee934..9280cc09 100644 --- a/modelscope/pipelines/base.py +++ b/modelscope/pipelines/base.py @@ -152,7 +152,7 @@ class Pipeline(ABC): **kwargs) -> Union[Dict[str, Any], Generator]: # model provider should leave it as it is # 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) # place model to cpu or gpu if (self.model or (self.has_multiple_models and self.models[0])): diff --git a/modelscope/trainers/trainer.py b/modelscope/trainers/trainer.py index 92541252..522405ff 100644 --- a/modelscope/trainers/trainer.py +++ b/modelscope/trainers/trainer.py @@ -437,7 +437,7 @@ class EpochBasedTrainer(BaseTrainer): def train(self, checkpoint_path=None, *args, **kwargs): self._mode = ModeKeys.TRAIN - model_name = self.cfg.task + model_name = self.cfg.model.type create_library_statistics("train", model_name, None) if self.train_dataset is None: @@ -459,7 +459,7 @@ class EpochBasedTrainer(BaseTrainer): self.train_loop(self.train_dataloader) def evaluate(self, checkpoint_path=None): - model_name = self.cfg.task + model_name = self.cfg.model.type create_library_statistics("evaluate", model_name, None) if checkpoint_path is not None and os.path.isfile(checkpoint_path): from modelscope.trainers.hooks import CheckpointHook