【笔记】RuntimeError: Trying to backward through the graph a second time:将无关变量的梯度回传关系撤销

问题: RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results hav

问题:

RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed. Specify retain_graph=True when calling .backward() or autograd.grad() the first time.

解决办法: 首先应该明白一件事,与XXX.backward() 中 XXX 有计算关系的所有变量均存在

grad_fn 关系,梯度回传的目的是为了更新网络中权重和偏移量的值,所有与梯度回传过程中计算权重和偏移量无关的变量均应 .detach() 处理,避免发生此类错误。

reference:

报错RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed - Rogn - 博客园

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755028237a5228615.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信