I’m experiencing memory leak when using a linear layer and a Relu layer.

def forward(self, noise, elem_class):
    
    process = psutil.Process(os.getpid())
    print("Memory 1.1: ", process.memory_info().rss, "bytes", flush=True)
    
    in_vector = torch.cat((noise, elem_class), dim=-1) 
    
    process = psutil.Process(os.getpid())
    print("Memory 1.2: ", process.memory_info().rss, "bytes", flush=True)
    
    in_vector = self.shared_gen_linear(in_vector)
    
    process = psutil.Process(os.getpid())
    print("Memory 1.3: ", process.memory_info().rss, "bytes", flush=True)
    
    in_vector = F.relu(in_vector)           #   batch_size x (2*standard_dim)
    
    process = psutil.Process(os.getpid())
    print("Memory 1.4: ", process.memory_info().rss, "bytes", flush=True)
    
    feats = in_vector[:, :self.standard_dim]
    feats2 = in_vector[:, self.standard_dim:]
    
    for layer in range(0, len(self.feat_gen_linear)):
        feats = self.feat_gen_linear[layer](feats)
    
    feats = feats.view(-1, self.feature_size, self.num_classes)     
    feats = torch.softmax(feats, dim=-1)
    feats = feats.view(-1, self.num_classes*self.feature_size)

    feats2 = self.feats2_gen_linear(feats2)
    feats2 = feats2.view(-1, self.num_classes, 3)
    feats2 = torch.softmax(feats2, dim=-1)
    feats2 = feats2.view(-1, self.num_classes*3)
    
    return feats, feats2


And this layer is defined in the init function of the class.

self.shared_gen_linear = nn.Linear(self.noise_dim + self.num_classes, 2*self.standard_dim)

From the output of the process memory, it appears that the memory leak occurs in

    in_vector = self.shared_gen_linear(in_vector)   
    in_vector = F.relu(in_vector)           #   batch_size x (2*standard_dim)


As seen here,

Memory 1.1:  1217851392 bytes
Memory 1.2:  1217851392 bytes
Memory 1.3:  1218121728 bytes
Memory 1.4:  1218392064 bytes
Memory 1.1:  1219203072 bytes
Memory 1.2:  1219203072 bytes
Memory 1.3:  1219473408 bytes
Memory 1.4:  1220014080 bytes

Any insights on why this memory leak would occur?  I am using PyTorch 1.1.0.