在模型运行过程中,脚本突然卡死。单卡训练过程时,表现为长时间日志不打印;多卡训练过程时,表现为其他进程由于连不上这台机器超时退出,但卡死的进程仍然存在没有退出。
当python版本为3.8-3.11,由于Python本身问题,底层在非二进制场景下执行算子编译时,如果用户脚本侧使用fork的方式起多进程,可能出现子进程锁死,启动失败。
import multiprocessing as mp w=mp.Process(target=func, args=('xxxx',)) w.start()
import multiprocessing as mp ctx = mp.get_context('spawn') w=ctx.Process(target=func, args=('xxxx',)) w.start()
将fork方式进行如下修改,即可使用forkserver方式启动子进程。
import multiprocessing as mp ctx = mp.get_context('forkserver') w=ctx.Process(target=func, args=('xxxx',)) w.start()
import multiprocessing as mp torch_npu.npu.synchronize() w=mp.Process(target=func, args=('xxxx',)) w.start()
torch_npu.npu.set_compile_mode(jit_compile=False)