code: def load_model(self, fname, cpu=False, cand_enc_only=False):
      if cpu or not torch.cuda.is_available():
          state_dict = torch.load(
              fname, map_location=torch.device("cpu")
          )
      else:
          state_dict = torch.load(fname)
      if cand_enc_only:
          cand_state_dict = get_submodel_from_state_dict(
              state_dict, "cand_encoder"
          )
          self.model.cand_encoder.load_state_dict(cand_state_dict)
      else:
          self.model.upgrade_state_dict_named(state_dict)
          self.model.load_state_dict(state_dict)
  
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 2 for calling the BiEncoderRanker obj's underlying member method code with example usage: obj.load_model(fname, cpu, cand_enc_only) without return types