class_docstr: Basic tests on the util functions in TorchAgent.
class_docstr_tok: ["Basic","tests","on","the","util","functions","in","TorchAgent","."]
docstr: Make sure when resuming training that model uses appropriate mf.
  
  Copy train_model from testing_utils to directly access agent.
docstr_tok: ["Make","sure","when","resuming","training","that","model","uses","appropriate","mf",".","Copy","train_model","from","testing_utils","to","directly","access","agent","."]
code: def test_resume_checkpoint(self):
      """
      Make sure when resuming training that model uses appropriate mf.
  
      Copy train_model from testing_utils to directly access agent.
      """
      import parlai.scripts.train_model as tms
  
      def get_popt_and_tl(opt):
          parser = tms.setup_args()
          parser.set_params(**opt)
          popt = parser.parse_args([])
          for k, v in opt.items():
              popt[k] = v
          return popt, tms.TrainLoop(popt)
  
      def get_opt(init_mf, mf):
          return {
              "task": "integration_tests",
              "init_model": init_mf,
              "model": "parlai.agents.test_agents.test_agents:MockTorchAgent",
              "model_file": mf,
              "num_epochs": 3,
              "validation_every_n_epochs": 1,
              "save_after_valid": True,
              "log_every_n_secs": 10,
          }
  
      with tempdir() as tmpdir:
          # First train model with init_model path set
          mf = os.path.join(tmpdir, "model")
          init_mf = os.path.join(tmpdir, "init_model")
          with open(init_mf, "w") as f:
              f.write(" ")
          opt = get_opt(init_mf, mf)
          popt, tl = get_popt_and_tl(opt)
          agent = tl.agent
          # init model file should be set appropriately
          init_model_file, is_finetune = agent._get_init_model(
              popt, None
          )
          self.assertEqual(init_model_file, init_mf)
          self.assertTrue(is_finetune)
          valid, test = tl.train()
          # now, train the model for another epoch
          opt = get_opt("{}.checkpoint".format(mf), mf)
          opt["load_from_checkpoint"] = True
          popt, tl = get_popt_and_tl(opt)
          agent = tl.agent
          init_model_file, is_finetune = agent._get_init_model(
              popt, None
          )
          self.assertEqual(init_model_file, "{}.checkpoint".format(mf))
          self.assertFalse(is_finetune)
  
imports: import os
  import unittest
  from parlai.core.agents import create_agent_from_shared
  from parlai.utils.testing import tempdir
  from parlai.utils.misc import Message
label_desc: Use image node_id 19 for calling the TestTorchAgent obj's underlying member method code with example usage: obj.test_resume_checkpoint() and returns: popt,  tms, dict