I tried using the if-clause protection, however, the behaviour is the same: it is just being frozen within the first iteration and does not continue firther. Here is the code.
import multiprocessing
...
def main():
    nn.init.kaiming_uniform_(list(densenet.parameters())[0], nonlinearity = 'relu')
    loader = DataLoader(train_data,batch_size=128,shuffle=False,num_workers=0)
    loader_dev = DataLoader(dev_data,batch_size=10,shuffle=None,num_workers=0)
    N_epochs = 10
    for epoch in range(N_epochs):
          optimizer = optim.Adam(densenet.parameters(), lr=.001, betas=(0.9, 0.999), eps=1e-08)
          for batch in loader:
                images = batch[0].float().to('cpu')
                labels = batch[1].float().to('cpu')
                preds = densenet(images)
                loss = Loss(preds,labels).Huber()

                with torch.no_grad():
                      loss_dev = 0
                      for batch_dev in loader_dev:
                          images_dev = batch_dev[0].float().to('cpu')
                          labels_dev = batch_dev[1].float().to('cpu')
                          preds_dev = densenet(images_dev)
                          loss_ = Loss(preds_dev,labels_dev).Huber()
                          loss_dev += loss_

                optimizer.zero_grad()
                loss.backward()
                optimizer.step()

if __name__ == '__main__':
    multiprocessing.freeze_support()
    main()