mindspore.nn.Buffer

View Source On Gitee
class mindspore.nn.Buffer(data=None, *, persistent=True)[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 Cell's state.

Buffers are Tensor subclasses, that have a very special property when used with Cell s: when they're assigned as Cell attributes they are automatically added to the list of its buffers, and will appear e.g. in mindspore.nn.Cell.buffers() iterator. Assigning a tensor doesn't have such effect. One can still assign a tensor as a buffer explicitly by using the mindspore.nn.Cell.register_buffer() function.

Parameters

data (Tensor) – buffer tensor.

Keyword Arguments

persistent (bool, optional) – whether the buffer is part of the Cell's state_dict. Default True.