class

ParameterList

extendsModule
ParameterList(parameters: list[Parameter] | None = None)
source

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= None
Initial list of 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]
Internal ordered mapping from string index to Parameter, inherited from Module.

Notes

  • forward is intentionally not implemented. Access individual parameters via indexing: self.scales[i].
  • Unlike ModuleList, this container holds Parameter objects (leaf tensors with requires_grad=True by 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)

dunder

__init__

None
__init__(parameters: list[Parameter] | None = None)
source

Initialise the ParameterList module. See the class docstring for parameter semantics.

fn

append

None
append(param: Parameter)
source

Append a module to the end of the ParameterList.

fn

extend

None
extend(parameters: Iterable[Parameter])
source

Append each module from an iterable to the ParameterList.

fn

forward

Tensor
forward(args: object = ())
source

Apply the contained modules to the input.

Parameters

None
No description.

Returns

Tensor

Output tensor produced by the contained modules.

dunder

__getitem__

Parameter
__getitem__(idx: int)
source

Return the child module(s) at the given index or slice.

dunder

__setitem__

None
__setitem__(idx: int, param: Parameter)
source

Replace the child module at the given index.

dunder

__len__

int
__len__()
source

Return the number of registered child modules.

dunder

__iter__

Iterator[Parameter]
__iter__()
source

Iterate over the registered child modules.