torch.nn.parameter.Parameter(data=None, requires_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