Skip to content

Misleading message: "RuntimeError: Input type (Variable) and weight type (Variable) should be the same" #5808

@PiotrCzapla

Description

@PiotrCzapla

It took me quite a while to figure out what this message means (it was my very first model):

RuntimeError: Input type (Variable) and weight type (Variable) should be the same

It appears when input variable is on GPU and weight is on CPU. Here is a minimal code to replicate the error:

filters = torch.randn(8,4,3,3)
inputs = torch.randn(1,4,5,5)
F.conv2d(inputs.cuda(), filters, padding=1)

If one removes .cuda() everything starts to work fine.

I wasn't able to find anything on google when I searched for the phrase above so I've thought It make sense to report it as an issue so that next person may have more luck. I'm leaving it open in case you want to improve the message, but I will understand if you close it. Either way is ok and should help other newbies.

Environment details:

  • PyTorch version: 0.4.0a0+cdd0feb,
  • CUDA/cuDNN version: I've used .Dockerfile to compile it

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