code: def build_finetuning_model(task_name: str, state_dict_path: str):
      model = build_model("bert-base-uncased", task_name)
      if Path(state_dict_path).exists():
          model.load_state_dict(torch.load(state_dict_path))
      else:
          trainer = prepare_traced_trainer(model, task_name, True)
          trainer.train()
          torch.save(model.state_dict(), state_dict_path)
      return model
  
imports: from __future__ import annotations
  from pathlib import Path
  import numpy
  import torch
  from torch.utils.data import ConcatDataset
  import nni
  from datasets import load_dataset, load_metric
  from transformers import BertTokenizerFast, DataCollatorWithPadding, BertForSequenceClassification, EvalPrediction
  from transformers.trainer import Trainer
  from transformers.training_args import TrainingArguments
  from nni.compression.distillation import DynamicLayerwiseDistiller, Adaptive1dLayerwiseDistiller
  from nni.compression.utils import TransformersEvaluator
  from nni.compression.pruning import MovementPruner
  from nni.compression.speedup import ModelSpeedup
  from nni.compression.utils.external.external_replacer import TransformersAttentionReplacer
  from nni.compression.pruning import TaylorPruner, AGPPruner
  from transformers.models.bert.modeling_bert import BertLayer
  from nni.compression.base.setting import PruningSetting
label_desc: Use image node_id 4 for calling a global function with example usage: build_finetuning_model(task_name, state_dict_path) and returns: model