You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/04/14 03:52:06 UTC

[GitHub] [tvm] comaniac commented on a change in pull request #7845: Fix PyTorch matmul conversion when given (2-dim, N-dim) input pair

comaniac commented on a change in pull request #7845:
URL: https://github.com/apache/tvm/pull/7845#discussion_r612916935



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1607,6 +1607,12 @@ def matmul(self, inputs, input_types):
                 return _op.reshape(output, [*a_shape[:-2], a_shape[-2], b_shape[-1]])
             return output
 
+        # Reshape a or b into a 2 dimensional tensor
+        if len(a_shape) > 2:
+            inputs_0 = _op.reshape(inputs_0, [-1, a_shape[-1]])
+        if len(b_shape) > 2:
+            inputs_1 = _op.reshape(inputs_1, [-1, b_shape[-1]])
+
         # Otherwise a simple dense op will get the job done.

Review comment:
       ```suggestion
            # A simple dense op will get the job done.
   ```
   

##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1607,6 +1607,12 @@ def matmul(self, inputs, input_types):
                 return _op.reshape(output, [*a_shape[:-2], a_shape[-2], b_shape[-1]])
             return output
 
+        # Reshape a or b into a 2 dimensional tensor

Review comment:
       I feel merging them to the above if-branch could be clearer:
   
   ```
   if both a and b > 2:
     Batch matmul
   elif a > 2:
     Reshape a
   elif b > 2:
     Reshape b
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org