tf.ReversibleResidualLayerWrapper module
tf.ReversibleResidualLayerWrapper module¶
- class tf.ReversibleResidualLayerWrapper.ReversibleResidualLayerWrapper(*args: Any, **kwargs: Any)¶
Bases:
modelzoo.common.layers.tf.AbstractRecomputeWrapper.AbstractRecomputeWrapperA wrapper to create a reversible residual layer.
A reversible residual layer is defined to take inputs
x1andx2and to returny1andy2outputs that are the same shape asx1andx2, respectively. The following is the formulation:y1 = x1 + f(x2, f_side_input) y2 = x2 + g(y1, g_side_input)
Limitations:
fandgmust not close over any tensors. All side inputs tofandgshould be passed in to the call function askwargs, which will be forwarded to the call functions of bothfandg(i.e.,fandgmust acceptkwargs).fandgmust agree on the dimensionality of their inputs and outputs in order for the addition in the equations above to work. In particular, the input shape tofmust be the same as the output shape ofg, and vice versa.
- Parameters
f_block (function) – Function
(Tensor) -> (Tensor)defining theftransformation of the layer. Input shape must be the shape ofx2, and the output shape must be the same asx1.g_block (function) – Function
(Tensor) -> (Tensor)defining thegtransformation of the layer. Input shape must be the shape ofx1, and the output shape must be the same asx2.
- call(*args, **kwargs)¶