본문 바로가기

인공지능 공부

[pytorch] Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! 에러

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument mat1 in method wrapper_CUDA_addmm)

위와 같은 오류가 나서 찾아보기 시작했다.  

 

위의 오류는 데이터와 모델 등이 같은 곳에서 동작하지 않아서 생기는 오류였다.

 

이를 데이터와 모델 뒤에.to(device)를 하였는데도 같은 오류가 떴다.

 

 

 

huggingface에서 글을 하나 찾아서 보니 model을 실행 할 때가 아닌 만들고 나서 먼저 보내둬야 한다는 것을 알았다.

 

참고: https://discuss.huggingface.co/t/runtimeerror-expected-all-tensors-to-be-on-the-same-device-but-found-at-least-two-devices-cuda-1-and-cuda-0/39548

 

 

위와 사진처럼 모델 뒤에 to(device)를 해주었다.

 

  이후 학습은 잘 되었지만 

 

부분에 문제가 생겼고 이는 다시 cpu로 내려야 겠다고 생각을 하여 

이렇게 수정을 하니 성공적으로 동작 하게 되었다.

'인공지능 공부' 카테고리의 다른 글

지도학습과 비지도학습의 차이  (0) 2023.04.08