Parameters Conversion#
- initialize_module(module: torch.nn.modules.module.Module, vec: torch.Tensor, clone=True, detach=True)[source]#
initializes a module's parameters with a 1-D vector
- Parameters
module (Module) -- module to initialize weights
vec (Tensor) -- a 1-D Tensor
clone (bool, optional) -- clones the vector before initilization. Defaults to True.
detach (bool, optional) -- detaches the output before the initialization. Defaults to True.
- vector_to_named_parameters_like(vec: torch.Tensor, named_parameters_like: collections.OrderedDict) collections.OrderedDict [source]#
Convert one vector to new named parameters like the ones provided
- Parameters
vec (Tensor) -- a single vector represents the parameters of a model.
parameters (OrderedDict) -- a dictioanry of Tensors that are the parameters of a model. This is only used to get the sizes and keys. New parametere are defined.
- vector_to_parameters_like(vec, parameters_like)[source]#
Convert one vector to new parameters like the ones provided
- Parameters
vec (Tensor) -- a single vector represents the parameters of a model.
parameters (Iterable[Tensor]) -- an iterator of Tensors that are the parameters of a model. This is only used to get the sizes. New parametere are defined.
- vectorize_module(module: torch.nn.modules.module.Module, clone=True, detach=True)[source]#
convert parameters of a module to a vector
- Parameters
module (Module) -- module to convert the parameters of
clone (bool, optional) -- clones the output. Defaults to True.
detach (bool, optional) -- detaches the output. Defaults to True.
- Returns
Module -- 1-D Tensor of all parameters in the module
- vectorize_module_grads(module: torch.nn.modules.module.Module, clone=True, detach=True)[source]#
convert parameters gradients of a module to a vector
- Parameters
module (Module) -- module to convert the parameters of
clone (bool, optional) -- clones the output. Defaults to True.
detach (bool, optional) -- detaches the output. Defaults to True.
- Returns
Module --
- 1-D Tensor of gradients of all parameters in the module. None if at
least grad of one children deos not exist.