Rate this Page

Buffer#

classtorch.nn.parameter.Buffer(data=None,*,persistent=True)[source]#

A kind of Tensor that should not be considered a modelparameter. For example, BatchNorm’srunning_mean is not a parameter, but is part of the module’s state.

Buffers areTensor subclasses, that have avery special property when used withModule s – when they’reassigned as Module attributes they are automatically added to the list ofits buffers, and will appear e.g. inbuffers() iterator.Assigning a Tensor doesn’t have such effect. One can still assign a Tensor as explicitly by usingtheregister_buffer() function.

Parameters
  • data (Tensor) – buffer tensor.

  • persistent (bool,optional) – whether the buffer is part of the module’sstate_dict. Default:True