ParameterList
ModuleParameterList(parameters: list[Parameter] | None = None)A list-like container that registers Parameter objects with the module.
ParameterList stores an ordered sequence of Parameter leaf tensors
and registers each one via register_parameter. This means every stored
parameter appears in parameters(), participates in gradient tracking,
and is included in state_dict() / load_state_dict.
It is semantically equivalent to assigning a list of Parameter\s as
attributes of a module, but is the correct approach when the number of
parameters is data-dependent or only known at runtime.
Parameters
parameterslist[Parameter] or None= NoneParameter objects. Each is registered under its
zero-based integer index formatted as a string. Pass None
(default) for an empty list.Attributes
_parametersOrderedDict[str, Parameter | None]Parameter, inherited
from Module.Notes
forwardis intentionally not implemented. Access individual parameters via indexing:self.scales[i].- Unlike
ModuleList, this container holdsParameterobjects (leaf tensors withrequires_grad=Trueby default), not arbitrary modules.
Examples
**Per-layer learnable temperature scales (e.g. knowledge distillation):**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> class ScaledDistiller(nn.Module):
... def __init__(self, n_layers: int) -> None:
... super().__init__()
... self.scales = nn.ParameterList(
... [nn.Parameter(lucid.ones(1)) for _ in range(n_layers)]
... )
...
... def forward(self, feats: list[lucid.Tensor]) -> list[lucid.Tensor]:
... return [f * self.scales[i] for i, f in enumerate(feats)]
>>>
>>> distiller = ScaledDistiller(n_layers=6)
**Dynamically growing learnable biases:**
>>> bias_bank = nn.ParameterList()
>>> for _ in range(4):
... bias_bank.append(nn.Parameter(lucid.zeros(128)))
>>> # All 4 biases visible to optimizer:
>>> n_params = sum(p.numel() for p in bias_bank.parameters())Methods (8)
__init__
→None__init__(parameters: list[Parameter] | None = None)Initialise the ParameterList module. See the class docstring for parameter semantics.
append
→Noneappend(param: Parameter)Append a module to the end of the ParameterList.
extend
→Noneextend(parameters: Iterable[Parameter])Append each module from an iterable to the ParameterList.
forward
→Tensorforward(args: object = ())Apply the contained modules to the input.
Parameters
NoneReturns
TensorOutput tensor produced by the contained modules.
__getitem__
→Parameter__getitem__(idx: int)Return the child module(s) at the given index or slice.
__setitem__
→None__setitem__(idx: int, param: Parameter)Replace the child module at the given index.
__len__
→int__len__()Return the number of registered child modules.
__iter__
→Iterator[Parameter]__iter__()Iterate over the registered child modules.