code: def gat(
      gw,
      feature,
      hidden_size,
      activation,
      name,
      num_heads=8,
      feat_drop=0.6,
      attn_drop=0.6,
      is_test=False,
  ):
      """Implementation of graph attention networks (GAT)
  
      This is an implementation of the paper GRAPH ATTENTION NETWORKS
      (https://arxiv.org/abs/1710.10903).
  
      Args:
          gw: Graph wrapper object (:code:`StaticGraphWrapper` or :code:`GraphWrapper`)
  
          feature: A tensor with shape (num_nodes, feature_size).
  
          hidden_size: The hidden size for gat.
  
          activation: The activation for the output.
  
          name: Gat layer names.
  
          num_heads: The head number in gat.
  
          feat_drop: Dropout rate for feature.
  
          attn_drop: Dropout rate for attention.
  
          is_test: Whether in test phrase.
  
      Return:
          A tensor with shape (num_nodes, hidden_size * num_heads)
      """
  
      def send_attention(src_feat, dst_feat, edge_feat):
          output = src_feat["left_a"] + dst_feat["right_a"]
          output = L.leaky_relu(
              output, alpha=0.2
          )  # (num_edges, num_heads)
          return {"alpha": output, "h": src_feat["h"]}
  
      def reduce_attention(msg):
          alpha = msg[
              "alpha"
          ]  # lod-tensor (batch_size, seq_len, num_heads)
          h = msg["h"]
          alpha = paddle_helper.sequence_softmax(alpha)
          old_h = h
          h = L.reshape(h, [-1, num_heads, hidden_size])
          alpha = L.reshape(alpha, [-1, num_heads, 1])
          if attn_drop > 1e-15:
              alpha = L.dropout(
                  alpha,
                  dropout_prob=attn_drop,
                  is_test=is_test,
                  dropout_implementation="upscale_in_train",
              )
          h = h * alpha
          h = L.reshape(h, [-1, num_heads * hidden_size])
          h = L.lod_reset(h, old_h)
          return L.sequence_pool(h, "sum")
  
      if feat_drop > 1e-15:
          feature = L.dropout(
              feature,
              dropout_prob=feat_drop,
              is_test=is_test,
              dropout_implementation="upscale_in_train",
          )
  
      ft = L.fc(
          feature,
          hidden_size * num_heads,
          bias_attr=False,
          param_attr=fluid.ParamAttr(name=name + "_weight"),
      )
      left_a = L.create_parameter(
          shape=[num_heads, hidden_size],
          dtype="float32",
          name=name + "_gat_l_A",
      )
      right_a = L.create_parameter(
          shape=[num_heads, hidden_size],
          dtype="float32",
          name=name + "_gat_r_A",
      )
      reshape_ft = L.reshape(ft, [-1, num_heads, hidden_size])
      left_a_value = L.reduce_sum(reshape_ft * left_a, -1)
      right_a_value = L.reduce_sum(reshape_ft * right_a, -1)
  
      msg = gw.send(
          send_attention,
          nfeat_list=[
              ("h", ft),
              ("left_a", left_a_value),
              ("right_a", right_a_value),
          ],
      )
      output = gw.recv(msg, reduce_attention)
      bias = L.create_parameter(
          shape=[hidden_size * num_heads],
          dtype="float32",
          is_bias=True,
          name=name + "_bias",
      )
      bias.stop_gradient = True
      output = L.elementwise_add(output, bias, act=activation)
      return output
  
file_path: PGL/legacy/pgl/layers/conv.py
imports: import pgl
  import paddle.fluid
  import paddle.fluid.layers
  from pgl.utils import paddle_helper
  from pgl import message_passing
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: gat(gw, feature, hidden_size, activation, name, num_heads, feat_drop, attn_drop, is_test) and returns: output, dict, L