class_docstr: Transformer class.
class_docstr_tok: ["Transformer","class","."]
code: def __init__(
      self,
      config: TransformerConfig,
      spec: Union[TransformerBlockSubmodules, ModuleSpec],
      post_layer_norm: bool = True,
      pre_process: bool = True,
      post_process: bool = True,
  ):
      super().__init__(config=config)
  
      self.submodules = _get_block_submodules(config, spec)
      self.post_layer_norm = post_layer_norm
      self.pre_process = pre_process
      self.post_process = post_process
  
      # required for pipeline parallel schedules
      self.input_tensor = None
  
      self.checkpoint_core_attention = (
          self.config.recompute_granularity == "selective"
      )
  
      self._build_layers()
      self.num_layers_per_pipeline_rank = len(self.layers)
  
imports: import re
  from contextlib import nullcontext
  from dataclasses import dataclass
  from typing import List, Union
  import torch
  from torch import Tensor
  from megatron.core import InferenceParams, parallel_state, tensor_parallel
  from megatron.core.fusions.fused_layer_norm import FusedLayerNorm
  from megatron.core.transformer.custom_layers.transformer_engine import TENorm
  from megatron.core.transformer.enums import AttnMaskType
  from megatron.core.transformer.module import MegatronModule
  from megatron.core.transformer.spec_utils import ModuleSpec, build_module
  from megatron.core.transformer.transformer_config import TransformerConfig
  from megatron.core.transformer.transformer_layer import TransformerLayer
  from megatron.core.utils import make_sharded_tensor_for_checkpoint, make_viewless_tensor
label_desc: Use image node_id 1 to create a new TransformerBlock object from inherited base classes: MegatronModule with example: obj = TransformerBlock(config, spec, post_layer_norm, pre_process, post_process)