Misc
Utilities for reading and for writing neural network parameters
count_parameters(net)
¶
Get the number of parameters the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
net
|
Module
|
The torch module whose parameters will be counted. |
required |
Source code in evotorch/neuroevolution/net/misc.py
device_of_module(m, default=None)
¶
Get the device in which the module exists.
This function looks at the first parameter of the module, and returns its device. This function is not meant to be used on modules whose parameters exist on different devices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
Module
|
The module whose device is being queried. |
required |
default
|
Optional[Union[str, device]]
|
The fallback device to return if the module has no parameters. If this is left as None, the fallback device is assumed to be "cpu". |
None
|
Source code in evotorch/neuroevolution/net/misc.py
fill_parameters(net, vector)
¶
Fill the parameters of a torch module (net) from a vector.
No gradient information is kept.
The vector's length must be exactly the same with the number of parameters of the PyTorch module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
net
|
Module
|
The torch module whose parameter values will be filled. |
required |
vector
|
Tensor
|
A 1-D torch tensor which stores the parameter values. |
required |
Source code in evotorch/neuroevolution/net/misc.py
parameter_vector(net, *, device=None)
¶
Get all the parameters of a torch module (net) into a vector
No gradient information is kept.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
net
|
Module
|
The torch module whose parameters will be extracted. |
required |
device
|
Optional[Device]
|
The device in which the parameter vector will be constructed. If the network has parameter across multiple devices, you can specify this argument so that concatenation of all the parameters will be successful. |
None
|