code: def AttentionResampling(
      shorten_factor,
      d_model,
      is_upsampling,
      d_ff,
      n_heads,
      dropout,
      dropout_shared_axes,
      mode,
      ff_activation,
      context_bias_layer,
      location_bias_layer,
      total_pooling,
      resampling_fn,
  ):
      """Attention resampling."""
  
      attention = RelativeAttentionLMLayer(
          d_model,
          context_bias_layer,
          location_bias_layer,
          total_pooling,
          n_heads=n_heads,
          dropout=dropout,
          mode=mode,
      )
  
      feed_forward = FeedForwardBlock(
          d_model,
          d_ff,
          dropout,
          dropout_shared_axes,
          mode,
          ff_activation,
      )
  
      resampling = resampling_fn(shorten_factor, d_model, mode=mode)
  
      def _Dropout():
          return core.Dropout(
              rate=dropout, shared_axes=dropout_shared_axes, mode=mode
          )
  
      return [
          LayerNorm(),  # h
          cb.Branch(
              cb.Serial(
                  resampling,
                  LayerNorm(),
              ),
              None,
          ),  # h', h
          cb.Serial(  # pylint: disable=g-long-ternary
              cb.Select([0, 2, 1, 2]),
              cb.Add(),
          )
          if is_upsampling
          else [],
          cb.Residual(
              cb.Select([0, 1, 1]),  # h', h, h
              attention,
              _Dropout(),
          ),
          cb.Residual(
              LayerNorm(),
              feed_forward,
              _Dropout(),
          ),
      ]
  
file_path: trax/trax/layers/research/resampling.py
imports: from trax.fastmath import numpy
  from trax.layers import combinators
  from trax.layers import core
  from trax.layers.normalization import LayerNorm
  from trax.layers.pooling import AvgPool
  from trax.layers.research.rel_attention import RelativeAttentionLMLayer
label_desc: Use image node_id 7 for calling a global function with example usage: AttentionResampling(shorten_factor, d_model, is_upsampling, d_ff, n_heads, dropout, dropout_shared_axes, mode, ff_activation, context_bias_layer, location_bias_layer, total_pooling, resampling_fn) and returns: list, core