code: def encoder(
      enc_input,
      input_mask,
      n_layer,
      n_head,
      d_key,
      d_value,
      d_model,
      d_inner_hid,
      prepostprocess_dropout,
      attention_dropout,
      relu_dropout,
      hidden_act,
      preprocess_cmd="n",
      postprocess_cmd="da",
      param_initializer=None,
      name="",
  ):
      """
      The encoder is composed of a stack of identical layers returned by calling
      encoder_layer.
      """
  
      d_shape = L.shape(input_mask)
      pad_idx = build_pad_idx(input_mask)
      attn_bias = build_attn_bias(input_mask, n_head, enc_input.dtype)
  
      enc_input = to_2d(enc_input)
      all_hidden = []
      all_attn = []
      all_ffn = []
      for i in range(n_layer):
          enc_output, ctx_multiheads_attn, ffn_output = encoder_layer(
              enc_input,
              input_mask,
              attn_bias,
              n_head,
              d_key,
              d_value,
              d_model,
              d_inner_hid,
              prepostprocess_dropout,
              attention_dropout,
              relu_dropout,
              hidden_act,
              preprocess_cmd,
              postprocess_cmd,
              param_initializer=param_initializer,
              name=name + "_layer_" + str(i),
          )
          all_hidden.append(enc_output)
          all_attn.append(ctx_multiheads_attn)
          all_ffn.append(ffn_output)
          enc_input = enc_output
      enc_output = pre_process_layer(
          enc_output,
          preprocess_cmd,
          prepostprocess_dropout,
          name="post_encoder",
      )
      enc_output = to_3d(enc_output)
      return enc_output, all_hidden, all_attn, all_ffn
  
file_path: PGL/legacy/examples/xformer/transformer_encoder_sparse.py
imports: from functools import partial
  import paddle.fluid
  import paddle.fluid.layers
  import paddle.fluid.layers
  from .sparse_scaled_dot_product_attention import sparse_scaled_dot_product_attention
label_desc: Use image node_id 7 for calling a global function with example usage: encoder(enc_input, input_mask, n_layer, n_head, d_key, d_value, d_model, d_inner_hid, prepostprocess_dropout, attention_dropout, relu_dropout, hidden_act, preprocess_cmd, postprocess_cmd, param_initializer, name) and returns: enc_output,  all_hidden,  all_attn,  all_ffn