In the code, I print the memory usage after x created and beforce the forward pass. Thus the increased memory didn’t include the tensor x. I have tried del x and gc.collect() it didn’t work.
print("Before forward: {}".format(psutil.Process(os.getpid()).memory_info().rss))
with torch.no_grad():
    outputs = self.model(x)
print("After forward: {}".format(psutil.Process(os.getpid()).memory_info().rss))