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
Parameter 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())Used by 1
Constructors
1Instance methods
3Append a module to the end of the ParameterList.
Append each module from an iterable to the ParameterList.
Apply the contained modules to the input.
Parameters
NoneReturns
TensorOutput tensor produced by the contained modules.
Dunder methods
4Return the child module(s) at the given index or slice.
Iterate over the registered child modules.
Return the number of registered child modules.
Replace the child module at the given index.