analogvnn.parameter.PseudoParameter
#
Module Contents#
Classes#
A parameterized parameter which acts like a normal parameter during gradient updates. |
- class analogvnn.parameter.PseudoParameter.PseudoParameter(data=None, requires_grad=True, transformation=None)[source]#
Bases:
torch.nn.Module
A parameterized parameter which acts like a normal parameter during gradient updates.
PyTorch’s ParameterizedParameters vs AnalogVNN’s PseudoParameters:
- Similarity (Forward or Parameterizing the data):
> Data -> ParameterizingModel -> Parameterized Data
Difference (Backward or Gradient Calculations): - ParameterizedParameters
> Parameterized Data -> ParameterizingModel -> Data
PseudoParameters > Parameterized Data -> Data
- Variables:
_transformation (Callable) – the transformation.
_transformed (nn.Parameter) – the transformed parameter.
- Properties:
grad (Tensor): the gradient of the parameter. module (PseudoParameterModule): the module that wraps the parameter and the transformation. transformation (Callable): the transformation.
- property transformation[source]#
Returns the transformation.
- Returns:
the transformation.
- Return type:
Callable
- static identity(x: Any) Any [source]#
The identity function.
- Parameters:
x (Any) – the input tensor.
- Returns:
the input tensor.
- Return type:
Any
- __call__(*args, **kwargs)[source]#
Transforms the parameter.
- Parameters:
*args – additional arguments.
**kwargs – additional keyword arguments.
- Returns:
the transformed parameter.
- Return type:
nn.Parameter
- Raises:
RuntimeError – if the transformation callable fails.
- set_original_data(data: torch.Tensor) PseudoParameter [source]#
Set data to the original parameter.
- Parameters:
data (Tensor) – the data to set.
- Returns:
self.
- Return type:
- __repr__()[source]#
Returns a string representation of the parameter.
- Returns:
the string representation.
- Return type:
- set_transformation(transformation) PseudoParameter [source]#
Sets the transformation.
- Parameters:
transformation (Callable) – the transformation.
- Returns:
self.
- Return type:
- static substitute_member(tensor_from: Any, tensor_to: Any, property_name: str, setter: bool = True)[source]#
Substitutes a member of a tensor as property of another tensor.
- classmethod parameterize(module: torch.nn.Module, param_name: str, transformation: Callable) PseudoParameter [source]#
Parameterizes a parameter.
- Parameters:
module (nn.Module) – the module.
param_name (str) – the name of the parameter.
transformation (Callable) – the transformation to apply.
- Returns:
the parameterized parameter.
- Return type:
- classmethod parametrize_module(module: torch.nn.Module, transformation: Callable, requires_grad: bool = True)[source]#
Parametrize all parameters of a module.
- Parameters:
module (nn.Module) – the module parameters to parametrize.
transformation (Callable) – the transformation.
requires_grad (bool) – if True, only parametrized parameters that require gradients.