Got it.
class MaskedMSE(nn.Module):
    def __init__(self):
        super(MaskedMSE, self).__init__()
        self.criterion = nn.MSELoss()

    def forward(self, input, target, mask_a, mask_b):
        self.loss = self.criterion(input*mask_a, target*mask_b)
        return self.loss