if you are here and you are not constructing an layer or loss before using it that’s why your getting the error. Do:
loss = nn.MSELoss()(y, y_pred)

not
loss = nn.MSELoss(y, y_pred)

very different it seems.