Parameter
TensorParameter(data: Tensor | list[object] | None = None, requires_grad: bool = True)A Tensor subclass that Module recognises as a learnable parameter.
When an instance is bound as an attribute of a Module, the module's
__setattr__ hook detects the _is_parameter marker and routes it
into the module's _parameters registry instead of treating it as a
plain Tensor attribute. This is what makes Module.parameters() and
Module.named_parameters() discover the tensor automatically — no
manual registration call is needed.
By default the underlying tensor has requires_grad=True, so it
participates in the autograd graph from the moment of construction.
Pass requires_grad=False for "buffer-like" learnables (e.g.
BatchNorm's running mean) that should still be tracked under
state_dict but shouldn't accumulate gradients.
Parameters
dataTensor | list | None= NoneNone (default) yields a zero-sized
placeholder F32/CPU parameter, useful when the actual shape is
deferred until first forward (lazy modules). A Tensor
clones its storage so the new parameter is independent of the
source. A list / nested-list is converted via _to_impl.requires_gradbool= TrueTrue).Attributes
_is_parameterboolTrue) consumed by Module's
attribute-binding logic.Notes
Subclassing Tensor (rather than wrapping one) keeps every tensor
operation usable on a Parameter without unwrap boilerplate — e.g.
p + 1 returns a Tensor, while p.data and p.grad still
work. The _is_parameter class attribute is the sole behavioural
difference visible to Module.
Examples
>>> import lucid
>>> from lucid.nn import Parameter, Module
>>> class Affine(Module):
... def __init__(self):
... super().__init__()
... self.w = Parameter(lucid.randn(3)) # auto-registered
... self.b = Parameter(lucid.zeros(3))
>>> m = Affine()
>>> list(m.named_parameters()) # both surface here automatically
[('w', Parameter ...), ('b', Parameter ...)]