Skip to content

Runtime Error: 'lengths' argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor #1300

@goobill

Description

@goobill

I've been following the chatbot tutorial (https://pytorch.org/tutorials/beginner/chatbot_tutorial.html#run-model) and discovered the code does not run out of the box for me.

After training the model and inputting custom test data for the bot to respond I get the error:

RuntimeError: 'lengths' argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

I found a similar issue with a fix on the Pytorch Github issues, pytorch/pytorch#43227

Their solution was to use the .cpu() on the length argument.

On line 683, of https://github.com/pytorch/tutorials/blob/master/beginner_source/chatbot_tutorial.py, I applied the .cpu() method to the variable input_sequence and that resolved my issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions