traveller59 / spconv

Spatial Sparse Convolution Library
Apache License 2.0
1.86k stars 363 forks source link

RuntimeError: sparse tensors do not have strides #573

Open tjyuyao opened 1 year ago

tjyuyao commented 1 year ago

I have encountered a problem which can be reproduced by the following minimal code:

import torch
from spconv.pytorch import SparseConv2d, SparseConvTensor, SparseReLU
from spconv.pytorch.functional import sparse_add

device='cuda:0'

x = SparseConvTensor.from_dense(torch.randn((2, 48, 48, 7)).to(device))

conv1 = SparseConv2d(7, 7, kernel_size=3, stride=2, padding=1).to(device)
conv2 = SparseConv2d(7, 7, kernel_size=1, stride=2, padding=0).to(device)
act = SparseReLU(inplace=True).to(device)

y = sparse_add(conv1(x), conv2(x))

y = act(y)

The calling trace is as follows:

Traceback (most recent call last):
  File "/home/hyuyao/2023/pytorch-cifar100-master/compare_elu_spadd.py", line 23, in test_spconv
    y = act(y)
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/spconv/pytorch/modules.py", line 175, in forward
    return input.replace_feature(super().forward(input.features))
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/activation.py", line 98, in forward
    return F.relu(input, inplace=self.inplace)
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/functional.py", line 1297, in relu
    result = torch.relu_(input)
RuntimeError: sparse tensors do not have strides
lebron-2016 commented 6 months ago

I have encountered a problem which can be reproduced by the following minimal code:

import torch
from spconv.pytorch import SparseConv2d, SparseConvTensor, SparseReLU
from spconv.pytorch.functional import sparse_add

device='cuda:0'

x = SparseConvTensor.from_dense(torch.randn((2, 48, 48, 7)).to(device))

conv1 = SparseConv2d(7, 7, kernel_size=3, stride=2, padding=1).to(device)
conv2 = SparseConv2d(7, 7, kernel_size=1, stride=2, padding=0).to(device)
act = SparseReLU(inplace=True).to(device)

y = sparse_add(conv1(x), conv2(x))

y = act(y)

The calling trace is as follows:

Traceback (most recent call last):
  File "/home/hyuyao/2023/pytorch-cifar100-master/compare_elu_spadd.py", line 23, in test_spconv
    y = act(y)
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/spconv/pytorch/modules.py", line 175, in forward
    return input.replace_feature(super().forward(input.features))
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/modules/activation.py", line 98, in forward
    return F.relu(input, inplace=self.inplace)
  File "/home/hyuyao/miniconda3/envs/py39/lib/python3.9/site-packages/torch/nn/functional.py", line 1297, in relu
    result = torch.relu_(input)
RuntimeError: sparse tensors do not have strides

您好,请问解决了吗?