成功解决tensorflow.python.framework.errors_impl.InvalidArgumentError报错问题
生活随笔
收集整理的這篇文章主要介紹了
成功解决tensorflow.python.framework.errors_impl.InvalidArgumentError报错问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題描述:在使用TensorFlow2.2訓練模型時,加入多GPU訓練出現如下錯誤
tensorflow.python.framework.errors_impl.InvalidArgumentError: No OpKernel was registered to support Op 'NcclAllReduce' used by {{node NcclAllReduce}} with these attrs: [reduction="sum", shared_name="c1", T=DT_FLOAT, num_devices=2] Registered devices: [CPU, GPU, XLA_CPU, XLA_GPU] Registered kernels:<no registered kernels>[[NcclAllReduce]] [Op:__inference_train_function_81214]這個錯誤是發生在使用多個GPU進行并行訓練的時候,使用單個GPU訓練的時候并沒有報錯。
運行環境:
- 訓練的模型yolox
- 系統:Win10
- tensorflow-gpu版本:2.2.0
- 使用2張GPU
報錯原因:
MirroredStrategy默認使用NCCL進行跨設備通信,而NCCL在Windows上不可用,也就是說這種默認的多GPU分布式訓練模式不支持win系統;所以需要修改多GPU訓練模式。
解決問題:
Ctrl+F,在train.py文件中檢索‘strategy’關鍵詞,發現如下
添加訓練模式如下:
if ngpus_per_node > 1:strategy = tf.distribute.MirroredStrategy(devices=["/gpu:0", "/gpu:1"], cross_device_ops=tf.distribute.HierarchicalCopyAllReduce())else:strategy = Noneprint('Number of devices: {}'.format(ngpus_per_node))錯誤消失,模型成功開始訓練了!
不容易啊,排查了整整一上午,記錄一下!!網上的介紹沒有明確說怎么修改,完全知不道怎么改,后來仔細讀了下面的GPU分布式訓練才改對。
參考網頁:多GPU分布式訓練;錯誤問題原因。
總結
以上是生活随笔為你收集整理的成功解决tensorflow.python.framework.errors_impl.InvalidArgumentError报错问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 汽车驱动力及发动机转矩曲线在python
- 下一篇: 哪吒:若求职不易,那就跟它斗争到底