class_docstr: Non-recurrent encoder based on the transformer architecture in:
  
  Attention Is All You Need, Figure 1 (left)
  Vaswani et al. (https://arxiv.org/pdf/1706.03762.pdf).
  
  :param config: Configuration for transformer encoder.
code: def __init__(
      self,
      config: transformer.TransformerConfig,
      inference_only: bool = False,
      dtype: Optional[pt.dtype] = None,
      clamp_to_dtype: bool = False,
  ) -> None:
      pt.nn.Module.__init__(self)
      self.config = config
  
      self.dropout = pt.nn.Dropout(p=config.dropout_prepost)
  
      self.pos_embedding = layers.PositionalEmbeddings(
          weight_type=self.config.positional_embedding_type,
          num_embed=self.config.model_size,
          max_seq_len=self.config.max_seq_len_source,
          scale_up_input=True,
          scale_down_positions=False,
          dtype=dtype,
      )
  
      self.layers = pt.nn.ModuleList(  # using ModuleList because we have additional inputs
          transformer.TransformerEncoderBlock(
              config,
              inference_only=inference_only,
              dtype=dtype,
              clamp_to_dtype=clamp_to_dtype,
          )
          for _ in range(config.num_layers)
      )
  
      self.final_process = transformer.TransformerProcessBlock(
          sequence=config.preprocess_sequence,
          dropout=config.dropout_prepost,
          num_hidden=self.config.model_size,
          dtype=dtype,
          clamp_to_dtype=clamp_to_dtype,
      )
  
imports: from abc import abstractmethod
  from dataclasses import dataclass, field
  from typing import List, Tuple, Optional, Union
  import torch
  import sockeye.constants
  from .None import config
  from .None import layers
  from .None import transformer
label_desc: Use image node_id 1 to create a new TransformerEncoder object from inherited base classes: Encoder with example: obj = TransformerEncoder(config, inference_only, dtype, clamp_to_dtype)