fn
ones_like
→Tensorones_like(t: Tensor, dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: _bool = False)Return an all-ones tensor with the same shape, dtype, and device as t.
Equivalent to lucid.ones(t.shape, dtype=t.dtype, device=t.device),
but infers metadata from an existing tensor. Every element satisfies
Parameters
tTensorReference tensor whose
shape, dtype, and device are
used as defaults.dtypelucid.dtypeOverride the data type. Defaults to
t.dtype.devicestr or lucid.deviceOverride the device. Defaults to
t.device.requires_gradboolEnable autograd tracking on the output. Default:
False.Returns
TensorAll-ones tensor shaped like t.
Notes
Multiplicative identity initialisation is used in layer-normalisation and group-normalisation to set the learnable scale parameter to at the start of training, so the network begins as a pure normalisation with no learned rescaling:
Examples
>>> import lucid
>>> x = lucid.randn(2, 8)
>>> gamma = lucid.ones_like(x)
>>> gamma.shape
(2, 8)
Initialise scale parameters of a normalisation layer:
>>> weight = lucid.ones_like(x, requires_grad=True)