UserWarning: An output with one or more elements was resized since it had shape

This part of code was working properly with old torch versions but it raises this error when I switched to torch 1.9

torch.index_select(v_flat, dim=0, index=self._i00.view(-1), out=self._v00)
        torch.index_select(v_flat, dim=0, index=self._i01.view(-1), out=self._v01)
        torch.index_select(v_flat, dim=0, index=self._i10.view(-1), out=self._v10)
        torch.index_select(v_flat, dim=0, index=self._i11.view(-1), out=self._v11)

it raises this warning

UserWarning: An output with one or more elements was resized since it had shape [638976, 1], which does not match the required output shape [638976, 3].This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at  /opt/conda/conda-bld/pytorch_1623448265233/work/aten/src/ATen/native/Resize.cpp:23.)
  torch.index_select(v_flat, dim=0, index=self._i00.view(-1), out=self._v00)

how could I resolve it ? thank you

1 Like

Double post from here with follow up.