old_contents: import abc
  import functools
  
  
  
  _FORWARD = "forward"
  _BACKWARD = "backward"
  
  
  class InvertibleLayer(abc.ABC):
    def forward(self, *args):
      return NotImplemented
  
    def backward(self, *args):
      return NotImplemented
  
  
  class InvertibleNetwork(InvertibleLayer):
    def __init__(self, *layers):
      assert all(isinstance(layer, InvertibleLayer) for layer in layers)
      self._layers = layers
  
    def forward(self, *args):
      return _reduce_layers(_FORWARD, *args, **kwargs)
  
    def backward(self, *args):
      return _reduce_layers(_BACKWARD, *args, **kwargs)
  
    def _reduce_layers(self, method, *args):
      assert method in {_FORWARD, _BACKWARD}
      return functools.reduce(lambda args, layer: getattr(layer, method)(*args),
                              self._layers,
                              args)
  
new_contents: import abc
  import functools
  
  
  
  _FORWARD = "forward"
  _BACKWARD = "backward"
  
  
  class InvertibleLayer(abc.ABC):
    @abc.abstractmethod
    def forward(self, x):
      return NotImplemented
  
    @abc.abstractmethod
    def backward(self, x):
      return NotImplemented
  
  
  class InvertibleNetwork(InvertibleLayer):
    def __init__(self, *layers):
      assert all(isinstance(layer, InvertibleLayer) for layer in layers)
      self._layers = layers
  
    def forward(self, x):
      return self._reduce_layers(_FORWARD, x)
  
    def backward(self, x):
      return self._reduce_layers(_BACKWARD, x)
  
    def _reduce_layers(self, method, x):
      assert method in {_FORWARD, _BACKWARD}
      return functools.reduce(
          lambda x, layer: getattr(layer, method)(x),
          self._layers if method == _FORWARD else reversed(self._layers),
          x)
  
subject: Fix invertible module