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__ sees that it is a Parameter 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
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= TrueTrue).Attributes
_ is_ parameterboolTrue; False on Tensor) that
lucid.serialization reads to tell a parameter from a tensor
without importing lucid.nn.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. Being a Parameter is the sole difference visible to
Module: a registered parameter name takes only a Parameter or
None.
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 ...)]Used by 88
- lucid.compile._entry.function
- lucid.compile._entry.module
- lucid.compile._entry.step
- lucid.compile._optim.lbfgs
- lucid.nn
- lucid.nn._state_dict
- lucid.nn._swap
- lucid.nn.module
- lucid.nn.modules._conv_common
- lucid.nn.modules._lazy
- lucid.nn.modules._slope
- lucid.nn.modules.attention
… 76 more