Pytorch参数inplace详解


官方文档

Relu


Applies the rectified linear unit function element-wise:


Parameters

  • inplace – can optionally do the operation in-place. Default: False

解释inplace=True含义

inplace=Flase的情况

上图的这种传递类似C语言的值传递,input丢进去之后,给形参复制了一份值,形参和实参不指向同一块地址。

inplace=True的情况

上图设置了inplace=True这种情况之后,丢进去的input,类似C语言的地址传递,进去之后在计算的过程中直接作用于input,返回的output的地址也和input一致。

引用

(https://blog.csdn.net/manmanking/article/details/104830822)
官方文档 (https://pytorch.org/docs/stable/generated/torch.nn.ReLU.html?highlight=relu#torch.nn.ReLU)


文章作者: Jelly
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Jelly !
  目录