class_docstr: Layers of encoder transformer blocks plus an final layernorm.
  
  Args:
      num_layers (int): number of layers.
      dim_model (int): main dimension of modules in transformer blocks.
      dim_ff (int): dim_ff used in :py:class:`model_center.layer.FeedForward`.
      num_heads (int): num_heads used in :py:class:`model_center.layer.Attention`.
      dim_head (int): dim_head used in :py:class:`model_center.layer.Attention`.
      dtype (optional): Defaults to torch.half.
      eps (float, optional): eps used in :py:class:`model_center.layer.LayerNorm`. Defaults to 1e-6.
      dropout_p (float, optional): Defaults to 0.
code: def __init__(
      self,
      num_layers: int,
      dim_model: int,
      dim_ff: int,
      num_heads: int,
      dim_head: int,
      dtype: torch.dtype = torch.half,
      eps: float = 1e-6,
      dropout_p: Optional[float] = None,
      mask_modules: Optional[List[Tuple[bool, bool]]] = None,
  ):
      super().__init__()
  
      self.num_layers = num_layers
  
      if mask_modules is not None:
          assert (
              len(mask_modules) == num_layers
          ), "The total number of masks should equal to num_layers"
          for mask_module in mask_modules:
              assert (
                  len(mask_module) == 2
              ), "For encoder, each mask should be (mask_att, mask_ffn)"
      else:
          mask_modules = [(False, False)] * num_layers
  
      self.layers = bmt.TransformerBlockList(
          [
              bmt.CheckpointBlock(
                  TransformerBlock(
                      dim_model=dim_model,
                      dim_ff=dim_ff,
                      num_heads=num_heads,
                      dim_head=dim_head,
                      dtype=dtype,
                      eps=eps,
                      dropout_p=dropout_p,
                      mask_att=mask_modules[ith][0],
                      mask_ffn=mask_modules[ith][1],
                  )
              )
              for ith in range(num_layers)
          ]
      )
  
      self.output_layernorm = LayerNorm(
          dim_norm=dim_model, dtype=dtype, eps=eps
      )
  
file_path: DeepKE/example/llm/CPM-Bee/src/cpm_live/layers/transformer.py
imports: import torch
  import bmtrain
  from typing import Optional, List, Tuple
  from .blocks import TransformerBlock
  from .layernorm import LayerNorm
label_desc: Use image node_id 1 to create a new Encoder object from inherited base classes: bmt with example: obj = Encoder(num_layers, dim_model, dim_ff, num_heads, dim_head, dtype, eps, dropout_p, mask_modules)