Skip to content

Commit 1d703fe

Browse files
Make ModelManager import more robust (#38936)
* Make ModelManager import more robust * Make ModelManager import more robust 2 * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Add model tag to annotations as well * Change to not use function import --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 1c18250 commit 1d703fe

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • sdks/python/apache_beam/ml/inference

sdks/python/apache_beam/ml/inference/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ def annotations(self):
14431443
'model_handler_type': (
14441444
f'{self._model_handler.__class__.__module__}'
14451445
f'.{self._model_handler.__class__.__qualname__}'),
1446+
'model_identifier': self._model_tag,
14461447
**super().annotations()
14471448
}
14481449

@@ -1997,6 +1998,11 @@ def load():
19971998
# Ensure the tag we're loading is valid, if not replace it with a valid tag
19981999
self._cur_tag = self._model_metadata.get_valid_tag(model_tag)
19992000
if self.use_model_manager:
2001+
# Force an import here to avoid missing ModelManager when needed.
2002+
# Throw an error if ModelManager is not available since it's required for this code path.
2003+
global ModelManager
2004+
if ModelManager is None:
2005+
from apache_beam.ml.inference.model_manager import ModelManager
20002006
logging.info("Using Model Manager to manage models automatically.")
20012007
model_manager = multi_process_shared.MultiProcessShared(
20022008
lambda: ModelManager(**self._model_manager_args),

0 commit comments

Comments
 (0)