But have you any idea about difference in the next two samples?
First one:
x = torch.randn(1, 3, 333, 332)

process = psutil.Process(os.getpid())
model = PSPNet()

@profile
def run_network(idx):
    mem = process.memory_full_info().rss / 1024**2
    print(idx, mem)
    out = model(x)
    # del out

def main():
    for idx in range(40):
        run_network(idx)

main()

Its output has the next repetitive output:
Line #    Mem usage    Increment   Line Contents
================================================
   132    354.2 MiB    354.2 MiB   @profile
   133                             def run_network(idx):
   134    354.2 MiB      0.0 MiB       mem = process.memory_full_info().rss / 1024**2
   135    354.2 MiB      0.0 MiB       print(idx, mem)
   136    433.0 MiB     78.8 MiB       out = model(x)
   137    366.8 MiB      0.0 MiB       del out

that is the out of network is really deleted;
the sample from my server:
    @profile
    def predict(self, img):

        with torch.no_grad():
            data = torch.randn(1, 3, 333, 332)

            logit = self.net(data)
            pred = torch.sigmoid(logit.cpu())[0][0].data.numpy()
            mask = pred >= 0.5

        return None

which in turn doesn’t lead to memory cleaning but just the opposite (up to a certain size as we saw)
its output:
 Line #    Mem usage    Increment   Line Contents
 ================================================
     55    560.0 MiB    560.0 MiB       @profile
     56                                 def predict(self, img):
     57
     58    560.0 MiB      0.0 MiB           with torch.no_grad():
     59                                         # data = self.test_image_transforms(img)
     60                                         # data = torch.unsqueeze(data, dim=0)
     61                                         # data = data.to(self.device)
     62    560.0 MiB      0.0 MiB               data = torch.randn(1, 3, 333, 332)
     63
     64    685.0 MiB    125.0 MiB               logit = self.net(data)
     65
     66    685.0 MiB      0.0 MiB               del logit
     67                                         # pred = torch.sigmoid(logit.cpu())[0][0].data.numpy()
     68                                         # mask = pred >= 0.5
     69
     70
     71    685.0 MiB      0.0 MiB           return None