`MSELossFlat`: Meaning of 'flattens input and target'?

The documentation for MSELossFlat says:

“Same as nn.MSELoss, but flattens input and target.”

What does ‘flattens’ mean? When should we use nn.MSELoss and when should we use MSELossFlat?

1 Like

I think I understand now:

‘flattens’ means applying squeeze(), e.g., turning a rank 2 tensor into a rank 1 tensor.

Compared to nn.MSELoss, MSELossFlat will work even if the prediction tensor is rank 2 but the target tensor is rank 1.

2 Likes