class_docstr: Bert Language model.
code: def __init__(
      self,
      num_tokentypes=2,
      add_binary_head=True,
      parallel_output=True,
      pre_process=True,
      post_process=True,
      cpu_offload=False,
  ):
      super(BertModel, self).__init__()
      args = get_args()
  
      self.fp16_lm_cross_entropy = args.fp16_lm_cross_entropy
      self.add_binary_head = add_binary_head
      self.parallel_output = parallel_output
      self.pre_process = pre_process
      self.post_process = post_process
  
      init_method = init_method_normal(args.init_method_std)
      scaled_init_method = scaled_init_method_normal(
          args.init_method_std, args.num_layers
      )
  
      (
          self.language_model,
          self._language_model_key,
      ) = get_language_model(
          num_tokentypes=num_tokentypes,
          add_pooler=self.add_binary_head,
          encoder_attn_mask_type=AttnMaskType.padding,
          init_method=init_method,
          scaled_init_method=scaled_init_method,
          pre_process=self.pre_process,
          post_process=self.post_process,
      )
  
      self.initialize_word_embeddings(init_method_normal)
      if self.post_process:
          self.lm_head = BertLMHead(
              self.word_embeddings_weight().size(0),
              args.hidden_size,
              init_method,
              args.layernorm_epsilon,
              parallel_output,
          )
          self._lm_head_key = "lm_head"
          self.binary_head = None
          if self.add_binary_head:
              self.binary_head = get_linear_layer(
                  args.hidden_size, 2, init_method
              )
              self._binary_head_key = "binary_head"
  
      self.forward_context = contextlib.nullcontext
      if cpu_offload:
          self.forward_context = torch.autograd.graph.save_on_cpu
  
imports: import contextlib
  import torch
  from apex.transformer import tensor_parallel
  from apex.transformer.enums import AttnMaskType
  from apex.transformer.enums import ModelType
  from apex.transformer.layers import FusedLayerNorm
  from apex.transformer.testing.global_vars import get_args
  from apex.transformer.testing.standalone_transformer_lm import MegatronModule, get_language_model, get_linear_layer, init_method_normal, scaled_init_method_normal, parallel_lm_logits
label_desc: Use image node_id 1 to create a new BertModel object from inherited base classes: MegatronModule with example: obj = BertModel(num_tokentypes, add_binary_head, parallel_output, pre_process, post_process, cpu_offload)