tf.ReversibleResidualLayerWrapper module
tf.ReversibleResidualLayerWrapper module¶
- class tf.ReversibleResidualLayerWrapper.ReversibleResidualLayerWrapper(*args: Any, **kwargs: Any)¶
Bases:
modelzoo.common.layers.tf.AbstractRecomputeWrapper.AbstractRecomputeWrapper
A wrapper to create a reversible residual layer.
A reversible residual layer is defined to take inputs
x1
andx2
and to returny1
andy2
outputs that are the same shape asx1
andx2
, respectively. The following is the formulation:y1 = x1 + f(x2, f_side_input) y2 = x2 + g(y1, g_side_input)
Limitations:
f
andg
must not close over any tensors. All side inputs tof
andg
should be passed in to the call function askwargs
, which will be forwarded to the call functions of bothf
andg
(i.e.,f
andg
must acceptkwargs
).f
andg
must 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 tof
must be the same as the output shape ofg
, and vice versa.
- Parameters
f_block (function) – Function
(Tensor) -> (Tensor)
defining thef
transformation 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 theg
transformation of the layer. Input shape must be the shape ofx1
, and the output shape must be the same asx2
.
- call(*args, **kwargs)¶