code: def main():
      parser = get_parser()
      args = parser.parse_args()
  
      cp = torch.load(args.checkpoint, map_location="cpu")
  
      cfg = FairseqConfig(
          criterion=ModelCriterionConfig(
              _name="model", log_keys=["correct"]
          ),
      )
  
      if args.type == "image_classification":
          cfg.task = ImageClassificationConfig(
              _name="image_classification",
              data=".",
          )
  
          if args.inception_norms:
              cfg.task.normalization_mean = [0.5, 0.5, 0.5]
              cfg.task.normalization_std = [0.5, 0.5, 0.5]
  
          cfg.model = Data2VecImageClassificationConfig(
              _name="data2vec_image_classification",
          )
          cfg.model.pretrained_model_args = FairseqConfig(
              model=Data2VecVisionConfig(
                  _name="data2vec_vision", shared_rel_pos_bias=False
              ),
              task=ImagePretrainingConfig(
                  _name="image_pretraining",
              ),
          )
  
          cfg = OmegaConf.create(cfg)
  
          state = {
              "cfg": OmegaConf.to_container(
                  cfg, resolve=True, enum_to_str=True
              ),
              "model": cp["module"],
              "best_loss": None,
              "optimizer": None,
              "extra_state": {},
          }
  
          model = Data2VecImageClassificationModel(cfg.model)
          model.load_state_dict(
              update_checkpoint(
                  state["model"],
                  prefix="model.encoder.",
                  is_nested=True,
              ),
              strict=True,
          )
      elif args.type == "vision":
          cfg.task = ImagePretrainingConfig(
              _name="image_pretraining",
              data=".",
          )
  
          if args.inception_norms:
              cfg.task.normalization_mean = [0.5, 0.5, 0.5]
              cfg.task.normalization_std = [0.5, 0.5, 0.5]
  
          cfg.model = Data2VecVisionConfig(
              _name="data2vec_vision",
          )
          cfg = OmegaConf.create(cfg)
  
          state = {
              "cfg": OmegaConf.to_container(
                  cfg, resolve=True, enum_to_str=True
              ),
              "model": cp["model"],
              "best_loss": None,
              "optimizer": None,
              "extra_state": {},
          }
  
          model = Data2VecVisionModel(cfg.model)
          model.load_state_dict(
              update_checkpoint(
                  state["model"], prefix="encoder.", is_nested=False
              ),
              strict=True,
          )
      else:
          raise Exception("unsupported type " + args.type)
  
      print(state["cfg"], state.keys())
      torch.save(state, args.output)
  
file_path: fairseq/examples/data2vec/fb_convert_beit_cp.py
imports: import argparse
  import torch
  from omegaconf import OmegaConf
  from fairseq.criterions.model_criterion import ModelCriterionConfig
  from fairseq.dataclass.configs import FairseqConfig
  from tasks import ImageClassificationConfig, ImagePretrainingConfig
  from models.data2vec_image_classification import Data2VecImageClassificationConfig, Data2VecImageClassificationModel
  from models.data2vec_vision import Data2VecVisionConfig, Data2VecVisionModel
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types