fn
randn_like
→Tensorrandn_like(t: Tensor, dtype: DTypeLike = None, device: DeviceLike = None, requires_grad: _bool = False)Return a random tensor with the same shape, dtype, and device as t.
Equivalent to lucid.randn(t.shape, dtype=t.dtype, device=t.device),
inferring all metadata from an existing tensor.
Each element is drawn independently from the standard normal:
Parameters
tTensorReference tensor whose
shape, dtype, and device are
inherited unless overridden.dtypelucid.dtypeOverride the data type. Defaults to
t.dtype.devicestr or lucid.deviceOverride the device. Defaults to
t.device.requires_gradboolEnable autograd tracking. Default:
False.Returns
TensorStandard-normal random tensor shaped like t.
Notes
A common pattern in noise injection regularisation is to add scaled Gaussian noise to activations or weights during training:
randn_like makes this concise and device-safe:
.. code-block:: python
x_noisy = x + noise_scale * lucid.randn_like(x)
Examples
>>> import lucid
>>> w = lucid.zeros(256, 512, dtype=lucid.float16, device="metal")
>>> noise = lucid.randn_like(w)
>>> noise.shape, noise.dtype, noise.device
((256, 512), lucid.float16, lucid.device('metal'))