首页 > 其他分享 >DDP运行报错(单卡无错):ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1)

DDP运行报错(单卡无错):ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1)

时间:2023-04-25 11:48:35浏览次数:37  
标签:loss DDP parameters elastic torch module 报错 forward your

使用DDP时出现错误,但是单卡跑无错误。
错误记录如下:

RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by passing the keyword argument find_unused_parameters=True to torch.nn.parallel.DistributedDataParallel, and by
making sure all forward function outputs participate in calculating loss.
If you already have done the above, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's forward function. Please include the loss function and the structure of the return value of forward of your module when reporting this issue (e.g. list, dict, iterable).
Parameter indices which did not receive grad for rank 1: 4 5 6 7
In addition, you can set the environment variable TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print out information about which particular parameters did not receive gradient on this rank as part of this error

一度以为是DDP的bug,仔细阅读报错发现,关键在于

This error indicates that your module has parameters that were not used in producing loss.

即有参数未参与到loss生成过程中,换句话说就是有参数在init中定义,但是未在forward中使用,就会造成这样的结果。原来为了不断调优模型,我将几个待选网络模块都写在了init函数中,然后这样只需要在forward中改变调用的模块就可以了。在单机运行中这样是可行的无错的,但是在DDP中由于需要多卡进行loss的reduce,为了防止出错,ddp就强行设置了这样的规则,但是可以通过如上错误提示里面的参数更改此设置,但是尽量不要修改。
解决方法:将init函数中未使用到的模块注释掉即可。

标签:loss,DDP,parameters,elastic,torch,module,报错,forward,your
From: https://www.cnblogs.com/fireinstone/p/17352130.html

相关文章

  • 使用PyTorch和Flower 进行联邦学习
    本文将介绍如何使用Flower构建现有机器学习工作的联邦学习版本。我们将使用PyTorch在CIFAR-10数据集上训练卷积神经网络,然后将展示如何修改训练代码以联邦的方式运行训练。完整文章:https://avoid.overfit.cn/post/8d05a12c208c4f499573c9966d0fe415......
  • Redis 报错总结一
    Redis报错总结一Invalidargumentduringstartup:Failedtoopenthe.conffile:redis.window.conf【1】cmd运行redis-server.exeredis.windows.conf报错:提示找不到配置文件。加上文件路径:可以启动成功【2】解决办法【2.1】便捷启动1cd到redis安装目录,输入以......
  • 解决npm install各种报错的6种方案 Error: Command failed: cmd.exe autoreconf -ivf
    报错示例:Error:Commandfailed:C:\Windows\system32\cmd.exe/s/c"autoreconf-ivf"gifsiclepre-buildtestfailedPSG:\code_all\my_webpack_webgl2021-5-17-dev_01\three151-demo>npminstallnpmnoticeBeginningOctober4,2021,allconnect......
  • Navicat连接Oracle报错:ORA-28547...
    使用Navicat连接正常的oracle数据库时,提示 可能是因为Navicat本地的OCI版本与Oracle数据库版本不符造成的,可以下载对应的OCI版本在Navicat中使用。1.下载OCI搜索oracleinstantclient找到相关下载地址OracleInstantClientDownloads根据实际oracle数据库版本选择对应in......
  • 解决Some index files failed to download.They have been ignored, or old ones used
    使用pingwww.baidu.com测试一下网络,如果出现:ping:www.baidu.com:Temporaryfailureinnameresolution就是网络问题了以下是解决办法,修改两处后重启即可,下面详细说明第一处修改的地方:sudovim/etc/systemd/resolved.conf修改DNS如下:[Resolve]DNS=8.8.8.8#FallbackD......
  • Python学习笔记--json序列化时间报错-改源码
    问题:转换时间报错执行代码为:importjsonfromdatetimeimportdate,datetimed={"time1":date.today(),"time2":datetime.today()}res=json.dumps(d)#报错  TypeError:ObjectoftypedateisnotJSONserializable方案1:手动转换str()方案2:继承类......
  • 【c&c++】VScode报错error: ‘::main‘ must return ‘int‘ void main()
    在运行指针时终端出现error:‘::main’mustreturn‘int’voidmain()错误。源代码如下:#include<stdio.h>voidmain(){inta,*p,b,c,d,e;a=100;p=&a;/*(*&a)先进行&a运算,得a的地址,再进行*运算,即变量a的值*/b=*&a;printf("a=%d\n",a);......
  • Pytorch可视化热力图
     可视化热力图可以有两种方式:1)特征图可视化,将各通道特征的最大值作为热力图像素值,进行可视化——可以参考博客,一种比较灵活的特征图保存方式2)根据梯度值结合特征图计算热力图,热力图的显示的重点是梯度高的地方,也是网络关注的重点 基于梯度进行热力图可视化有一些工作,如grad......
  • ElementUI: Uncaught (in promise) cancel 报错
    场景:使用element confirm组件时,点击【取消】按钮,提示错误 Uncaught(inpromise)cancel 代码如下:open(){this.$confirm('此操作将永久删除该文件,是否继续?','提示',{confirmButtonText:'确定',cancelButtonText:'取消',......
  • pip 安装库是报错ERROR: Cannot unpack file C:\Users\LX\AppData\Local\Temp\p
    使用pip安装python库的时候出现报错:ERROR:CannotunpackfileC:\Users\LX\AppData\Local\Temp\pip-unpack-apk_4xkw\simple(downloadedfromC:\Users\LX\AppData\Local\Temp\pip-req-build-htbv29co,content-type:text/html;charset=utf-8);cannotdetectarch......