I found that just modifying the function name will solve my problem.
I changed this part:
class Model(nn.Module):
  def forward(self, input):
    input = input.cuda()
    output = self.other_function(input)
    return output

model.train()
out = model(data)