DLLXW / baby-llama2-chinese

用于从头预训练+SFT一个小参数量的中文LLaMa2的仓库;24G单卡即可运行得到一个具备简单中文问答能力的chat-llama2.
MIT License
2.34k stars 288 forks source link

fix: multi gpu ddp save error #56

Closed billvsme closed 6 months ago

billvsme commented 6 months ago

当使用超过1个cpu,并且使用ddp的时候,save模型的代码if和else里的torch.save分别会被LOCAL_RANK=0以及LOCAL_RANK>=1的进程执行,会导致同时保存多次模型数据到同一个文件当中,导致save的数据torch.load报错

RuntimeError: PytorchStreamReader failed reading file byteorder: invalid header or archive is corrupted

当2个gpu执行时:

# 满足 if 条件
ddp = True , LOCAL_RANK=0

# 满足 else 条件
ddp = True,  LOCAL_RANK=1

导致save了2次