Runtime Error:Found dtype Long but expected Float

Hi when i use MSELOSS instead of NLLLOSS , i get this Error

import torch
import torch.nn as nn
import torch.optim as optim

model = nn.Sequential(
nn.Linear(3072, 512),
nn.Tanh(),
nn.Linear(512, 2),
nn.LogSoftmax(dim=1))

learning_rate = 1e-2

optimizer = optim.SGD(model.parameters(), lr=learning_rate)

loss_fn = nn.MSELoss()

n_epochs = 100

for epoch in range(n_epochs):
for img, label in cifar2:
out = model(img.view(-1).unsqueeze(0))
leb = torch.tensor([label])
loss = loss_fn(out, leb)

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

print("Epoch: %d, Loss: %f" % (epoch, float(loss)))

As the error message explains floating point tensors are expected for the model output and target while you are most likely still passing the target tensor as a LongTensor to nn.MSELoss.
Transform it via label = label.float() and the error should be gone.
The more interesting question would be what the model output and targets contain and how MSELoss should be used in this case as it seems you might still pass class indices to the loss function and I would then expect to see a shape mismatch next.