damccorm commented on code in PR #24062:
URL: https://github.com/apache/beam/pull/24062#discussion_r1022157803
##########
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:
This is failing with `AttributeError: 'PytorchLinearRegression' object has
no attribute 'generate'` - I think that's just an issue with this test and we
need to add a `generate` function to the class, ideally which behaves slightly
different than the forward function.
Same with other similar test
--
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]