参考链接:Difference between ‘register_buffer’ and ‘register_parameter’ of PyTorch Module.
nn.Parameter(torch.randn(1))
- nn.Parameter is a subclass of torch.Tensor. Parameter class “doesn’t add any functionality other than automatically calling requires_grad.
- Model parameters are learned and updated using SGD during the training process.
- Parameters may be accessed through the
model.parameters()
method on the Module class.
register_buffer(‘buffer_name’, torch.randn(1))
- If you have parameters in your model, that should be saved and restored in the state_dict, but not trained by the optimizer, you should register them as buffers. Buffers won’t be returned in model.parameters(), so that the o