Hmm, I don’t see anything wrong with these pieces of code.
For the dice score, I would advise having a dice_score function that returns the dice for each element of the batch, and then doing a mean on the concatenations of all the dices.
val_dices = []
for val_batch, val_sample in enumerate(val_dataset_loader,0):
    ...
    val_dices.append(dice_score(pred_val_mask, val_mask)) # dice score return a tensor of length batch_size
    ...
val_dice_score = torch.cat(val_dices, 0).mean().item()

If your dataset length is not a multiple of your batch_size, computing the dice per batch is gonna cause some differences when summing.
On a different note, it is preferable that a model returns non-normalized activations (before sigmoid or softmax) as, depending on your loss (not the case in your code), this can cause numerical instability. This mostly happens when the loss uses a log.