본문 바로가기
프로그래밍/Python

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same 에러해결

by Leeys 2022. 4. 5.
반응형

개발환경

 

- ubuntu18.04

- python3.7

 

 

1. Problem

 

RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

pytorch로 학습을 할 때 input type과 weight type이 같아야만 한다는 에러가 발생

 

 

2. Reason

 

GPU로 학습을 할 때 model이나 dataset를 GPU에 설정하지 않았기 때문에 발생

 

 

 

3. Solution

 

torch.tensor(..., device="cuda") 
torch.tensor(...).cuda() 
torch.tensor(...).to("cuda")

model.to("cuda")

dataset이나 model을 GPU에 올려놓도록 하자!

반응형

댓글