fn

ones_

Tensor
ones_(tensor: Tensor)
source

Fill tensor in-place with ones.

Convenience wrapper around constant_ with val=1.0. The canonical use case is the gain (gamma) parameter of normalisation layers (BatchNorm, LayerNorm, GroupNorm) so the layer initially acts as the identity scaling.

Parameters

tensorTensor
Tensor to fill in place; any shape is accepted.

Returns

Tensor

tensor (mutated) for chaining.

Notes

Equivalent to constant_ (tensor, 1.0).

Examples

>>> import lucid
>>> from lucid.nn.init import ones_
>>> gamma = lucid.empty(64)
>>> ones_(gamma)