在跑模型的时候出现了上述报错,有以下两个解决办法 将优化器的 foreach=False 避免使用 torch.set_default_dtype(torch.float64) 参考链接: Tensors of the same index must be on the same device and the same dtype except `step` tensors that can be CPU and float32 notwithstanding - PyTorch Forums 参考链接2: python - PyTorch: Tensors of the same index must be on the same device and the same dtype except `step` tensors that can be CPU and float32 notwithstanding - Stack Overflow