NVIDIA / MinkowskiEngine

Minkowski Engine is an auto-diff neural network library for high-dimensional sparse tensors
https://nvidia.github.io/MinkowskiEngine
Other
2.43k stars 360 forks source link

Elementwise product #415

Open bricerauby opened 2 years ago

bricerauby commented 2 years ago

Describe the bug

When multiplying (elementwise with * ) two sparse tensors as explained in the documentation, the results does not correspond to a standard elementwise product. The element of the tensor which has it coordinate manager shared are not zeroed when multiplied by a zero element (not represented in the coordinates). Is this expected ? How should I proceed to make a standard elementwise multiplication?


To Reproduce

import MinkowskiEngine as ME
import torch 
import numpy as np

x = np.zeros((3,3))
x[0,0] = 3
x[2,1] = 0.2
x = torch.Tensor(x)
x = ME.to_sparse(x.view(1,1,x.shape[-2],x.shape[-1]))

y = ME.SparseTensor(coordinates=torch.Tensor([[0, 0, 0], [0, 2, 2]]),
                    features=torch.Tensor([[3.], [5.]]), coordinate_manager=x.coordinate_manager)

c = (x * y) 
x = x.dense(shape=torch.Size([1,1,3,3]))[0]
y = y.dense()[0]
c = c.dense()[0]
print(c)
print(x*y)

Output :

tensor([[[[9.0000, 0.0000, 0.0000],
          [0.0000, 0.0000, 0.0000],
          [0.0000, 0.2000, 0.0000]]]])
tensor([[[[9., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.]]]])

Expected behavior the sparse and dense elementwise products should have the same output


==========System========== Linux-3.10.0-1160.41.1.el7.x86_64-x86_64-with-glibc2.2.5 cat: /etc/lsb-release: No such file or directory 3.8.10 (default, Jun 16 2021, 14:19:02) [GCC 9.3.0] ==========Pytorch========== 1.8.1+cu102 torch.cuda.is_available(): True ==========NVIDIA-SMI========== /bin/nvidia-smi Driver Version 470.57.02 CUDA Version 11.4 VBIOS Version 88.00.13.00.02 Image Version G503.0201.00.03 GSP Firmware Version N/A ==========NVCC========== which: no nvcc ==========MinkowskiEngine========== 0.5.4 MinkowskiEngine compiled with CUDA Support: True NVCC version MinkowskiEngine is compiled: 11000 CUDART version MinkowskiEngine is compiled: 11000

bricerauby commented 2 years ago

If I understand well, it seems that the error comes from this line

Maybe the multiplication should distinguished from addition or multiplication

bricerauby commented 2 years ago

I had not seen previous issue, so this issue is a duplicate of #390. @chrischoy Should I close this ?