Skip to content

Commit

Permalink
Add try exception to persist and load (#193)
Browse files Browse the repository at this point in the history
* fix: add exception to catch exception when persisitng and loading model

* build: update version to 2.1.3
  • Loading branch information
phamhoangtuan authored Jun 29, 2023
1 parent 312a6eb commit 9ba0377
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions h1st/model/repository/model_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "h1st"
version = "2.1.2"
version = "2.1.3"
description = "Human-First AI (H1st)"
authors = ["Aitomatic, Inc. <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 9ba0377

Please sign in to comment.