docstr: Return opt and model states.
  
  Override this method from TorchAgent to allow us to load partial weights from
  pre-trained models.
docstr_tok: ["Return","opt","and","model","states",".","Override","this","method","from","TorchAgent","to","allow","us","to","load","partial","weights","from","pre-trained","models","."]
code: def load(self, path):
      """
      Return opt and model states.
  
      Override this method from TorchAgent to allow us to load partial weights from
      pre-trained models.
      """
      with PathManager.open(path, "rb") as f:
          states = torch.load(f, map_location=lambda cpu, _: cpu)
  
      if "model" in states:
          new_state_dict = states["model"]
          # load params
          current_state = self.model.state_dict()
          # filter out unnecessary params
          pre_trained_state = {
              k: v
              for k, v in new_state_dict.items()
              if k in current_state
          }
          # upload pretrained state
          current_state.update(pre_trained_state)
          self.model.load_state_dict(current_state)
  
      if "optimizer" in states and hasattr(self, "optimizer"):
          self.optimizer.load_state_dict(states["optimizer"])
      return states
  
file_path: ParlAI/projects/wizard_of_wikipedia/wizard_transformer_ranker/wizard_transformer_ranker.py
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.agents.transformer.transformer import TransformerRankerAgent
  from .wizard_dict import WizardDictAgent
  from parlai.utils.io import PathManager
  import numpy
  import torch
label_desc: Use image node_id 6 for calling the WizardTransformerRankerAgent obj's underlying member method code with example usage: obj.load(path) and returns: states