Skip to content
class

UninitializedParameter

extendsParameter
UninitializedParameter(data: Tensor | list[object] | None = None, requires_grad: bool = True)

A parameter that exists before its shape does.

A lazy layer cannot build its weights until it sees an input, but parameters() is read before that — by an optimizer, an EMA, a parameter-server shard — and whatever is read then is what those hold for the rest of the run. Returning nothing means they hold nothing, and the layer silently never trains.

So the object is created up front over a zero-element buffer and materialize fills it in place. What matters is that the object survives: id(param) is the same before and after, so a list captured early still names the weights that eventually exist.

Parameters

dataTensor | list | None= None
Initial values. None (default) yields a zero-sized placeholder parameter in the default dtype on the default device, useful when the actual shape is deferred until first forward (lazy modules). A Tensor is wrapped without a copy: the parameter shares the tensor's storage, as in the reference, so an in-place write through one is seen by the other (copy.deepcopy is what makes an independent one). A list / nested-list is converted via _to_impl.
requires_gradbool= True
Whether to record gradient flow through this parameter (default: True).

Notes

Lucid's engine optimizers capture TensorImpl pointers, one level below the Parameter, so preserving the Python object is necessary but not sufficient — see the deferred binding in lucid.optim.Optimizer, which is the other half.

Used by 4

Instance methods

1
fn

materialize

→None
materialize(data: Tensor)

Take on data's storage, shape and dtype, in place.

Parameters

dataTensor
The real parameter, already the right shape and initialised.

Raises

RuntimeError
If data is bool or an integer dtype, which cannot require gradients.

Notes

Rebinds _impl rather than copying into it: the buffer is a different size, and copy_from is shape-strict by design. The instance's class is rewritten to Parameter so nothing downstream keeps treating a fully-formed weight as pending.