ParameterList
- class torch.nn.ParameterList(values=None)
Holds parameters in a list.
ParameterListcan be used like a regular Python list, but Tensors that areParameterare properly registered, and will be visible by all methods.
Holds parameters in a list.
ParameterList can be used like a regular Python
list, but Tensors that are Parameter are properly registered,
and will be visible by all methods.
ModuleNote that the constructor, assigning an element of the list, the
append() method and the extend()
method will convert any Tensor into Parameter.
parameters (iterable, optional) – an iterable of elements to add to the list.
Example:
class MyModule(nn.Module):
def __init__(self) -> None:
super().__init__()
self.params = nn.ParameterList(
[nn.Parameter(torch.randn(10, 10)) for i in range(10)]
)
def forward(self, x):
# ParameterList can act as an iterable, or be indexed using ints
for i, p in enumerate(self.params):
x = self.params[i // 2].mm(x) + p.mm(x)
return x
Append a given value at the end of the list.
value (Any) – value to append
Self
Append values from a Python iterable to the end of the list.
values (iterable) – iterable of values to append
Self
Return the extra representation of the module.