code: def __init__(self, nx, n_ctx, config, scale=False):
      super(Attention, self).__init__()
      n_state = nx  # in Attention: n_state=768 (nx=n_embd)
      # [switch nx => n_state from Block to Attention to keep identical to TF implem]
      assert n_state % config.num_heads == 0
      self.register_buffer(
          "b",
          torch.tril(torch.ones(n_ctx, n_ctx)).view(1, 1, n_ctx, n_ctx),
      )
      self.n_head = config.num_heads
      self.split_size = n_state
      self.scale = scale
      self.c_attn = Conv1D(n_state * 3, 1, nx)
      self.c_proj = Conv1D(n_state, 1, nx)
      self.attn_dropout = torch.nn.Dropout(
          config.attention_dropout_probability
      )
      self.resid_dropout = torch.nn.Dropout(
          config.residual_dropout_probability
      )
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import copy
  import io
  import json
  import logging
  import math
  import re
  import tarfile
  import numpy
  import torch
  from torch.nn import Parameter
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.file_utils import cached_path
  from allennlp.common.from_params import FromParams
  from io import open
label_desc: Use image node_id 1 to create a new Attention object from inherited base classes: torch.nn with example: obj = Attention(nx, n_ctx, config, scale)