From 9ba037738fc44ba9e75d2074e40944980c600993 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Thu, 29 Jun 2023 14:24:56 +0700 Subject: [PATCH] Add try exception to persist and load (#193) * fix: add exception to catch exception when persisitng and loading model * build: update version to 2.1.3 --- h1st/model/repository/model_repository.py | 10 +++++++--- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/h1st/model/repository/model_repository.py b/h1st/model/repository/model_repository.py index 3be906a0..68931a7c 100644 --- a/h1st/model/repository/model_repository.py +++ b/h1st/model/repository/model_repository.py @@ -421,22 +421,24 @@ def persist(self, model, version=None): self._serder.serialize(model, serialized_dir) _tar_create(tar_file, serialized_dir) - logger.info(f'Created tar file {tar_file} at {serialized_dir} for model {model} version {version}') + logger.info(f'Created tar file {tar_file} for model {model} version {version}') with open(tar_file, mode="rb") as f: self._storage.set_bytes( self._get_key(model, version), f.read(), ) - logger.info(f'Set bytes {self._get_key(model, version)} to storage from {tar_file} - {serialized_dir}') + logger.info(f'Set bytes {self._get_key(model, version)} to storage from local {tar_file}') self._storage.set_obj( self._get_key(model, "latest"), version, ) - logger.info(f'Set obj {self._get_key(model, "latest")} to storage from {tar_file} - {serialized_dir}') + logger.info(f'Set obj {self._get_key(model, "latest")} to storage from local {tar_file}') model.version = version + except Exception as e: + logger.exception(f'Error persisting model {model} version {version}: {e}') finally: dir_util.remove_tree(tmpdir) logger.info(f'Removed temp dir {tmpdir}') @@ -468,6 +470,8 @@ def load(self, model, version=None): _tar_extract(tar_file, serialized_dir) self._serder.deserialize(model, serialized_dir) model.version = version + except Exception as e: + logger.exception(f'Error loading model {model} version {version}: {e}') finally: # We get error from Tensorflow telling that it could not find the folder # Unsuccessful TensorSliceReader constructor: Failed to get matching files on diff --git a/pyproject.toml b/pyproject.toml index 3448057b..3b0e0e08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "h1st" -version = "2.1.2" +version = "2.1.3" description = "Human-First AI (H1st)" authors = ["Aitomatic, Inc. "] license = "Apache-2.0"