Issue 1:
🐛 Bug

The MSELoss criteria has a strange behavior when used with two tensors of different sizes -- I would expect this to throw an error. Instead it does... something else.

To Reproduce

Steps to reproduce the behavior:

Install stable, non-CUDA torch, i.e.: https://download.pytorch.org/whl/cpu/torch-1.0.0-cp37-cp37m-linux_x86_64.whl

>>> import torch
>>> import torch.nn as nn
>>> a = torch.Tensor([1, 2, 3])
>>> b = torch.Tensor([[1],[2],[3]])
>>> nn.MSELoss()(a, b)
tensor(1.3333)

Expected behavior

I would've appreciated an error in this case. Perhaps there is some reason why someone might wish to call MSELoss with different sized arrays... but I think if the number of dimensions between the two vectors differs, it's likely the user's mistake.

I realize this is a "rookie mistake," but I promise it was not a fun way to spend 2 hours. Perhaps a friendly warning message could save someone the headache in the future?

Environment

$ python3 collect_env.py
Collecting environment information...
PyTorch version: 1.0.0
Is debug build: No
CUDA used to build PyTorch: Could not collect

OS: Arch Linux
GCC version: (GCC) 8.2.1 20181127
CMake version: version 3.13.3

Python version: 3.7
Is CUDA available: No
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: Quadro M1000M
Nvidia driver version: 415.27
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] Could not collect
[conda] Could not collect

Additional context

It looks like this may have been looked at previously in issue #12129 or PR #5085 ?

Issue 2:
Issue description

When computing the loss between predicted and target with shapes such as target.shape = [100] and predicted.shape = [100, 1], an error should be thrown. Indeed, my colleagues tell me this was the case in version 0.4, but lost in version 1.0.

Code example

# Version 1.0
# Set up straightforward linear regression problem.
import torch
import torch.nn as nn
sample_size = 100
x = torch.randn((sample_size,2))
eps = torch.randn(sample_size )
y = 10 + 9*x[:,0] - 2*x[:, 1] + eps
#y = y.reshape(sample_size, 1)
model = nn.Linear(2, 1)

optimizer = torch.optim.SGD(model.parameters(), lr=.1)
loss_func = nn.MSELoss()
for epoch in range(30):
optimizer.zero_grad()
yhat = model(x)
loss_val = loss_func(yhat, y)
loss_val.backward()
optimizer.step()
print(loss_val.item())

print(model.weight.data)
print(model.bias.data)

If you leave y.reshape commented out, the correct estimates of this straightforward linear regression problem are not found and the loss fails to decrease into a region near the global optimum of this convex problem. Yet, no error is raised.

If you uncomment y.reshape, the correct estimates are found and the loss decreases in the anticipated way.

System Info

Collecting environment information...

PyTorch version: 1.0.0

Is debug build: No

CUDA used to build PyTorch: None

OS: Ubuntu 16.04.5 LTS

GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609

CMake version: Could not collect

Python version: 3.5

Is CUDA available: No

CUDA runtime version: No CUDA

GPU models and configuration: No CUDA

Nvidia driver version: No CUDA

cuDNN version: No CUDA

Versions of relevant libraries:

[pip] Could not collect

[conda] blas 1.0 mkl

[conda] mkl 2017.0.3 0

[conda] torch 1.0.0

[conda] torchvision 0.2.1