Fix direct comparison of OperatorDef proto structs (#18466)
authorJunjie Bai <bai@in.tum.de>
Wed, 27 Mar 2019 00:16:23 +0000 (17:16 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 27 Mar 2019 00:25:09 +0000 (17:25 -0700)
Summary:
arguments order is okay to be different

ajyu
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18466

Differential Revision: D14627258

Pulled By: bddppq

fbshipit-source-id: 430e1fb1bea2c5639a547ae7c1652368788c86b9

caffe2/python/serialized_test/serialized_test_util.py

index 1579d8a..2e92e91 100644 (file)
@@ -181,10 +181,21 @@ class SerializedTestCase(hu.HypothesisTestCase):
             with open(grad_path, 'rb') as f:
                 loaded_grad = f.read()
             grad_proto = parse_proto(loaded_grad)
-            self.assertTrue(grad_proto == grad_ops[i])
+            self._assertSameOps(grad_proto, grad_ops[i])
 
         shutil.rmtree(temp_dir)
 
+    def _assertSameOps(self, op1, op2):
+        op1_ = caffe2_pb2.OperatorDef()
+        op1_.CopyFrom(op1)
+        op1_.arg.sort(key=lambda arg: arg.name)
+
+        op2_ = caffe2_pb2.OperatorDef()
+        op2_.CopyFrom(op2)
+        op2_.arg.sort(key=lambda arg: arg.name)
+
+        self.assertEqual(op1_, op2_)
+
     def assertSerializedOperatorChecks(
             self,
             inputs,