RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you

Pytorch报错:

RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the ‘spawn’ start method

问题背景:

在dataloader中,使用了多线程处理数据,并且自定义了collate_func

解决方案:

如果不是特别大的消耗,可以取消调用该函数的cuda方法

如果一定要使用,Python 3 支持进程之间共享 CUDA 张量,我们可以使用 spawn 或forkserver 启动此类方法

使用数据并行化方法是目前pytorch官方比较推荐的方法

猜你喜欢

转载自blog.csdn.net/ftimes/article/details/120391671