code: def __init__(
      self,
      d_qk: int,
      d_value: int,
      d_ffn: int,
      n_head: int,
      n_groups: int = 1,
      bidirectional: bool = False,
      apply_rel_dist: Optional[str] = None,
      composite_attention: bool = False,
      pre_ln: bool = False,
      dropout: float = 0.0,
      temperature: float = 1.0,
  ):
      super(TransformerEncoderBlock, self).__init__()
      if n_groups < 1:
          raise ValueError(
              f"n_groups must be a positive integer, but {n_groups} is given"
          )
      elif n_groups == 1:
          if d_qk != d_value:
              warning.warn(
                  "When n_groups=1, `d_qk` and `d_value` is suggested to be equal, "
                  f"but are {d_qk} and {d_value}, respectively. "
                  "d_qk will be ignored."
              )
          self.shape_qk = self.composite_attention = False
          self.attention = SelfAttention(
              d_hidden=d_value,
              n_head=n_head,
              bidirectional=bidirectional,
              apply_rel_dist=apply_rel_dist,
              dropout=dropout,
              temperature=temperature,
          )
      else:
          self.shape_qk = True
          self.composite_attention = composite_attention
          Attention = (
              CompositeAttention
              if composite_attention
              else GroupSelfAttention
          )
          self.attention = Attention(
              d_qk=d_qk,
              d_value=d_value,
              n_head=n_head,
              n_groups=n_groups,
              bidirectional=bidirectional,
              apply_rel_dist=apply_rel_dist,
              dropout=dropout,
              temperature=temperature,
          )
      self.pre_ln = pre_ln
      self.layer_norm = nn.LayerNorm(d_value)
      self.dropout = nn.Dropout(dropout)
      self.ffn = PositionwiseFFN(
          d_model=d_value,
          d_hidden=d_ffn,
          dropout=dropout,
          pre_ln=pre_ln,
      )
  
file_path: gluonts/src/gluonts/nursery/daf/tslib/nn/transformer.py
imports: from typing import Optional, List
  from collections import OrderedDict
  import warnings
  import torch
  from torch import Tensor, BoolTensor
  from torch import nn
  from .attention import SelfAttention, GroupSelfAttention, CompositeAttention, InterAttention
  from .activations import Swish
label_desc: Use image node_id 1 to create a new TransformerEncoderBlock object from inherited base classes: nn with example: obj = TransformerEncoderBlock(d_qk, d_value, d_ffn, n_head, n_groups, bidirectional, apply_rel_dist, composite_attention, pre_ln, dropout, temperature)