Repository: apache/tvm

Issue:
[Bug] NotImplementedError ['aten::__lshift__', 'aten::__rshift__', 'aten::__ior__', `aten::fmod`, `aten::remainder`]
Hi,

I am running a pytorch model and I am getting this error.

File "/home/hummingbird/tvm/python/tvm/relay/frontend/pytorch.py", line 3991, in from_pytorch
    converter.report_missing_conversion(op_names)
  File "/home/hummingbird/tvm/python/tvm/relay/frontend/pytorch.py", line 3197, in report_missing_conversion
    raise NotImplementedError(msg)
NotImplementedError: The following operators are not implemented: ['aten::__lshift__', 'aten::__rshift__', 'aten::unique_consecutive', 'aten::__ior__']

My versions are:
torch: 1.10.0
tvm: 0.9.dev708+g17652d341

@masahi 

Thanks!


Discussion:
@interesaaat Can we remove `aten::unique_consecutive` from the list now? Other ops seem trivial.
Yes let's remove unique_consecutive. I will open another issue if it will
be really needed.

On Mon, Mar 7, 2022, 10:20 PM Masahiro Masuda ***@***.***>
wrote:

> @interesaaat <https://github.com/interesaaat> Can we remove
> aten::unique_consecutive from the list now? Other ops seem trivial.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/apache/tvm/issues/10499#issuecomment-1061448838>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AALWR5YEMV3HNCDMN63ELC3U63WRNANCNFSM5QAJDYNA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


Resolving patch:
diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py
--- a/python/tvm/relay/frontend/pytorch.py
+++ b/python/tvm/relay/frontend/pytorch.py
@@ -3163,6 +3163,11 @@ def create_convert_map(self):
             "aten::dot": self.dot,
             "aten::mv": self.mv,
             "aten::grid_sampler": self.grid_sampler,
+            "aten::__ior__": self.make_elemwise("bitwise_or"),
+            "aten::__iand__": self.make_elemwise("bitwise_and"),
+            "aten::__ixor__": self.make_elemwise("bitwise_xor"),
+            "aten::__lshift__": self.make_elemwise("left_shift"),
+            "aten::__rshift__": self.make_elemwise("right_shift"),
         }
 
     def update_convert_map(self, custom_map):
diff --git a/python/tvm/relay/op/_tensor.py b/python/tvm/relay/op/_tensor.py
--- a/python/tvm/relay/op/_tensor.py
+++ b/python/tvm/relay/op/_tensor.py
@@ -267,6 +267,8 @@ def elemwise_shape_func(attrs, inputs, _):
 register_shape_func("greater_equal", False, broadcast_shape_func)
 register_shape_func("maximum", False, broadcast_shape_func)
 register_shape_func("minimum", False, broadcast_shape_func)
+register_shape_func("left_shift", False, broadcast_shape_func)
+register_shape_func("right_shift", False, broadcast_shape_func)
 
 register_shape_func("sqrt", False, elemwise_shape_func)
 register_shape_func("negative", False, elemwise_shape_func)


Test patch:
diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py
--- a/tests/python/frontend/pytorch/test_forward.py
+++ b/tests/python/frontend/pytorch/test_forward.py
@@ -4205,6 +4205,39 @@ def forward(self, x):
     relay.frontend.from_pytorch(script_module, [("x", x.shape)])
 
 
+@tvm.testing.uses_gpu
+def test_binary_bitwise():
+    def test_ior(x, y):
+        return x.__ior__(y)
+
+    def test_iand(x, y):
+        return x.__iand__(y)
+
+    def test_ixor(x, y):
+        return x.__ixor__(y)
+
+    x = torch.tensor([7, 49, 16, 1, 2, 3], dtype=torch.uint8)
+    y = torch.tensor([39, 128, 99, 228, 63, 17], dtype=torch.uint8)
+
+    for test_fn in [test_ior, test_iand, test_ixor]:
+        verify_model(test_fn, [x, y])
+
+
+@tvm.testing.uses_gpu
+def test_shift():
+    def test_lshift(x, y):
+        return x << y
+
+    def test_rshift(x, y):
+        return x >> y
+
+    x = torch.tensor([39, 128, 99, 228, 63, 17], dtype=torch.int32)
+    y = torch.tensor([3, 2, 7, 4, 5, 9], dtype=torch.int32)
+
+    for test_fn in [test_lshift, test_rshift]:
+        verify_model(test_fn, [x, y])
+
+
 @tvm.testing.uses_gpu
 def test_mod():
     def test_fmod(x, y):