Hello everyone, I am Miaomiao who loves programming. Double 985 master's degree, now working as a full-stack engineer, keen to apply data thinking to work and life. Engaged in machine learning and related front-end and back-end development work. He has won many top rankings in competitions such as Alibaba Cloud, HKUST Xunfei, and CCF. Now he is a CSDN blog expert and a high-quality creator in the field of artificial intelligence. I like to summarize and summarize the knowledge I have learned through blog creation, which not only forms a deep and unique understanding, but also helps novices get started quickly.
This article mainly introduces the solution of RuntimeError: Expected all tensors to be on the same device, but found at least two devices, hoping to help students who are learning python.
Article directory
1. Problem description
Today, when using a large model for token generation (model.generate), the error message "RuntimeError: Expected all tensors to be on the same device, but found at least two devices" appeared. The specific error message is shown in the figure below:
After personal practice, I finally found a solution to the problem, and finally summarized the step-by-step operation process as follows. I hope it can help students who encounter the same bug.