Assuming you are working on a multi-class segmentation use case, I would use nn.CrossEntropyLoss as the “base” loss instead of MSELoss.
For the dice loss implementation, you could have a look at this issue or the implementation from torchgeometry.