The problem is with your shapes.
Currently you are just using tensors of the shape [batch_size] for the output and target.
This works fine in your manual approach, as you are just defining the weight matrix as torch.randn(dim_in) (the output dimension is missing).
However, if you use the nn.Linear module, the output will have a shape of [batch_size, out_features].
In your case it will be [300, 1].
Now, if you calculate the MSELoss of the output ([300, 1]) and target ([300]), an internal broadcasting will happen, which is unwanted at this point.
This issue is being tracked here 5.
You can easily fix this by unsqueezing dim1 in your target for the nn.Linear approach:
l = loss(output, yn_.unsqueeze(1))

Also note that Variables are deprecated since PyTorch 0.4.0. If you are using a newer version, you can just create tensors with requires_grad=True.