code: def _ReversibleSerialForget(
      layers, d_model, n_layers, forget_dense=True
  ):
      """ReversibleSerial but with a forgetting block every n_layers."""
      if not n_layers or len(layers) <= n_layers + 1:
          return tl.ReversibleSerial(layers)
      layers1, layers2 = layers[:n_layers], layers[n_layers:]
  
      if forget_dense:
          forgetting_layer = tl.Serial(
              _XYAvg(),
              tl.Dense(d_model),
              tl.Dup(),
          )
      else:
          forgetting_layer = tl.Select([0, 1])
  
      return tl.Serial(
          tl.ReversibleSerial(layers1),
          forgetting_layer,
          _ReversibleSerialForget(
              layers2, d_model, n_layers, forget_dense
          ),
      )
  
imports: import functools
  from trax import layers
  from trax.fastmath import numpy
  from trax.models.reformer import reformer
  from trax.models.research import configurable_transformer
  from trax.models.research import transformer2
label_desc: Use image node_id 6 for calling a global function with example usage: _ReversibleSerialForget(layers, d_model, n_layers, forget_dense) and returns: tl, tl