class_docstr: Multi-headed attention.
  
  See "Attention Is All You Need" for more details.
class_docstr_tok: ["Multi-headed","attention",".","See","``","Attention","Is","All","You","Need","''","for","more","details","."]
code: def __init__(self, config: GraphormerConfig):
      super().__init__()
      self.embedding_dim = config.embedding_dim
      self.kdim = (
          config.kdim
          if config.kdim is not None
          else config.embedding_dim
      )
      self.vdim = (
          config.vdim
          if config.vdim is not None
          else config.embedding_dim
      )
      self.qkv_same_dim = (
          self.kdim == config.embedding_dim
          and self.vdim == config.embedding_dim
      )
  
      self.num_heads = config.num_attention_heads
      self.attention_dropout_module = torch.nn.Dropout(
          p=config.attention_dropout, inplace=False
      )
  
      self.head_dim = config.embedding_dim // config.num_attention_heads
      if not (
          self.head_dim * config.num_attention_heads
          == self.embedding_dim
      ):
          raise AssertionError(
              "The embedding_dim must be divisible by num_heads."
          )
      self.scaling = self.head_dim**-0.5
  
      self.self_attention = True  # config.self_attention
      if not (self.self_attention):
          raise NotImplementedError(
              "The Graphormer model only supports self attention for now."
          )
      if self.self_attention and not self.qkv_same_dim:
          raise AssertionError(
              "Self-attention requires query, key and value to be of the same size."
          )
  
      self.k_proj = quant_noise(
          nn.Linear(self.kdim, config.embedding_dim, bias=config.bias),
          config.q_noise,
          config.qn_block_size,
      )
      self.v_proj = quant_noise(
          nn.Linear(self.vdim, config.embedding_dim, bias=config.bias),
          config.q_noise,
          config.qn_block_size,
      )
      self.q_proj = quant_noise(
          nn.Linear(
              config.embedding_dim,
              config.embedding_dim,
              bias=config.bias,
          ),
          config.q_noise,
          config.qn_block_size,
      )
  
      self.out_proj = quant_noise(
          nn.Linear(
              config.embedding_dim,
              config.embedding_dim,
              bias=config.bias,
          ),
          config.q_noise,
          config.qn_block_size,
      )
  
      self.onnx_trace = False
  
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 1 to create a new GraphormerMultiheadAttention object from inherited base classes: nn with example: obj = GraphormerMultiheadAttention(config)