Create a Momentum Residual Network.
It iterates
v_{t + 1} = gamma * v_t + (1 - gamma) * f_t(x_t)
x_{t + 1} = x_t + v_{t + 1}
where the f_t are stored in functions. These forward equations can be reversed in closed-form, enabling learning without backpropagation. This process trades memory for computations.
a list of Sequential to define the transformation at each layer. Each function in the list can take additional inputs. ‘x’ is assumed to be the first input.
the momentum term
if init_speed is True then specify an init_function for the velocity v
to initialize the velocity to init_function(x) before the forward pass
if True then standard backpropagation is used, if False activations are not saved during the forward pass allowing memory savings
if True then the update rule is v_{t + 1} = (1 - gamma) * v_t + gamma * f_t(x_t) if False then the update rule is v_{t + 1} = (1 - gamma) * v_t + gamma * (f_t(x_t) - x_t)
Notes
Implementation based on Michael E. Sander, Pierre Ablin, Mathieu Blondel, Gabriel Peyre. Momentum Residual Neural Networks. Proceedings of the 38th International Conference on Machine Learning, PMLR 139:9276-9287
Examples
>>> import torch
>>> from torch import nn
>>> from momentumnet import MomentumNet
>>> hidden = 8
>>> d = 50
>>> function = nn.Sequential(nn.Linear(d, hidden),
... nn.Tanh(), nn.Linear(hidden, d))
>>> mresnet = MomentumNet([function,] * 10, gamma=0.99)
>>> x = torch.randn(10, d)
>>> mresnet(x).shape
torch.Size([10, 50])
Methods
forward(x, *args, **kwargs) |
maps x to the output of the network |
Initializes internal Module state, shared by both nn.Module and ScriptModule.
Methods
|
Initializes internal Module state, shared by both nn.Module and ScriptModule. |
|
Adds a child module to the current module. |
|
Applies |
|
Casts all floating point parameters and buffers to |
|
Returns an iterator over module buffers. |
|
Returns an iterator over immediate children modules. |
|
Moves all model parameters and buffers to the CPU. |
|
Moves all model parameters and buffers to the GPU. |
|
Casts all floating point parameters and buffers to |
|
Sets the module in evaluation mode. |
|
Set the extra representation of the module |
|
Casts all floating point parameters and buffers to |
|
Defines the computation performed at every call. |
|
Returns the buffer given by |
|
Returns any extra state to include in the module's state_dict. |
|
Returns the parameter given by |
|
Returns the submodule given by |
|
Casts all floating point parameters and buffers to |
|
Copies parameters and buffers from |
|
Returns an iterator over all modules in the network. |
|
Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself. |
|
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself. |
|
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself. |
|
Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself. |
|
Returns an iterator over module parameters. |
|
Registers a backward hook on the module. |
|
Adds a buffer to the module. |
|
Registers a forward hook on the module. |
|
Registers a forward pre-hook on the module. |
|
Registers a backward hook on the module. |
|
Adds a parameter to the module. |
|
Change if autograd should record operations on parameters in this module. |
|
This function is called from |
|
See |
|
Returns a dictionary containing a whole state of the module. |
|
Moves and/or casts the parameters and buffers. |
|
Moves the parameters and buffers to the specified device without copying storage. |
|
Sets the module in training mode. |
|
Casts all parameters and buffers to |
|
Moves all model parameters and buffers to the XPU. |
|
Sets gradients of all model parameters to zero. |
Attributes
|
|
|
This allows better BC support for |
|
|
|