学习随笔:torch.nn.Parameter()

官方解释

torch.nn.parameter.Parameter(data=Nonerequires_grad=True)

官方解释为

A kind of Tensor that is to be considered a module parameter.

Parameters are Tensor subclasses, that have a very special property when used with Module s - when they’re assigned as Module attributes they are automatically added to the list of its parameters, and will appear e.g. in parameters() iterator. Assigning a Tensor doesn’t have such effect. This is because one might want to cache some temporary state, like last hidden state of the RNN, in the model. If there was no such class as Parameter, these temporaries would get registered too.

参数是 Tensor 子类,当与模块一起使用时,它们具有非常特殊的属性 - 当它们被指定为模块属性时,它们会自动添加到其参数列表中,并且会出现在 parameters() 迭代器中。分配 Tensor 不会产生这种效果。这是因为人们可能希望在模型中缓存一些临时状态,例如 RNN 的最后隐藏状态。如果没有 Parameter 这样的类,这些临时变量也会被注册。

简而言之:可以将一个没有梯度的、不可训练的tensor,转换成一个有梯度、可训练的tensor

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值