Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: expected scalar type Long but found Int #17

Open
Memerlin opened this issue May 2, 2023 · 1 comment
Open

RuntimeError: expected scalar type Long but found Int #17

Memerlin opened this issue May 2, 2023 · 1 comment

Comments

@Memerlin
Copy link

Memerlin commented May 2, 2023

When I try to run train.py, I run into this error:

Traceback (most recent call last):
  File "C:\Users\Lucy\Documents\Chatbot maybe\train.py", line 83, in <module>
    loss = criterion(outputs, labels)
  File "C:\Users\Lucy\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "C:\Users\Lucy\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 1174, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "C:\Users\Lucy\anaconda3\envs\pytorch\lib\site-packages\torch\nn\functional.py", line 3029, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: expected scalar type Long but found Int
@LuluW8071
Copy link

The label for reposnse in train_dataloader should be Long.

In train.py

labels = labels.to(dtype=torch.long).to(device)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants