code: def pre_post_process_layer(
      prev_out, out, process_cmd, dropout_rate=0.0, name=""
  ):
      """
      Add residual connection, layer normalization and droput to the out tensor
      optionally according to the value of process_cmd.
      This will be used before or after multi-head attention and position-wise
      feed-forward networks.
      """
      for cmd in process_cmd:
          if cmd == "a":  # add residual connection
              out = out + prev_out if prev_out else out
          elif cmd == "n":  # add layer normalization
              out_dtype = out.dtype
              if out_dtype == fluid.core.VarDesc.VarType.FP16:
                  out = layers.cast(x=out, dtype="float32")
              out = layers.layer_norm(
                  out,
                  begin_norm_axis=len(out.shape) - 1,
                  param_attr=fluid.ParamAttr(
                      name=name + "_layer_norm_scale",
                      initializer=fluid.initializer.Constant(1.0),
                  ),
                  bias_attr=fluid.ParamAttr(
                      name=name + "_layer_norm_bias",
                      initializer=fluid.initializer.Constant(0.0),
                  ),
              )
              if out_dtype == fluid.core.VarDesc.VarType.FP16:
                  out = layers.cast(x=out, dtype="float16")
          elif cmd == "d":  # add dropout
              if dropout_rate:
                  out = layers.dropout(
                      out,
                      dropout_prob=dropout_rate,
                      dropout_implementation="upscale_in_train",
                      is_test=False,
                  )
      return out
  
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 3 for calling a global function with example usage: pre_post_process_layer(prev_out, out, process_cmd, dropout_rate, name) and returns: out