riteshghorse commented on code in PR #26683:
URL: https://github.com/apache/beam/pull/26683#discussion_r1194109659


##########
sdks/python/apache_beam/ml/inference/pytorch_inference_test.py:
##########
@@ -893,5 +894,55 @@ def test_env_vars_set_correctly_keyed_tensor_handler(self):
       self.assertTrue((os.environ['FOO']) == 'bar')
 
 
[email protected]_pytorch
+class PytorchInferenceTestWithMocks(unittest.TestCase):
+  def setUp(self):
+    self._load_model = pytorch_inference._load_model
+    pytorch_inference._load_model = unittest.mock.MagicMock(
+        return_value=("model", "device"))
+    self.tmpdir = tempfile.mkdtemp()
+    self.state_dict = OrderedDict([('linear.weight', torch.Tensor([[2.0, 3]])),
+                                   ('linear.bias', torch.Tensor([0.5]))])
+    self.torch_path = os.path.join(self.tmpdir, 'torch_model.pt')
+    torch.save(self.state_dict, self.torch_path)
+    self.model_params = {'input_dim': 2, 'output_dim': 1}
+
+  def tearDown(self):
+    pytorch_inference._load_model = self._load_model
+    shutil.rmtree(self.tmpdir)
+
+  def test_load_model_args_tensor(self):
+    load_model_args = {'weights_only': True}
+    model_handler = PytorchModelHandlerTensor(
+        state_dict_path=self.torch_path,
+        model_class=PytorchLinearRegression,
+        model_params=self.model_params,
+        load_model_args=load_model_args)
+    model_handler.load_model()
+    pytorch_inference._load_model.assert_called_with(
+        PytorchLinearRegression,
+        self.torch_path,

Review Comment:
   done



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