jrmccluskey commented on code in PR #24062:
URL: https://github.com/apache/beam/pull/24062#discussion_r1023177391


##########
sdks/python/apache_beam/ml/inference/pytorch_inference_test.py:
##########
@@ -315,6 +358,73 @@ def test_inference_runner_inference_args(self):
     for actual, expected in zip(predictions, KEYED_TORCH_PREDICTIONS):
       self.assertEqual(actual, expected)
 
+  def test_run_inference_helper(self):
+    examples = [
+        torch.from_numpy(np.array([1], dtype="float32")),
+        torch.from_numpy(np.array([5], dtype="float32")),
+        torch.from_numpy(np.array([-3], dtype="float32")),
+        torch.from_numpy(np.array([10.0], dtype="float32")),
+    ]
+    expected_predictions = [
+        PredictionResult(ex, pred) for ex,
+        pred in zip(
+            examples,
+            torch.Tensor([example * 2.0 + 0.5
+                          for example in examples]).reshape(-1, 1))
+    ]
+
+    gen_fn = make_tensor_model_fn('generate')
+
+    model = PytorchLinearRegression(input_dim=1, output_dim=1)
+    model.load_state_dict(
+        OrderedDict([('linear.weight', torch.Tensor([[2.0]])),
+                     ('linear.bias', torch.Tensor([0.5]))]))
+    model.eval()
+
+    inference_runner = TestPytorchModelHandlerForInferenceOnly(
+        torch.device('cpu'), inference_fn=gen_fn)
+    predictions = inference_runner.run_inference(examples, model)

Review Comment:
   Okay that should be fixed now. Test models got `generate()` methods that 
slightly change the output behavior so we can confirm that the routing is 
different. 



-- 
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]

Reply via email to