class_docstr: Check that loading a checkpoint during training works
  Check that loading a checkpoint for benchmarking works
class_docstr_tok: ["Check","that","loading","a","checkpoint","during","training","works","Check","that","loading","a","checkpoint","for","benchmarking","works"]
code: def test_benchmarking_with_checkpoint_resharding(self) -> None:
      with in_temporary_directory() as checkpoint_folder:
          # Run a pre-training in FSDP mode and save a sharded checkpoint
          config = self._create_pretraining_config(with_fsdp=True)
          run_integration_test(config)
          checkpoint_path = os.path.join(
              checkpoint_folder, "checkpoint.torch"
          )
  
          # List the files inside the current working directory
          # to later test what files have been created
          files_before_conversion = set(os.listdir(checkpoint_folder))
  
          # Transform the sharded checkpoint to a consolidated checkpoint
          eval_checkpoint_path_1 = os.path.join(
              checkpoint_folder, "checkpoint_eval_1.torch"
          )
          CheckpointFormatConverter.sharded_to_consolidated_checkpoint(
              input_checkpoint_path=checkpoint_path,
              output_checkpoint_path=eval_checkpoint_path_1,
          )
  
          # Transform the sharded checkpoint to a sliced checkpoint
          eval_checkpoint_path_2 = os.path.join(
              checkpoint_folder, "checkpoint_eval_2.torch"
          )
          CheckpointFormatConverter.sharded_to_sliced_checkpoint(
              input_checkpoint_path=checkpoint_path,
              output_checkpoint_path=eval_checkpoint_path_2,
          )
  
          # Verify the content of the directory after checkpoint conversion
          files_after_conversion = set(os.listdir(checkpoint_folder))
          new_files = files_after_conversion - files_before_conversion
          expected_new_files = {
              "checkpoint_eval_1.torch",
              "checkpoint_eval_2.torch",
              "checkpoint_eval_2_layers",
          }
          self.assertEqual(
              new_files,
              expected_new_files,
              "checkpoint 2 slices should be packaged in a directory",
          )
  
          # Run a benchmark in FSDP mode and record the losses and accuracies
          eval_losses, eval_accuracies = self.run_benchmarking(
              checkpoint_path, with_fsdp=True
          )
          self.assertGreater(len(eval_losses), 0)
          self.assertEqual(4, len(eval_accuracies))
  
          # Check that these losses and accuracies are the same with the
          # consolidated and sliced checkpoints
          for eval_checkpoint in [
              eval_checkpoint_path_1,
              eval_checkpoint_path_2,
          ]:
              fsdp_losses, fsdp_accuracies = self.run_benchmarking(
                  eval_checkpoint, with_fsdp=True
              )
              self.assertEqual(fsdp_losses, eval_losses)
              self.assertEqual(fsdp_accuracies, eval_accuracies)
  
          # Check that the consolidated and sliced checkpoints, contrary to
          # the sharded checkpoint, can be used with a different number of GPUs
          for eval_checkpoint in [
              eval_checkpoint_path_1,
              eval_checkpoint_path_2,
          ]:
              fsdp_losses, fsdp_accuracies = self.run_benchmarking(
                  eval_checkpoint, with_fsdp=True, num_gpu=1
              )
              self.assertGreater(len(fsdp_losses), 0)
              self.assertEqual(len(fsdp_accuracies), 4)
  
imports: import os
  import unittest
  from vissl.config.attr_dict import AttrDict
  from vissl.utils.checkpoint import CheckpointFormatConverter
  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 12 for calling the TestStateCheckpointing obj's underlying member method code with example usage: obj.test_benchmarking_with_checkpoint_resharding() without return types