tvalentyn commented on code in PR #40667:
URL: https://github.com/apache/beam/pull/40667#discussion_r4332165498
##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -2237,26 +2240,36 @@ def process(
side input is empty or the model has not been updated, the method
simply runs inference on the batch of data.
"""
- if not si_model_metadata:
- if (not self._model_metadata.is_valid_tag(self._cur_tag) or
- self._model is None):
+ if (not si_model_metadata or
+ isinstance(si_model_metadata, beam.pvalue.EmptySideInput)):
+ # No side input value: keep the loaded model, if any.
+ needs_update = (
+ self._model is None or # No model loaded yet.
+ not self._model_metadata.is_valid_tag(self._cur_tag)) # Invalidated.
+ if needs_update:
self.update_model(side_input_model_path=None)
return self._run_inference(batch, inference_args)
- if isinstance(si_model_metadata, beam.pvalue.EmptySideInput):
- self.update_model(side_input_model_path=None)
- elif isinstance(si_model_metadata, list) and hasattr(si_model_metadata[0],
- 'keys'):
+ if isinstance(si_model_metadata, list) and hasattr(si_model_metadata[0],
+ 'keys'):
# TODO(https://github.com/apache/beam/issues/27628): Update metrics here
- self.update_model(si_model_metadata)
- elif self._side_input_path != si_model_metadata.model_id:
- self._side_input_path = si_model_metadata.model_id
- self._metrics_collector = self.get_metrics_collector(
- prefix=si_model_metadata.model_name)
- lock = threading.Lock()
- with lock:
+ needs_update = (
+ self._model is None or # No model loaded yet.
+ self._side_input_path != si_model_metadata or # New mapping.
+ not self._model_metadata.is_valid_tag(self._cur_tag)) # Invalidated.
+ if needs_update:
+ self.update_model(si_model_metadata)
+ self._side_input_path = list(si_model_metadata)
+ else:
+ needs_update = (
+ self._model is None or # No model loaded yet.
+ self._side_input_path != si_model_metadata.model_id or # New model.
+ not self._model_metadata.is_valid_tag(self._cur_tag)) # Invalidated.
Review Comment:
done, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]