code: def __init__(self, cfg: MaeImageClassificationConfig):
      super().__init__()
      self.cfg = cfg
  
      if cfg.pretrained_model_args is None:
          state = checkpoint_utils.load_checkpoint_to_cpu(
              cfg.model_path, {}
          )
          pretrained_args = state.get("cfg", None)
  
          pretrained_args.criterion = None
          pretrained_args.lr_scheduler = None
  
          logger.info(pretrained_args.model)
  
          with open_dict(pretrained_args.model):
              pretrained_args.model.drop_path_rate = cfg.drop_path_rate
              if cfg.norm_eps is not None:
                  pretrained_args.model.norm_eps = cfg.norm_eps
  
          cfg.pretrained_model_args = pretrained_args
  
          logger.info(pretrained_args)
      else:
          state = None
          pretrained_args = cfg.pretrained_model_args
  
      if "data" in pretrained_args.task:
          pretrained_args.task.data = cfg.data
      elif "image" in pretrained_args.task:
          pretrained_args.task.image.data = cfg.data
  
      if "modalities" in pretrained_args.model:
          prenet_blocks = pretrained_args.model["modalities"]["image"][
              "prenet_depth"
          ]
          model_blocks = pretrained_args.model["depth"]
          with open_dict(pretrained_args):
              dpr = np.linspace(
                  0, cfg.drop_path_rate, model_blocks
              ).tolist()
              pretrained_args.model["modalities"]["image"][
                  "start_drop_path_rate"
              ] = dpr[0]
              pretrained_args.model["modalities"]["image"][
                  "end_drop_path_rate"
              ] = max(0, dpr[prenet_blocks - 1])
              pretrained_args.model["start_drop_path_rate"] = dpr[
                  prenet_blocks
              ]
              pretrained_args.model["end_drop_path_rate"] = dpr[-1]
  
              if (
                  "mae_masking"
                  in pretrained_args.model["modalities"]["image"]
              ):
                  del pretrained_args.model["modalities"]["image"][
                      "mae_masking"
                  ]
  
              if cfg.remove_alibi:
                  pretrained_args.model["modalities"]["image"][
                      "use_alibi_encoder"
                  ] = False
                  if (
                      state is not None
                      and "modality_encoders.IMAGE.alibi_bias"
                      in state["model"]
                  ):
                      del state["model"][
                          "modality_encoders.IMAGE.alibi_bias"
                      ]
  
              pretrained_args.model[
                  "encoder_dropout"
              ] = cfg.encoder_dropout
              pretrained_args.model["post_mlp_drop"] = cfg.post_mlp_drop
              pretrained_args.model[
                  "attention_dropout"
              ] = cfg.attention_dropout
              pretrained_args.model[
                  "activation_dropout"
              ] = cfg.activation_dropout
              pretrained_args.model["dropout_input"] = cfg.dropout_input
              pretrained_args.model["layerdrop"] = cfg.layerdrop
  
              pretrained_args.model["modalities"]["image"][
                  "prenet_layerdrop"
              ] = cfg.prenet_layerdrop
              pretrained_args.model["modalities"]["image"][
                  "prenet_dropout"
              ] = cfg.prenet_dropout
      else:
          # not d2v multi
          with open_dict(pretrained_args):
              pretrained_args.model[
                  "drop_path_rate"
              ] = cfg.drop_path_rate
              pretrained_args.model[
                  "block_dropout"
              ] = cfg.encoder_dropout
              pretrained_args.model[
                  "attention_dropout"
              ] = cfg.attention_dropout
              pretrained_args.model[
                  "activation_dropout"
              ] = cfg.activation_dropout
  
      task = tasks.setup_task(pretrained_args.task)
      model = task.build_model(
          pretrained_args.model, from_checkpoint=True
      )
  
      self.d2v_multi = "data2vec_multi" in pretrained_args.model._name
      self.linear_classifier = cfg.linear_classifier
  
      self.model = model
  
      if state is not None and not cfg.no_pretrained_weights:
          interpolate_pos_embed(model, state)
  
          if (
              "modality_encoders.IMAGE.positional_encoder.pos_embed"
              in state["model"]
          ):
              state["model"][
                  "modality_encoders.IMAGE.positional_encoder.positions"
              ] = state["model"][
                  "modality_encoders.IMAGE.positional_encoder.pos_embed"
              ]
              del state["model"][
                  "modality_encoders.IMAGE.positional_encoder.pos_embed"
              ]
          if "modality_encoders.IMAGE.encoder_mask" in state["model"]:
              del state["model"]["modality_encoders.IMAGE.encoder_mask"]
  
          model.load_state_dict(state["model"], strict=True)
  
      if self.d2v_multi:
          model.remove_pretraining_modules(modality="image")
      else:
          model.remove_pretraining_modules()
  
      if self.linear_classifier:
          model.requires_grad_(False)
  
      self.fc_norm = None
      if self.cfg.use_fc_norm:
          self.fc_norm = nn.LayerNorm(
              pretrained_args.model.embed_dim, eps=1e-6
          )
          nn.init.constant_(self.fc_norm.bias, 0)
          nn.init.constant_(self.fc_norm.weight, 1.0)
  
      self.head = nn.Linear(
          pretrained_args.model.embed_dim, cfg.num_classes
      )
  
      nn.init.trunc_normal_(self.head.weight, std=0.02)
      nn.init.constant_(self.head.bias, 0)
  
      self.mixup_fn = None
  
      if cfg.mixup > 0 or cfg.cutmix > 0:
          from timm.data import Mixup
  
          self.mixup_fn = Mixup(
              mixup_alpha=cfg.mixup,
              cutmix_alpha=cfg.cutmix,
              cutmix_minmax=None,
              prob=cfg.mixup_prob,
              switch_prob=cfg.mixup_switch_prob,
              mode=cfg.mixup_mode,
              label_smoothing=cfg.label_smoothing,
              num_classes=cfg.num_classes,
          )
  
      if self.model.norm is not None:
          for pn, p in self.model.norm.named_parameters():
              if len(p.shape) == 1 or pn.endswith(".bias"):
                  p.optim_overrides = {
                      "optimizer": {"weight_decay_scale": 0}
                  }
  
      if self.fc_norm is not None:
          for pn, p in self.fc_norm.named_parameters():
              if len(p.shape) == 1 or pn.endswith(".bias"):
                  p.optim_overrides = {
                      "optimizer": {"weight_decay_scale": 0}
                  }
  
      for pn, p in self.head.named_parameters():
          if len(p.shape) == 1 or pn.endswith(".bias"):
              p.optim_overrides = {
                  "optimizer": {"weight_decay_scale": 0}
              }
  
      if self.d2v_multi:
          mod_encs = list(model.modality_encoders.values())
          assert len(mod_encs) == 1, len(mod_encs)
          blocks = list(mod_encs[0].context_encoder.blocks) + list(
              model.blocks
          )
      else:
          blocks = model.blocks
  
      num_layers = len(blocks) + 1
      layer_scales = list(
          cfg.layer_decay ** (num_layers - i)
          for i in range(num_layers + 1)
      )
  
      if self.d2v_multi:
          for n, p in self.model.named_parameters():
              optimizer_override_dict = {}
  
              if len(p.shape) == 1 or n.endswith(".bias"):
                  optimizer_override_dict["weight_decay_scale"] = 0
  
              p.optim_overrides = {"optimizer": optimizer_override_dict}
  
          if cfg.layer_decay > 0:
              for i, b in enumerate(blocks):
                  lid = i + 1
                  if layer_scales[lid] == 1.0:
                      continue
  
                  for n, p in b.named_parameters():
                      optim_override = getattr(p, "optim_overrides", {})
                      if "optimizer" not in optim_override:
                          optim_override["optimizer"] = {}
  
                      if cfg.no_decay_blocks:
                          optim_override["optimizer"][
                              "lr_scale"
                          ] = layer_scales[lid]
                          p.optim_overrides = optim_override
                      else:
                          optim_override["optimizer"] = {
                              "lr_scale": layer_scales[lid]
                          }
                          p.optim_overrides = optim_override
  
      else:
          for n, p in self.model.named_parameters():
              optimizer_override_dict = {}
              layer_id = get_layer_id_for_vit(n, num_layers)
  
              if len(p.shape) == 1 or n.endswith(".bias"):
                  optimizer_override_dict["weight_decay_scale"] = 0
  
              if cfg.layer_decay > 0:
                  optimizer_override_dict["lr_scale"] = layer_scales[
                      layer_id
                  ]
              p.optim_overrides = {"optimizer": optimizer_override_dict}
  
imports: import logging
  from dataclasses import dataclass
  from enum import Enum, auto
  from typing import Any, Optional
  import numpy
  from omegaconf import II, MISSING
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import checkpoint_utils, tasks
  from omegaconf import open_dict
  from fairseq.dataclass import FairseqDataclass
  from fairseq.models import BaseFairseqModel, register_model
  from .mae import interpolate_pos_embed
label_desc: Use image node_id 1 to create a new MaeImageClassificationModel object from inherited base classes: BaseFairseqModel with example: obj = MaeImageClassificationModel(cfg)