class_docstr: Test the Regnet FSDP model in comparison with the DDP Regnet
  to verify that both converge to the same losses
class_docstr_tok: ["Test","the","Regnet","FSDP","model","in","comparison","with","the","DDP","Regnet","to","verify","that","both","converge","to","the","same","losses"]
code: def test_fsdp_extract_label_predictions(self) -> None:
      with in_temporary_directory() as pretrain_dir:
          # Start pre-training and consolidate the checkpoint
          config = self._create_pretraining_config(
              with_fsdp=True,
              with_activation_checkpointing=True,
              with_mixed_precision=False,
              auto_wrap_threshold=0,
          )
          run_integration_test(config)
          CheckpointFormatConverter.sharded_to_sliced_checkpoint(
              "checkpoint.torch", "checkpoint_sliced.torch"
          )
  
          with in_temporary_directory() as fine_tune_dir:
              # Run fine-tuning on the consolidated checkpoint
              finetune_config = self._create_finetuning_config(
                  checkpoint_path=os.path.join(
                      pretrain_dir, "checkpoint_sliced.torch"
                  ),
                  auto_wrap_threshold=True,
                  with_fsdp=True,
                  with_partial_head=True,
                  with_mixed_precision=True,
                  with_activation_checkpointing=True,
              )
              finetune_config.OPTIMIZER.num_epochs = 1
              results = run_integration_test(finetune_config)
              fine_tune_accuracy = results.get_final_accuracy(
                  layer_name="0"
              )
  
              # Consolidate the fine-tuned evaluation checkpoint
              CheckpointFormatConverter.sharded_to_sliced_checkpoint(
                  "checkpoint.torch", "checkpoint_sliced.torch"
              )
  
              # Run label extract on top of fine-tuned checkpoint
              # Run label extraction on both sharded and consolidated checkpoint
              for checkpoint_name in [
                  "checkpoint.torch",
                  "checkpoint_sliced.torch",
              ]:
                  with in_temporary_directory() as extract_dir:
                      extract_config = self._create_extract_label_prediction_finetuned_config(
                          with_fsdp=True,
                          with_mixed_precision=False,
                          auto_wrap_threshold=True,
                      )
                      extract_config.MODEL.WEIGHTS_INIT.PARAMS_FILE = (
                          os.path.join(fine_tune_dir, checkpoint_name)
                      )
                      run_integration_test(
                          extract_config,
                          engine_name="extract_label_predictions",
                      )
  
                      accuracy, preds, targets = self._read_accuracy(
                          extract_dir, layer="heads"
                      )
                      print(targets)
                      print(preds)
                      print("Accuracy:", accuracy)
                      self.assertAlmostEqual(
                          accuracy * 100.0, fine_tune_accuracy, places=3
                      )
  
          with in_temporary_directory() as lin_eval_dir:
              # Run linear evaluation on the consolidated checkpoint
              config = self._create_linear_evaluation_config(
                  with_fsdp=True,
                  with_mixed_precision=True,
                  auto_wrap_threshold=True,
              )
              config.OPTIMIZER.num_epochs = 1
              config.OPTIMIZER.param_schedulers.lr.values = [0.01]
              config.OPTIMIZER.param_schedulers.lr.milestones = []
              config.MODEL.WEIGHTS_INIT.PARAMS_FILE = os.path.join(
                  pretrain_dir, "checkpoint_sliced.torch"
              )
              results = run_integration_test(config)
              linear_accuracy = results.get_final_accuracy("res5")
  
              # Consolidate the linear evaluation checkpoint
              CheckpointFormatConverter.sharded_to_sliced_checkpoint(
                  "checkpoint.torch", "checkpoint_sliced.torch"
              )
  
              # Run label extraction on both sharded and consolidated checkpoint
              for checkpoint_name in [
                  "checkpoint.torch",
                  "checkpoint_sliced.torch",
              ]:
                  with in_temporary_directory() as extract_dir:
                      extract_config = (
                          self._create_extract_label_prediction_config(
                              with_fsdp=True,
                              with_mixed_precision=False,
                              auto_wrap_threshold=True,
                          )
                      )
                      extract_config.MODEL.WEIGHTS_INIT.PARAMS_FILE = (
                          os.path.join(lin_eval_dir, checkpoint_name)
                      )
                      run_integration_test(
                          extract_config,
                          engine_name="extract_label_predictions",
                      )
  
                      # Read the predictions and verify that they match
                      # the linear evaluation results
                      accuracy, preds, targets = self._read_accuracy(
                          extract_dir, layer="res5"
                      )
                      print(targets)
                      print(preds)
                      print("Accuracy:", accuracy)
                      self.assertAlmostEqual(
                          accuracy * 100.0, linear_accuracy, places=3
                      )
  
imports: import os
  import unittest
  import numpy
  import torch
  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 11 for calling the TestRegnetFSDPIntegration obj's underlying member method code with example usage: obj.test_fsdp_extract_label_predictions() without return types