code: def upgrade_state_dict_named(self, state_dict):
      prefix = ""
      current_head_names = (
          []
          if not hasattr(self, "classification_heads")
          else self.classification_heads.keys()
      )
  
      # Handle new classification heads present in the state dict.
      keys_to_delete = []
      for k in state_dict.keys():
          if not k.startswith(prefix + "classification_heads."):
              continue
  
          head_name = k[len(prefix + "classification_heads.") :].split(
              "."
          )[0]
          if head_name not in current_head_names:
              print(
                  "WARNING: deleting classification head ({}) from checkpoint "
                  "not present in current model: {}".format(
                      head_name, k
                  )
              )
              keys_to_delete.append(k)
      for k in keys_to_delete:
          del state_dict[k]
  
      # Copy any newly-added classification heads into the state dict
      # with their current weights.
      if hasattr(self, "classification_heads"):
          cur_state = self.classification_heads.state_dict()
          for k, v in cur_state.items():
              if prefix + "classification_heads." + k not in state_dict:
                  print(
                      "Overwriting",
                      prefix + "classification_heads." + k,
                  )
                  state_dict[prefix + "classification_heads." + k] = v
  
imports: import os
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from tqdm import tqdm
  from collections import OrderedDict
  from pytorch_transformers.modeling_bert import BertPreTrainedModel, BertConfig, BertModel
  from pytorch_transformers.tokenization_bert import BertTokenizer
  from elq.common.ranker_base import BertEncoder, get_model_obj
  from blink.common.optimizer import get_bert_optimizer
  from elq.biencoder.allennlp_span_utils import batched_span_select, batched_index_select
  from elq.biencoder.utils import batch_reshape_mask_left
label_desc: Use image node_id 9 for calling the BiEncoderModule obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict) without return types