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, or plain tensors -- each
wrapped in a Parameter first, as every entry point that
adds one does. 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.
A plain tensor is wrapped in a Parameter, as the
reference does for every entry point that adds one.
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 parameter at the given index, as the reference does --
None if that slot was explicitly cleared by assignment, never
an assertion failure for reading back what was legitimately put
there (LCD-571).
Iterate over the registered parameters, None included for a
slot explicitly cleared by assignment (LCD-571).
Return the number of registered child modules.
Replace the parameter at the given index.
A plain tensor is wrapped in a Parameter, as the reference
does; anything else that is not a Parameter is a TypeError
from the assignment.