ParameterDict
-
class torch.nn.ParameterDict(parameters=None)[source] -
Holds parameters in a dictionary.
ParameterDict can be indexed like a regular Python dictionary, but parameters it contains are properly registered, and will be visible by all Module methods.
ParameterDictis an ordered dictionary that respects- the order of insertion, and
- in
update(), the order of the mergedOrderedDictor anotherParameterDict(the argument toupdate()).
Note that
update()with other unordered mapping types (e.g., Python’s plaindict) does not preserve the order of the merged mapping.- Parameters
-
parameters (iterable, optional) – a mapping (dictionary) of (string :
Parameter) or an iterable of key-value pairs of type (string,Parameter)
Example:
class MyModule(nn.Module): def __init__(self): super(MyModule, self).__init__() self.params = nn.ParameterDict({ 'left': nn.Parameter(torch.randn(5, 10)), 'right': nn.Parameter(torch.randn(5, 10)) }) def forward(self, x, choice): x = self.params[choice].mm(x) return x-
clear()[source] -
Remove all items from the ParameterDict.
-
items()[source] -
Return an iterable of the ParameterDict key/value pairs.
-
keys()[source] -
Return an iterable of the ParameterDict keys.
-
pop(key)[source] -
Remove key from the ParameterDict and return its parameter.
- Parameters
-
key (string) – key to pop from the ParameterDict
-
update(parameters)[source] -
Update the
ParameterDictwith the key-value pairs from a mapping or an iterable, overwriting existing keys.Note
If
parametersis anOrderedDict, aParameterDict, or an iterable of key-value pairs, the order of new elements in it is preserved.- Parameters
-
parameters (iterable) – a mapping (dictionary) from string to
Parameter, or an iterable of key-value pairs of type (string,Parameter)
-
values()[source] -
Return an iterable of the ParameterDict values.
© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.nn.ParameterDict.html