ltkong218 / IFRNet

IFRNet: Intermediate Feature Refine Network for Efficient Frame Interpolation (CVPR 2022)
MIT License
276 stars 23 forks source link

GPU memory leak in class ResBlock (line 44 & 46 in IFRNet_S.py) in pytorch 1.13.0 #32

Open VicRanger opened 1 year ago

VicRanger commented 1 year ago

I found gpu memory leak when program runs into following lines. (It might be a bug in higher version of pytorch)

https://github.com/ltkong218/IFRNet/blob/main/models/IFRNet_S.py#L44 https://github.com/ltkong218/IFRNet/blob/main/models/IFRNet_S.py#L46

officical code (which leads to GPU memory leak):

out = self.conv1(x)
out[:, -self.side_channels:, :, :] = self.conv2(out[:, -self.side_channels:, :, :])
out = self.conv3(out)
out[:, -self.side_channels:, :, :] = self.conv4(out[:, -self.side_channels:, :, :])
out = self.prelu(x + self.conv5(out))
return out

then I changed codes to the following, GPU mem leak disappeared. (using concat to get a new feature after each side conv)

  out = self.conv1(x)
  side_ft = out[:, :-self.side_channels, :, :]
  conv_ft = out[:, -self.side_channels:, :, :]
  conv_ft = self.conv2(conv_ft)
  out = torch.cat([side_ft, conv_ft], axis=1)
  out = self.conv3(out)
  side_ft = out[:, :-self.side_channels, :, :]
  conv_ft = out[:, -self.side_channels:, :, :]
  conv_ft = self.conv4(conv_ft)
  out = torch.cat([side_ft, conv_ft], axis=1)
  out = self.prelu(x + self.conv5(out))

my specs: ubuntu 20.04, python 3.9, pytorch1.13.1+cu117, with gpu v100(single card)

ltkong218 commented 1 year ago

Thanks for the feedback. This may be a bug in higher version of PyTorch.