Skip to content
class

Parameter

extendsTensor
Parameter(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

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).

Attributes

_is_parameterbool
Class-level marker (always True; 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

… 76 more

Constructors

1
dunder

__init__

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

Initialise the instance. See the class docstring for parameter semantics.

Dunder methods

1
dunder

__repr__

→str
__repr__()

Return a developer-facing string representation of the instance.