Buffer — PyTorch 2.7 documentation (original) (raw)
class torch.nn.parameter.Buffer(data=None, *, persistent=True)[source][source]¶
A kind of Tensor that should not be considered a model parameter. For example, BatchNorm’s running_mean
is not a parameter, but is part of the module’s state.
Buffers 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 buffers, and will appear e.g. in buffers() iterator. Assigning a Tensor doesn’t have such effect. One can still assign a Tensor as explicitly by using the register_buffer() function.
Parameters