class_docstr: A task prepares and holds all the components of a training like optimizer, datasets,
  dataloaders, losses, meters etc. Task also contains the variable like training iteration,
  epoch number etc. that are updated during the training.
  
  We prepare every single component according to the parameter settings user wants
  and specified in the yaml config file.
  
  Task also supports 2 additional things:
  1) converts the model BatchNorm layers to the synchronized batchnorm
  2) sets mixed precision (apex and pytorch both supported)
class_docstr_tok: ["A","task","prepares","and","holds","all","the","components","of","a","training","like","optimizer",",","datasets",",","dataloaders",",","losses",",","meters","etc",".","Task","also","contains","the","variable","like","training","iteration",",","epoch","number","etc",".","that","are","updated","during","the","training",".","We","prepare","every","single","component","according","to","the","parameter","settings","user","wants","and","specified","in","the","yaml","config","file",".","Task","also","supports","2","additional","things",":","1",")","converts","the","model","BatchNorm","layers","to","the","synchronized","batchnorm","2",")","sets","mixed","precision","(","apex","and","pytorch","both","supported",")"]
docstr: - Builds and returns model used for task. The returned model is not copied to
    gpu yet (if using gpu) and neither wrapped with DDP yet. This is done later
    by self.prepare()
  
  - We also convert the model BatchNorm layers to SyncBatchNorm if user
    has set the config option. We support PyTorch and Apex SyncBatchNorms
    both.
  
  - If the model is set to be in evaluation model and the full model must be frozen,
    we freeze the model.
  
  - If the model must be initialized from a checkpoint or user passed weights file
    we initialize the model from the checkpoint or the weights.
docstr_tok: ["-","Builds","and","returns","model","used","for","task",".","The","returned","model","is","not","copied","to","gpu","yet","(","if","using","gpu",")","and","neither","wrapped","with","DDP","yet",".","This","is","done","later","by","self.prepare","(",")","-","We","also","convert","the","model","BatchNorm","layers","to","SyncBatchNorm","if","user","has","set","the","config","option",".","We","support","PyTorch","and","Apex","SyncBatchNorms","both",".","-","If","the","model","is","set","to","be","in","evaluation","model","and","the","full","model","must","be","frozen",",","we","freeze","the","model",".","-","If","the","model","must","be","initialized","from","a","checkpoint","or","user","passed","weights","file","we","initialize","the","model","from","the","checkpoint","or","the","weights","."]
code: def _build_model(self, strict_load: bool = False):
      """
      - Builds and returns model used for task. The returned model is not copied to
        gpu yet (if using gpu) and neither wrapped with DDP yet. This is done later
        by self.prepare()
  
      - We also convert the model BatchNorm layers to SyncBatchNorm if user
        has set the config option. We support PyTorch and Apex SyncBatchNorms
        both.
  
      - If the model is set to be in evaluation model and the full model must be frozen,
        we freeze the model.
  
      - If the model must be initialized from a checkpoint or user passed weights file
        we initialize the model from the checkpoint or the weights.
      """
      logging.info("Building model....")
  
      # Instantiate the raw model as specified
      model = build_model(
          self.config["MODEL"], self.config["OPTIMIZER"]
      )
  
      # Convert the BatchNorm layers to SyncBatchNorm if needed
      # Both Apex and Pytorch SyncBatchNorms are GPU only
      if (
          self.config["MODEL"]["SYNC_BN_CONFIG"][
              "CONVERT_BN_TO_SYNC_BN"
          ]
          and self.config["MACHINE"]["DEVICE"] == "gpu"
      ):
          model = convert_sync_bn(self.config, model)
  
      # Enforce eval mode, no matter what the prior tranforms have done.
      # For instance apex converts batch-norms and sets `requires_grad` to True
      if self.config["MODEL"]["FEATURE_EVAL_SETTINGS"]["EVAL_MODE_ON"]:
          if self.config["MODEL"]["FEATURE_EVAL_SETTINGS"][
              "FREEZE_TRUNK_ONLY"
          ]:
              logging.info(
                  "config.MODEL.FEATURE_EVAL_SETTINGS.FREEZE_TRUNK_ONLY=True, "
                  "will freeze trunk..."
              )
              model.freeze_trunk()
          elif self.config["MODEL"]["FEATURE_EVAL_SETTINGS"][
              "FREEZE_TRUNK_AND_HEAD"
          ]:
              logging.info(
                  "config.MODEL.FEATURE_EVAL_SETTINGS.FREEZE_TRUNK_AND_HEAD=True, will "
                  "freeze trunk and head..."
              )
              model.freeze_head_and_trunk()
  
      # assert that if the user set the PARAMS_FILE, it must exist and be valid.
      if (
          self.checkpoint_path is None
          and self.config["MODEL"]["WEIGHTS_INIT"]["PARAMS_FILE"]
      ):
          assert g_pathmgr.exists(
              self.config["MODEL"]["WEIGHTS_INIT"]["PARAMS_FILE"]
          ), "Specified PARAMS_FILE does NOT exist"
      # If we want to initialize the model in case of finetuning or evaluation,
      # we do it here. But we check that there is no checkpoint existing before
      # This is important in cases when the model training dies.
      if (
          self.checkpoint_path is None
          and self.config["MODEL"]["WEIGHTS_INIT"]["PARAMS_FILE"]
          and g_pathmgr.exists(
              self.config["MODEL"]["WEIGHTS_INIT"]["PARAMS_FILE"]
          )
      ):
          model = self._restore_model_weights(model, strict=strict_load)
  
      return model
  
imports: import gc
  import logging
  import torch
  from classy_vision.generic.distributed_util import is_distributed_training_run
  from classy_vision.generic.util import copy_model_to_gpu
  from classy_vision.hooks import ClassyHook
  from classy_vision.losses import build_loss
  from classy_vision.meters import build_meter
  from classy_vision.optim import build_optimizer, build_optimizer_schedulers
  from classy_vision.tasks import ClassificationTask, register_task
  from classy_vision.tasks.classification_task import AmpType, BroadcastBuffersMode
  from fairscale.nn import FullyShardedDataParallel
  from iopath.common.file_io import g_pathmgr
  from torch.cuda.amp import GradScaler
  from vissl.config import AttrDict
  from vissl.data import build_dataloader, build_dataset, print_sampler_config
  from vissl.models import build_model, convert_sync_bn
  from vissl.optimizers import get_optimizer_param_groups
  from vissl.utils.activation_checkpointing import manual_gradient_reduction
  from vissl.utils.checkpoint import CheckpointLoader
  from vissl.utils.ema_model import ModelEmaV2
  from vissl.utils.misc import is_apex_available, is_fairscale_sharded_available
label_desc: Use image node_id 25 for calling the SelfSupervisionTask obj's underlying member method code with example usage: obj._build_model(strict_load) and returns: model