本文用於記錄所在pytorch所遇到過的運行時錯誤,持續更新。
- 變量所在設備(CPU,GPU)不一致問題
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
可能原因:現在假設代碼要在GPU上運行,並且你已經進行my_model.to(device)
操作了。注意只有my_model
中的屬性(也就是self.
開頭的變量)纔會進行.to(device)
。如果出現這個錯誤,可能是有的中間變量需要手動再顯式地.to(device)
一下~