Register Buffer
What does Pytorch register_buffer do?
register_buffersaves the parameters instate_dict, but no gradients will be computed (hence no updates).model.parameters()will not return the params saved byregister_buffer.- Examples:
running_mean,running_stdin Batch Normmaskin causal self attention block in Transformer.
- Since it is in
state_dict, you will not lose it by save and load the models. register_parameterwill save the parameters instate_dictand will be updated by backprop.- It is equivalent to
self.my_param = nn.Parameter(torch.randn(10)).
- It is equivalent to
References:
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.