Eliaaazzz commented on code in PR #37428:
URL: https://github.com/apache/beam/pull/37428#discussion_r2744081016
##########
sdks/python/apache_beam/ml/inference/base_test.py:
##########
@@ -2133,5 +2133,63 @@ def request(self, batch, model, inference_args=None):
model_handler.run_inference([1], FakeModel())
+class FakeModelHandlerForSizing(base.ModelHandler[int, int, FakeModel]):
+ """A ModelHandler used to test element sizing behavior."""
+ def __init__(
+ self,
+ max_batch_size: int = 10,
+ max_batch_weight: Optional[int] = None,
+ element_size_fn=None):
+ self._max_batch_size = max_batch_size
+ self._max_batch_weight = max_batch_weight
+ self._element_size_fn = element_size_fn
+
+ def load_model(self) -> FakeModel:
+ return FakeModel()
+
+ def run_inference(self, batch, model, inference_args=None):
+ return [model.predict(x) for x in batch]
+
+ def batch_elements_kwargs(self):
+ kwargs = {'max_batch_size': self._max_batch_size}
+ if self._max_batch_weight is not None:
+ kwargs['max_batch_weight'] = self._max_batch_weight
+ if self._element_size_fn:
+ kwargs['element_size_fn'] = self._element_size_fn
+ return kwargs
Review Comment:
> This is probably a good suggestion
Makes sense, I'll refactor this to use super().__init__ and rely on the base
class implementation.
--
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]