class_docstr: Bert-based module for Biencoder model.
class_docstr_tok: ["Bert-based","module","for","Biencoder","model","."]
docstr: Initialize the state from a pretrained BERT model
  on iteration zero of ICT pretraining
docstr_tok: ["Initialize","the","state","from","a","pretrained","BERT","model","on","iteration","zero","of","ICT","pretraining"]
code: def init_state_dict_from_bert(self):
      """Initialize the state from a pretrained BERT model
      on iteration zero of ICT pretraining"""
      args = get_args()
  
      if args.bert_load is None:
          print_rank_0("bert-load argument is None")
          return
  
      tracker_filename = get_checkpoint_tracker_filename(args.bert_load)
      if not os.path.isfile(tracker_filename):
          raise FileNotFoundError("Could not find BERT checkpoint")
      with open(tracker_filename, "r") as f:
          iteration = int(f.read().strip())
          assert iteration > 0
  
      checkpoint_name = get_checkpoint_name(
          args.bert_load, iteration, False
      )
      if mpu.get_data_parallel_rank() == 0:
          print(
              "global rank {} is loading BERT checkpoint {}".format(
                  torch.distributed.get_rank(), checkpoint_name
              )
          )
  
      # Load the checkpoint.
      try:
          state_dict = torch.load(checkpoint_name, map_location="cpu")
      except ModuleNotFoundError:
          from megatron.fp16_deprecated import loss_scaler
  
          # For backward compatibility.
          print_rank_0(
              " > deserializing using the old code structure ..."
          )
          sys.modules["fp16.loss_scaler"] = sys.modules[
              "megatron.fp16_deprecated.loss_scaler"
          ]
          sys.modules["megatron.fp16.loss_scaler"] = sys.modules[
              "megatron.fp16_deprecated.loss_scaler"
          ]
          state_dict = torch.load(checkpoint_name, map_location="cpu")
          sys.modules.pop("fp16.loss_scaler", None)
          sys.modules.pop("megatron.fp16.loss_scaler", None)
      except BaseException:
          print_rank_0("could not load the BERT checkpoint")
          sys.exit()
  
      checkpoint_version = state_dict.get("checkpoint_version", 0)
  
      # load the LM state dict into each model
      model_dict = state_dict["model"]["language_model"]
  
      if self.biencoder_shared_query_context_model:
          self.model.language_model.load_state_dict(model_dict)
          fix_query_key_value_ordering(self.model, checkpoint_version)
      else:
          if self.use_query_model:
              self.query_model.language_model.load_state_dict(
                  model_dict
              )
              # give each model the same ict_head to begin with as well
              if self.biencoder_projection_dim > 0:
                  query_proj_state_dict = (
                      self.state_dict_for_save_checkpoint()[
                          self._query_key
                      ]["projection_enc"]
                  )
              fix_query_key_value_ordering(
                  self.query_model, checkpoint_version
              )
  
          if self.use_context_model:
              self.context_model.language_model.load_state_dict(
                  model_dict
              )
              if (
                  self.query_model is not None
                  and self.biencoder_projection_dim > 0
              ):
                  self.context_model.projection_enc.load_state_dict(
                      query_proj_state_dict
                  )
              fix_query_key_value_ordering(
                  self.context_model, checkpoint_version
              )
  
imports: import os
  import torch
  import sys
  from megatron import get_args, print_rank_0, get_tokenizer
  from megatron.core import mpu
  from megatron.checkpointing import fix_query_key_value_ordering
  from megatron.checkpointing import get_checkpoint_tracker_filename
  from megatron.checkpointing import get_checkpoint_name
  from megatron.model.bert_model import bert_position_ids
  from megatron.model.enums import AttnMaskType
  from megatron.model.language_model import get_language_model
  from megatron.model.utils import get_linear_layer
  from megatron.model.utils import init_method_normal
  from megatron.model.utils import scaled_init_method_normal
  from .module import MegatronModule
label_desc: Use image node_id 7 for calling the BiEncoderModel obj's underlying member method code with example usage: obj.init_state_dict_from_bert() without return types