joddiy commented on issue #634: cannot do matmul for high-dim tensors
URL: https://github.com/apache/singa/issues/634#issuecomment-605074280
 
 
   Hi, @dcslin , thanks for your help, this PR works fine for basic test cases. 
However, for some special cases in onnx, it has an incorrect result, I've 
extracted this test case for you, please use this:
   
   ```python3
   for dev in [cpu_dev, gpu_dev]:
   
         X = np.random.random((1, 256, 12, 64)).astype(np.float32)
         x = tensor.from_numpy(X)
         x.to_device(dev)
   
         W = np.random.random((1, 256, 12, 64)).astype(np.float32)
         w = tensor.from_numpy(W)
         w.to_device(dev)
   
         X = np.transpose(X, (0, 2, 1, 3))
         W = np.transpose(W, (0, 2, 1, 3))
         W = np.transpose(W, (0, 1, 3, 2))
         Y = np.matmul(X, W)
   
         x = autograd.transpose(x, (0, 2, 1, 3))
         w = autograd.transpose(w, (0, 2, 1, 3))
         w = autograd.transpose(w, (0, 1, 3, 2))
         y = autograd.matmul(x, w)
   
         np.testing.assert_array_almost_equal(tensor.to_numpy(x), X)
         np.testing.assert_array_almost_equal(tensor.to_numpy(w), W)
         np.testing.assert_array_almost_equal(tensor.to_numpy(y), Y)
   ```
   
   This test case reports:
   > Traceback (most recent call last):
     File "../../test/python/test_tensor.py", line 389, in test_matmul
       np.testing.assert_array_almost_equal(tensor.to_numpy(y), Y)
     File 
"/usr/local/lib/python3.5/dist-packages/numpy/testing/_private/utils.py", line 
1015, in assert_array_almost_equal
       precision=decimal)
     File 
"/usr/local/lib/python3.5/dist-packages/numpy/testing/_private/utils.py", line 
827, in assert_array_compare
       raise AssertionError(msg)
   AssertionError:
   Arrays are not almost equal to 6 decimals
   
   > Mismatch: 100%
   Max absolute difference: 11.377065
   Max relative difference: 1.148434
    x: array([[[[14.145736, 13.506734, 13.252323, ..., 14.569139, 15.795746,
             15.196916],
            [18.76216 , 17.117498, 14.830437, ..., 17.131226, 17.974703,...
    y: array([[[[16.710552, 17.515999, 15.49446 , ..., 15.438944, 18.269606,
             15.611665],
            [14.75556 , 14.552402, 14.04308 , ..., 14.70639 , 15.604133,...

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to