當數據和要加載的模型不在同一個cuda上時的處理方法


問題:
c = F.relu(policy_model.Q.c1(exp_list[i][k].unsqueeze(0)))
error:

*** RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:2! (when checking argument for argument weight in
method wrapper__cudnn_convolution)

原因:

       訓練好的Model和待使用的數據分別在兩個cuda上,因此出現錯誤。  

解決方法:

       在加載模型時,設置加載到數據所在的cuda上。確保模型和數據在同一個cuda上。

  即把:

     policy_model = torch.load(PATH)

       改為:

    policy_model = torch.load(PATH, map_location=torch.device('cuda:1'))

       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM