当前位置: 首页 > news >正文

织梦制作手机网站四川建筑职业技术学院教务网

织梦制作手机网站,四川建筑职业技术学院教务网,汕尾百度seo公司,可视化cms正文在后面#xff0c;往下拉即可~~~~~~~~~~~~ 欢迎各位深度学习的小伙伴订阅的我的专栏 Pytorch深度学习理论篇实战篇(2023版)专栏地址#xff1a; #x1f49b;Pytorch深度学习理论篇(2023版)https://blog.csdn.net/qq_39237205/category_12077968.html #x1f49a;Pyt…正文在后面往下拉即可~~~~~~~~~~~~ 欢迎各位深度学习的小伙伴订阅的我的专栏 Pytorch深度学习·理论篇实战篇(2023版)专栏地址 Pytorch深度学习·理论篇(2023版)https://blog.csdn.net/qq_39237205/category_12077968.html Pytorch深度学习·动手篇(2023版)https://blog.csdn.net/qq_39237205/category_12077994.html 正文开始 【就看这一篇就行】RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [256]] is at version 4; expected version 3 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True). 针对网上搜到的以下办法均无效的情况 1找到网络模型中的 inplace 操作将inplaceTrue改成 inplaceFalse例如torch.nn.ReLU(inplaceFalse) 2将代码中的“ab”之类的操作改为“c a b” 3将loss.backward()函数内的参数retain_graph值设置为True, loss.backward(retain_graphTrue)如果retain_graph设置为False计算过程中的中间变量使用完即被释放掉。 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑以上方案无效↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓正确解决方案如下↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 1、问题描述 提示在 loss.backward()报错 RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [256]] is at version 4; expected version 3 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True). 2、问题分析 在用PyTorch进行分布式训练时遇到以上错误。 日志的大概意思是用于梯度计算的变量通过inplace操作被修改。网上的一些解决方法基本是检查模型定义中是否有inplaceTrue 设置以及操作符。但是这两种方案都不能解决遇到的问题。 经过一些调试发现只有当某些特定情况下才会触发此报错。下面结合一个对比学习的例子并不是完整的脚本来简单描述 import torch import torch.nn as nnfrom torchvision.models import resnet50def main():model resnet50(num_classes256).cuda()model nn.parallel.DistributedDataParallel(model, device_ids[args.local_rank], find_unused_parametersTrue)criterion nn.MSELoss()optimizer torch.optim.SGD(model.parameters(),lr0.001,momentum0.99,weight_decay1e-4)for i in range(10):input0 torch.randn((4, 3, 224, 224), dtypetorch.float32).cuda()input2 torch.randn((4, 3, 224, 224), dtypetorch.float32).cuda()out1 model(input0)out2 model(input1)loss criterion(out1, out2)optimizer.zero_grad()loss.backward()optimizer.step()if __name__ __main__:main() 经过调试发现当使用nn.DataParallel并行训练或者单卡训练均可正常运行另外如果将两次模型调用集成到model中即通过out1, out2 model(input0, input1) 的方式在分布式训练下也不会报错。 由此可以猜测在分布式训练中如果对同一模型进行多次调用则会触发以上报错即 nn.parallel.DistributedDataParallel方法封装的模型forword()函数和backward()函数必须交替执行如果执行多个次forward()然后执行一次backward()则会报错。 那么解决此问题的入手点则可以聚焦到nn.parallel.DistributedDataParallel接口上。 通过查询PyTorch官方文档发现此接口下的两个参数 - find_unused_parameters: 如果模型的输出有不需要进行反向传播的此参数需要设置为True 若你的代码运行后卡住不动基本上就是该参数的问题。- broadcast_buffers: 该参数默认为True设置为True时在模型执行forward之前gpu0会把 buffer中的参数值全部覆盖到别的gpu上。 问题基本可以定位出来了即broadcast_buffersTrue导致参数被覆盖修改。 3、解决办法 # 在该出错文件上找到被调用的DistributedDataParallel()将broadcast_buffers设置为False model nn.parallel.DistributedDataParallel(model, device_ids[args.local_rank], broadcast_buffersFalse,find_unused_parametersTrue) RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [2048]] is at version 4; expected version 3 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
http://www.pierceye.com/news/367127/

相关文章:

  • wordpress手机加载不出来优化官网咨询
  • 平台网站建设预算表如何来做网站
  • 温州网站制作企业东莞网络推广公司电话
  • 网站建设的条件重庆那些网站
  • 伊犁网站制作大连甘井子区房价
  • 循环视频做网站背景win2012r2 建设网站
  • 建设网站制作汉狮团队义乌北苑编程网站开发公司
  • 网站开发公司会计处理滨州市住房和城乡建设局网站
  • 企业网站站内优化长尾关键词挖掘站长工具
  • 山东平台网站建设企业怎么做自己的品牌网站
  • 长沙seo网站排名杭州网站建设q479185700棒
  • 泰州网站建设搭建工程造价网
  • 网站流程优化c2c模式举例子
  • 帝国网站调用图片集网店平台有哪些
  • 做flash音乐网站的开题报告删除wordpress左上角
  • php网站开发学什么衡水大型网站建设
  • 广州网站开发软件平台wordpress 问号
  • 西安市建设干部学校网站厦门网站优化服务
  • 深圳市南山区住房和建设局官方网站如何把html网站改为asp网站
  • 网站建设有什么技术做dw网站图片怎么下载地址
  • 初中生如何做网站潍坊网站开发
  • 如何修改用织梦做的网站的模板价格对比网站开发
  • 单位建设网站的作用意义家在深圳坂田业主论坛
  • 网站什么时候备案好宜昌网站建设
  • 那个网站可以查询美做空基金竹中建设官方网站
  • 做直播网站找哪个网站网站平台推广方法
  • 查工程中标信息哪个网站成都网站建设 致尚
  • 做硅胶的网站wordpress googleapis
  • 做网站 简单外包常见的管理信息系统有哪些
  • 做网站一万静海网站开发