Comments (7)
Hi @joddiy , for tensor mul >2d, please use tensor.tensordot
, it depends on which axis to perform the tensordot
def test_4d_tensor_dot(self):
for dev in [cpu_dev, gpu_dev]:
x1 = np.random.randn(1, 12, 256, 64).astype(np.float32)
x2 = np.random.randn(1, 12, 64, 256).astype(np.float32)
x1 = tensor.from_numpy(x1)
x1.to_device(dev)
x2 = tensor.from_numpy(x2)
x2.to_device(dev)
y = tensor.tensordot(x1, x2, axes=([3],[2]))
print(y.shape)
y = tensor.tensordot(x1, x2, axes=([2,3],[3,2]))
print(y.shape)
output:
(1, 12, 256, 1, 12, 256)
(1, 12, 1, 12)
(1, 12, 256, 1, 12, 256)
(1, 12, 1, 12)
...........................
----------------------------------------------------------------------
Ran 27 tests in 0.121s
OK
reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.tensordot.html
from singa.
Hi, shicong, according to the np's definition, the matmul for high-dim matrix should be:
x1 = np.random.randn(1, 12, 256, 64).astype(np.float32)
x2 = np.random.randn(1, 12, 64, 256).astype(np.float32)
print(np.matmul(x1, x2).shape)
Output:
(1, 12, 256, 256)
Actually, it does the matmul for (256, 64) * (64, 256) for all cells of the first two axes (1, 12).
from singa.
fixed in #639
from singa.
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:
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,...
from singa.
And please check the subgraph for this test case:
from singa.
Hi @joddiy , Thank you for pointing out the issue, kindly help to check the lastest code
PR:#639
your test is added:
singa/test/python/test_tensor.py
Line 409 in fc1de1d
from singa.
Hi @dcslin , it works now, thanks for your hlep.
from singa.
Related Issues (20)
- Switch between CPU and GPU devices for cnn example HOT 4
- Save the downloaded datasets to local directory HOT 2
- Add running scripts for cnn and cifar_distributed_cnn examples HOT 4
- Intermediate information printing HOT 3
- Adding arguments for weight decay and momentum HOT 2
- Increase max epoch for cnn example for better convergence HOT 2
- Update CMakeLists.txt for release 4.0.0 HOT 1
- Check Apache license header for release 4.0.0
- OpenCL Compilation Fails
- Upload Release 4.0.0 Package to SVN HOT 1
- Update the NOTICE file for images HOT 1
- gitignore and gitmodules should be removed from the release tar file HOT 2
- Create a new branch dev-postgresql HOT 2
- Create the SumError New Loss Function HOT 1
- Dynamic Creation of Models HOT 2
- Need to return the gradients from optimizer HOT 4
- Maximum recursion depth exceeded in comparison for string HOT 1
- can sparse all-reduce keep efficiency with large number of gpu workers?
- Python 3.11, Model, ImportError HOT 9
- Update documentation for distributed training HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from singa.