mit-han-lab / torchsparse

[MICRO'23, MLSys'22] TorchSparse: Efficient Training and Inference Framework for Sparse Convolution on GPUs.

Home Page:https://torchsparse.mit.edu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] <title> Features Replacement of SparseTensor

huohuohuohuohuohuohuohuo opened this issue · comments

commented

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I am using features generated from a model to replace the original features of SparseTensors. I would like to ask how to make the correct replacement to ensure the subsequent transposed convolution successful. (I made several sparse convs with stride of 2 before). I was wondering the stride may also be replaced. Here is my code:

  def func(self, data, feats):
  
      data_Q = SparseTensor(
          feats=feats,
          coords=data.C
      )

      return data_Q

And I got errors when using the data_Q to implement the transposed convolution.
File "/home/hx/PycharmProjects/pcgc/PCGCv2_Resnet_ts/pcc_model.py", line 119, in forward
out_cls_list, out = self.decoder(y_q, training)
File "/home/hx/anaconda3/envs/torchsparse/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
File "/home/hx/PycharmProjects/pcgc/PCGCv2_Resnet_ts/autoencoder.py", line 289, in forward
out = self.relu(self.conv0(self.up0(x)))
File "/home/hx/anaconda3/envs/torchsparse/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
File "/home/hx/anaconda3/envs/torchsparse/lib/python3.9/site-packages/torchsparse-2.1.0-py3.9-linux-x86_64.egg/torchsparse/nn/modules/conv.py", line 98, in forward
return F.conv3d(
File "/home/hx/anaconda3/envs/torchsparse/lib/python3.9/site-packages/torchsparse-2.1.0-py3.9-linux-x86_64.egg/torchsparse/nn/functional/conv/conv.py", line 138, in conv3d
kmap = F.transpose_kernel_map(
File "/home/hx/anaconda3/envs/torchsparse/lib/python3.9/site-packages/torchsparse-2.1.0-py3.9-linux-x86_64.egg/torchsparse/nn/functional/conv/kmap/build_kmap.py", line 233, in transpose_kernel_map
kmap["out_in_map"], make_divisible(kmap["sizes"][0], cta_M)
TypeError: 'NoneType' object is not subscriptable

Similar operation in Minkowski Engine is shown below and it worked.

def func(self, data, feats):

    data_Q = ME.SparseTensor(
        features=feats,
        coordinate_map_key=data.coordinate_map_key,
        coordinate_manager=data.coordinate_manager,
        device=data.device)

    return data_Q

Expected Behavior

The transposed convolution can be successfully implemented.

Environment

- GCC:
- NVCC:
- PyTorch:
- PyTorch CUDA:
- TorchSparse:

Anything else?

No response

Hi @huohuohuohuohuohuohuohuo . It seems like the SparseTensor._caches is not correctly passed to the new SparseTensor you constructed, and thus the new SparseTensor does not have any information about the kmap. From the information you provided, one thing I suggest you try is to modify you func as:

  def func(self, data, feats):
  
      data_Q = SparseTensor(
          feats=feats,
          coords=data.C
      )
     data_Q._caches = data._caches
     return data_Q

Another method to do this is to just make copy of data (data_Q) and modify data_Q.F, without explicitly constructing a new SparseTensor.

commented

Thanks for your replying. Can I just assign the variable feats to the Sparse Tensor and return the data ?

data.F = feats

return data

Sure. It's ok to do that.

commented

It seems like that the copy of data (data_Q) is a shallow copy. The change of values of data_Q will affect the values of data. How do I make a deep copy ?

data_Q._caches = data._caches will not copy the stride and spatial range. Do I need copy this variables separately ?