I accidentally input a tensor of shape (batch_size, 1, 2, 2) into the BCEWithLogitsLoss() function and gave the expected outputs with the same shape as well. This gave me only one value as loss for each batch whereas I would expect 4 different values as loss for each batch (since it is 1, 2, 2). I wanted to know what torch does internally that I get such an output.

Below is the code I used to test:

```
import torch
import torch.nn as nn
import torch.nn.functional as F
```

```
a = torch.ones(10, 1, 2, 2)
b = torch.randn(10, 1, 2, 2)
```

```
t_loss = torch.binary_cross_entropy_with_logits_loss(b, a)
```

This `t_loss`

gave me an output loss of shape `(10, 1, 2, 2)`

.

```
lfunc = nn.BCEWithlogitsLoss()
n_loss = lfunc(b, a)
f_loss = F.binary_cross_entropy_with_logits_loss(b, a)
```

Here, `n_loss`

and `f_loss`

gave me the same output consisting of only one number.

I was wondering how PyTorch is internally handling this kind of situation.