code: def load_model(
      databunch, pretrained_path, finetuned_wgts_path, device
  ):
      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
  
      config = AutoConfig.from_pretrained(
          str(pretrained_path),
          num_labels=len(databunch.labels),
          model_type=model_type,
          id2label=databunch.label_map,
          label2id={
              label: i for i, label in enumerate(databunch.labels)
          },
      )
  
      model = AutoModelForTokenClassification.from_pretrained(
          str(pretrained_path),
          config=config,
          state_dict=model_state_dict,
      )
  
      return model
  
imports: import os
  import logging
  import torch
  import numpy
  from .data_ner import BertNERDataBunch
  from torch import nn
  from seqeval.metrics import f1_score, precision_score, recall_score
  from typing import Dict, List, Optional, Tuple
  from .learner_util import Learner
  from transformers import AutoConfig, AutoModelForTokenClassification, Trainer, TrainingArguments, EvalPrediction, HfArgumentParser
label_desc: Use image node_id 1 for calling a global function with example usage: load_model(databunch, pretrained_path, finetuned_wgts_path, device) and returns: model