class_docstr: Test for IBOT (https://arxiv.org/pdf/2111.07832.pdf)
code: def test_training_with_preemption_then_evaluation(self) -> None:
      config = self.create_pretraining_config()
      with in_temporary_directory() as pretrain_dir:
          result = run_integration_test(config)
          losses_before = result.get_losses()
  
          # Check content of pre-training directory after run is done
          dir_content = os.listdir(pretrain_dir)
          self.assertIn(
              "model_final_checkpoint_phase1.torch", dir_content
          )
  
          # Check the content of the checkpoint
          checkpoint = torch.load("model_final_checkpoint_phase1.torch")
          self.assertIn("loss", checkpoint)
          self.assertIn("criterion", checkpoint["loss"].keys())
          self.assertIn("teacher", checkpoint["loss"].keys())
  
          # Simulate a preemption by removing the last checkpoint
          # and then restarting the training
          os.remove("model_final_checkpoint_phase1.torch")
          os.remove("checkpoint.torch")
          os.remove("log.txt")
          result = run_integration_test(config)
          losses_after = result.get_losses()
  
          # Check that the preemption leads to restart at last checkpoint
          # and check that the losses match despite the preemption
          print("Losses before:", losses_before)
          print("Losses after:", losses_after)
          self.assertEqual(8, len(losses_before))
          self.assertEqual(4, len(losses_after))
          self.assertAlmostEqual(
              losses_after[-1], losses_before[-1], places=5
          )
  
          # Now load the checkpoint for evaluation
          with in_temporary_directory():
              eval_config = self.create_linear_eval_config(
                  gpu_count=2,
                  checkpoint_path=os.path.join(
                      pretrain_dir, "checkpoint.torch"
                  ),
              )
              result = run_integration_test(eval_config)
              losses = result.get_losses()
              self.assertGreater(len(losses), 0)
  
file_path: vissl/tests/test_ibot.py
imports: import os
  import unittest
  import torch
  from vissl.utils.hydra_config import compose_hydra_configuration, convert_to_attrdict
  from vissl.utils.test_utils import gpu_test, in_temporary_directory, run_integration_test
label_desc: Use image node_id 3 for calling the TestIBOT obj's underlying member method code with example usage: obj.test_training_with_preemption_then_evaluation() without return types