You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/07/15 13:16:12 UTC

[GitHub] [beam] yeandy commented on a diff in pull request #22282: [21894] Validates inference_args early

yeandy commented on code in PR #22282:
URL: https://github.com/apache/beam/pull/22282#discussion_r922153079


##########
sdks/python/apache_beam/ml/inference/base_test.py:
##########
@@ -128,9 +136,21 @@ def test_run_inference_impl_inference_args(self):
       pcoll = pipeline | 'start' >> beam.Create(examples)
       inference_args = {'key': True}
       actual = pcoll | base.RunInference(
-          FakeModelHandlerExtraInferenceArgs(), inference_args=inference_args)
+          FakeModelHandlerExpectedInferenceArgs(),
+          inference_args=inference_args)
       assert_that(actual, equal_to(examples), label='assert:inferences')
 
+  def test_unexpected_inference_args_passed(self):
+    with self.assertRaisesRegex(ValueError, r'inference_args were provided'):
+      with TestPipeline() as pipeline:
+        examples = [1, 5, 3, 10]
+        pcoll = pipeline | 'start' >> beam.Create(examples)
+        inference_args = {'key': True}
+        actual = pcoll | base.RunInference(
+            FakeModelHandlerFailsOnInferenceArgs(),
+            inference_args=inference_args)
+        assert_that(actual, equal_to(examples), label='assert:inferences')

Review Comment:
   Will we ever hit this `assert_that` line?



##########
sdks/python/apache_beam/ml/inference/base_test.py:
##########
@@ -79,12 +79,20 @@ def batch_elements_kwargs(self):
     return {'min_batch_size': 9999}
 
 
-class FakeModelHandlerExtraInferenceArgs(FakeModelHandler):
+class FakeModelHandlerFailsOnInferenceArgs(FakeModelHandler):
+  def run_inference(self, batch, unused_model, inference_args=None):
+    raise ValueError('run_inference should not be called.')

Review Comment:
   ```suggestion
       raise ValueError('run_inference should not be called because error should already be thrown from the validate_inference_args check.')
   ```



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org