code: def forward(
      self,
      input_nodes: torch.LongTensor,
      input_edges: torch.LongTensor,
      attn_bias: torch.Tensor,
      in_degree: torch.LongTensor,
      out_degree: torch.LongTensor,
      spatial_pos: torch.LongTensor,
      attn_edge_type: torch.LongTensor,
      perturb=None,
      last_state_only: bool = False,
      token_embeddings: Optional[torch.Tensor] = None,
      attn_mask: Optional[torch.Tensor] = None,
  ) -> Tuple[Union[torch.Tensor, List[torch.LongTensor]], torch.Tensor]:
      # compute padding mask. This is needed for multi-head attention
      data_x = input_nodes
      n_graph, n_node = data_x.size()[:2]
      padding_mask = (data_x[:, :, 0]).eq(0)
      padding_mask_cls = torch.zeros(
          n_graph,
          1,
          device=padding_mask.device,
          dtype=padding_mask.dtype,
      )
      padding_mask = torch.cat((padding_mask_cls, padding_mask), dim=1)
  
      attn_bias = self.graph_attn_bias(
          input_nodes,
          attn_bias,
          spatial_pos,
          input_edges,
          attn_edge_type,
      )
  
      if token_embeddings is not None:
          input_nodes = token_embeddings
      else:
          input_nodes = self.graph_node_feature(
              input_nodes, in_degree, out_degree
          )
  
      if perturb is not None:
          input_nodes[:, 1:, :] += perturb
  
      if self.embed_scale is not None:
          input_nodes = input_nodes * self.embed_scale
  
      if self.quant_noise is not None:
          input_nodes = self.quant_noise(input_nodes)
  
      if self.emb_layer_norm is not None:
          input_nodes = self.emb_layer_norm(input_nodes)
  
      input_nodes = self.dropout_module(input_nodes)
  
      input_nodes = input_nodes.transpose(0, 1)
  
      inner_states = []
      if not last_state_only:
          inner_states.append(input_nodes)
  
      for layer in self.layers:
          input_nodes, _ = layer(
              input_nodes,
              self_attn_padding_mask=padding_mask,
              self_attn_mask=attn_mask,
              self_attn_bias=attn_bias,
          )
          if not last_state_only:
              inner_states.append(input_nodes)
  
      graph_rep = input_nodes[0, :, :]
  
      if last_state_only:
          inner_states = [input_nodes]
  
      if self.traceable:
          return torch.stack(inner_states), graph_rep
      else:
          return inner_states, graph_rep
  
imports: import math
  from typing import Iterable, Iterator, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithNoAttention, SequenceClassifierOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import logging
  from .configuration_graphormer import GraphormerConfig
label_desc: Use image node_id 2 for calling the GraphormerGraphEncoder obj's underlying member method code with example usage: obj.forward(input_nodes, input_edges, attn_bias, in_degree, out_degree, spatial_pos, attn_edge_type, perturb, last_state_only, token_embeddings, attn_mask) and returns: torch,  graph_rep, inner_states,  graph_rep