本帖主要汇总了本人在Python中遇到的各种问题,持续更新。
1、RuntimeError: module must have its parameters and buffers on device cuda:1 (device_ids[0]) but found
PyTorch框架下,使用torch.nn.DataParallel进行多卡并行计算中可能会遇到该问题,是由于在多卡运算时主卡设置所导致。在多卡并行计算时,所使用的显卡中必须包含主卡,否则就会产生该问题。
在默认情况下,标号为0的显卡为主卡,如主机中有8块显卡,那么每张显卡的默认标号为[0,1,2,3,4,5,6,7],主卡为0号显卡,在多卡并行计算时,必须使用0号显卡,因为该显卡为主卡。如下代码中,主卡没有参与运算,就会导致该错误。
解决方案参考:https://blog.csdn.net/qq_32797059/article/details/96001647
2、 Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings' Current thread 0x00007f728860d700 (most recent call first): Aborted (core dumped)
该问题一般是由于系统中存在其余版本Python互相冲突或者Python卸载残留所导致,可以通过查看当前系统中环境变量中存在的Python环境变量路径,删除多余和无效的环境变量,将有效的环境变量添加进去即可。
解决方案参考:https://blog.csdn.net/qq_32797059/article/details/101602214