Lily-Le / EcoTTA

This is a community implementation for the paper EcoTTA: Memory-Efficient Continual Test-time Adaptation via Self-distilled Regularization
20 stars 2 forks source link

RuntimeError: set_sizes_and_strides is not allowed on a Tensor created from .data or .detach(). #6

Open daeunni opened 3 months ago

daeunni commented 3 months ago

Hi, @Lily-Le , I got this error when running CIFAR10 + WildResNet28.

  File "/d1/daeun/EcoTTA/ecotta_models/wideresnet28.py", line 97, in forward
    return F.relu(self.bn(self.conv(x)))
  File "/home/daeun/anaconda3/envs/cotta/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/daeun/anaconda3/envs/cotta/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 423, in forward
    return self._conv_forward(input, self.weight)
  File "/home/daeun/anaconda3/envs/cotta/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 419, in _conv_forward
    return F.conv2d(input, weight, self.bias, self.stride,
RuntimeError: set_sizes_and_strides is not allowed on a Tensor created from .data or .detach().
If your intent is to change the metadata of a Tensor (such as sizes / strides / storage / storage_offset)
without autograd tracking the change, remove the .data / .detach() call and wrap the change in a `with torch.no_grad():` block.
For example, change:

Do you have any idea?

daeunni commented 3 months ago

It seems https://github.com/Lily-Le/EcoTTA/blob/85c11222bb8b9ddae7270ebff9debf51a5e3bcc7/ecotta_models/wideresnet28.py#L96 this line occur that error.

daeunni commented 3 months ago

May I modify this part https://github.com/Lily-Le/EcoTTA/blob/85c11222bb8b9ddae7270ebff9debf51a5e3bcc7/ecotta_models/wideresnet28.py#L128C1-L131C30

like below? After I modify, I addressed this error but the performance seems to be slightly poor.

x1 = x.detach()
out1 = self.original_part(x1)
out2 = self.meta_part.meta_bn(out1)
out3 = self.meta_part(x)   # ERROR