程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

pythonRuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing

編輯:Python

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

  • fork and spawn Are different ways to build subprocesses :
forkspawn Bifurcation lay eggs Inherit Not inherited Build a child process from scratch , The data of the parent process is copied to the space of the child process , Own your own Python Interpreter The variable has the same... As in the parent process idN Import modules at the beginning of each child process Subprocess get at name == main Variables defined in the block N

Solution

if __name__=='__main__':
torch.multiprocessing.set_start_method('spawn')

Reference and more

  • The log says “RuntimeError: Cannot re-initialize CUDA in forked subprocess”
  • https://britishgeologicalsurvey.github.io/science/python-forking-vs-spawn/
  • https://www.pythonf.cn/read/65459
  • https://stackoverflow.com/questions/64095876/multiprocessing-fork-vs-spawn

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved