PyTorch中ReLU的inplace

0 - inplace

  在pytorch中,nn.ReLU(inplace=True)和nn.LeakyReLU(inplace=True)中存在inplace字段。该参数的inplace=True的意思是进行原地操作,例如:

  • x=x+5是对x的原地操作
  • y=x+5,x=y不是对x的原地操作

  所以,如果指定inplace=True,则对于上层网络传递下来的tensor直接进行修改,可以少存储变量y,节省运算内存。

inplace=True means that it will modify the input directly, without allocating 
any additional output. It can sometimes slightly decrease the memory usage, 
but may not always be a valid operation (because the original input is destroyed). 
However, if you don’t see an error, it means that your use case is valid.

  如果你使用了in-place operation而没有报错的话,那么你可以确定你的梯度计算是正确的。

1 - 参考资料

https://www.jianshu.com/p/8385aa74e2de

https://blog.csdn.net/york1996/article/details/81835873

转载于:https://www.cnblogs.com/CZiFan/p/10790765.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值