caught runtimeerror in replica 0 on device 0 错误解决
有时候我们在运行python|深度学习的bert代码时会报错:caught runtimeerror in replica 0 on device 0
查阅了很多解决方案,最终有效的是下面方案:
解决方案
在Bert模型代码文件里的将数据类型 dtype=next(self.parameters()).dtype 修改为 dtype=torch.float32
如:
modeling.py文件中
extended_attention_mask = extended_attention_mask.to(dtype=next(self.parameters()).dtype) # fp16 compatibility
修改为:
extended_attention_mask = extended_attention_mask.to(dtype=torch.float32) # fp16 compatibility
有时修改modeling.py文件中的即可,有时需要修改modeling_bert.py中的,自己试着调试即可!!