class_docstr: A transformer encoder block consists self-attention and a feed-forward layer with pre/post process blocks
  in between.
code: def __init__(
      self,
      config: TransformerConfig,
      inference_only: bool = False,
      dtype: Optional[pt.dtype] = None,
      clamp_to_dtype: bool = False,
  ) -> None:
      super().__init__()
  
      self.pre_self_attention = TransformerProcessBlock(
          sequence=config.preprocess_sequence,
          dropout=config.dropout_prepost,
          num_hidden=config.model_size,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
      self.self_attention = sockeye.layers.MultiHeadSelfAttention(
          depth_att=config.model_size,
          heads=config.attention_heads,
          depth_out=config.model_size,
          dropout=config.dropout_attention,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
      self.post_self_attention = TransformerProcessBlock(
          sequence=config.postprocess_sequence,
          dropout=config.dropout_prepost,
          num_hidden=config.model_size,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
  
      self.pre_ff = TransformerProcessBlock(
          sequence=config.preprocess_sequence,
          dropout=config.dropout_prepost,
          num_hidden=config.model_size,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
      self.ff = TransformerFeedForward(
          num_hidden=config.feed_forward_num_hidden,
          num_model=config.model_size,
          act_type=config.act_type,
          dropout=config.dropout_act,
          use_glu=config.use_glu,
          inference_only=inference_only,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
      self.post_ff = TransformerProcessBlock(
          sequence=config.postprocess_sequence,
          dropout=config.dropout_prepost,
          num_hidden=config.model_size,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
      self.lhuc = None
      if config.use_lhuc:
          self.lhuc = sockeye.layers.LHUC(
              config.model_size, dtype=dtype
          )
  
imports: from dataclasses import dataclass
  from typing import Optional, Tuple
  import torch
  import sockeye.layers
  from sockeye import constants
  from .None import config
label_desc: Use image node_id 1 to create a new TransformerEncoderBlock object from inherited base classes: pt.nn with example: obj = TransformerEncoderBlock(config, inference_only, dtype, clamp_to_dtype)