ganler opened a new issue #10651:
URL: https://github.com/apache/tvm/issues/10651


   Thanks for participating in the TVM community! We use https://discuss.tvm.ai 
for any general usage questions and discussions. The issue tracker is used for 
actionable items such as feature proposals discussion, roadmaps, and bug 
tracking.  You are always welcomed to post on the forum first :smile_cat:
   
   Issues that are inactive for a period of time may get closed. We adopt this 
policy so that we won't lose track of actionable issues that may fall at the 
bottom of the pile. Feel free to reopen a new one if you feel there is an 
additional problem that needs attention when an old one gets closed.
   
   Here's a simple `MatMul` operation where:
   - data tensor: [3]
   - weight tensor's shape: [3, 1]
   
   ```python
   import torch
   
   class Net(torch.nn.Module):
       def __init__(self) -> None:
           super().__init__()
           self.weight = torch.nn.Parameter(torch.randn(3, 1))
   
       def forward(self, x):
           return torch.matmul(x, self.weight)
   
   net = Net().eval()
   
   i = torch.zeros((3), dtype=torch.float)
   o = net(i)
   print(i.shape, o.shape)
   
   with torch.no_grad():
       torch.onnx.export(net, (i), "output.onnx", verbose=True, 
opset_version=14)
   ```
   
   ### Expected behavior
   
   Should be compiled by TVM, as it follows correct ONNX specification and can 
be executed by PyTorch and ONNXRuntime.
   
   ### Actual behavior
   
   ```
   ...
   File "/home/ganler/Documents/tvm/python/tvm/_ffi/_ctypes/packed_func.py", 
line 81, in cfun
       rv = local_pyfunc(*pyargs)
     File "/home/ganler/Documents/tvm/python/tvm/relay/op/nn/_nn.py", line 112, 
in alter_op_layout_dense
       return topi.nn.dense_alter_layout(attrs, inputs, tinfos, out_type)
     File "/home/ganler/miniconda3/lib/python3.8/site-packages/decorator.py", 
line 232, in fun
       return caller(func, *(extras + args), **kw)
     File "/home/ganler/Documents/tvm/python/tvm/target/generic_func.py", line 
286, in dispatch_func
       return dispatch_dict[k](*args, **kwargs)
     File "/home/ganler/Documents/tvm/python/tvm/topi/x86/dense_alter_op.py", 
line 48, in _alter_dense_layout
       M, K = get_const_tuple(data_tensor.shape)
   ValueError: not enough values to unpack (expected 2, got 1)
   ```
   
   This is simply because in 
   
   
https://github.com/apache/tvm/blob/894772975ab33443cf25f40d9f1e2f7b96224978/python/tvm/topi/x86/dense_alter_op.py#L48
   
   This optimization assumes data tensor's rank is 2. Maybe we simply need to 
add `unsqueeze()` to data tensor when converting such ONNX models.
   
   ### Environment
   
   678e76b3efd57b171940f0017bee89451e381785 TVM with LLVM.
   
   cc: @masahi @junrushao1994 @kevinthesun


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