code: def load_model(
      dataBunch,
      pretrained_path,
      finetuned_wgts_path,
      device,
      multi_label,
      pos_weight,
      weight,
  ):
      model_type = dataBunch.model_type
      model_state_dict = None
  
      if torch.cuda.is_available():
          map_location = lambda storage, loc: storage.cuda()
      else:
          map_location = "cpu"
  
      if finetuned_wgts_path:
          model_state_dict = torch.load(
              finetuned_wgts_path, map_location=map_location
          )
      else:
          model_state_dict = None
  
      if multi_label is True:
          config_class, model_class, _ = MODEL_CLASSES[model_type]
  
          model_class[1].pos_weight = (
              pos_weight
              if pos_weight is not None
              else dataBunch.pos_weight
          )
          model_class[1].weight = (
              weight if weight is not None else dataBunch.weight
          )
  
          config = config_class.from_pretrained(
              str(pretrained_path), num_labels=len(dataBunch.labels)
          )
  
          model = model_class[1].from_pretrained(
              str(pretrained_path),
              config=config,
              state_dict=model_state_dict,
          )
      else:
          if finetuned_wgts_path:
              finetuned_path = str(finetuned_wgts_path).replace(
                  "/pytorch_model.bin", ""
              )
              config = AutoConfig.from_pretrained(
                  str(finetuned_path), num_labels=len(dataBunch.labels)
              )
  
              model = (
                  AutoModelForSequenceClassification.from_pretrained(
                      str(finetuned_path), config=config
                  )
              )
          else:
              config = AutoConfig.from_pretrained(
                  str(pretrained_path), num_labels=len(dataBunch.labels)
              )
  
              model = (
                  AutoModelForSequenceClassification.from_pretrained(
                      str(pretrained_path), config=config
                  )
              )
  
      return model.to(device)
  
imports: import os
  import copy
  import logging
  from packaging import version
  from .data_cls import BertDataBunch
  from tqdm.autonotebook import tqdm
  import matplotlib.pyplot
  from .learner_util import Learner
  from torch import nn
  from typing import List, Optional
  from .modeling import BertForMultiLabelSequenceClassification, XLNetForMultiLabelSequenceClassification, RobertaForMultiLabelSequenceClassification, DistilBertForMultiLabelSequenceClassification, CamembertForMultiLabelSequenceClassification, AlbertForMultiLabelSequenceClassification, ElectraForMultiLabelSequenceClassification, FlaubertForMultiLabelSequenceClassification
  from fastprogress.fastprogress import master_bar, progress_bar
  import torch
  import pandas
  import numpy
  from sklearn.metrics import roc_curve, auc
  from pathlib import Path
  from torch.optim.lr_scheduler import _LRScheduler, Optimizer
  from tensorboardX import SummaryWriter
  from transformers import WEIGHTS_NAME, BertConfig, BertForSequenceClassification, BertTokenizer, XLMConfig, XLMForSequenceClassification, XLMTokenizer, XLNetConfig, XLNetForSequenceClassification, XLNetTokenizer, RobertaConfig, RobertaForSequenceClassification, RobertaTokenizer, CamembertConfig, CamembertForSequenceClassification, CamembertTokenizer, AlbertConfig, AlbertForSequenceClassification, AlbertTokenizer, DistilBertConfig, DistilBertForSequenceClassification, DistilBertTokenizer, ElectraConfig, ElectraForSequenceClassification, ElectraTokenizer, FlaubertConfig, FlaubertForSequenceClassification, FlaubertTokenizer
  from transformers import AutoModelForSequenceClassification, AutoConfig, TrainingArguments
  from transformers.trainer_callback import TrainerCallback, TrainerControl, TrainerState, CallbackHandler, DefaultFlowCallback
label_desc: Use image node_id 1 for calling a global function with example usage: load_model(dataBunch, pretrained_path, finetuned_wgts_path, device, multi_label, pos_weight, weight) and returns: model