class_docstr: Test PyTorch & CoreML forward pass parity, conversion success, ANE speed-up and trivial example accuracy
  of ANE-optimized distilbert models for sequence classification
class_docstr_tok: ["Test","PyTorch","&","CoreML","forward","pass","parity",",","conversion","success",",","ANE","speed-up","and","trivial","example","accuracy","of","ANE-optimized","distilbert","models","for","sequence","classification"]
code: def setUpClass(cls):
      cls.tokenizer = transformers.AutoTokenizer.from_pretrained(
          SEQUENCE_CLASSIFICATION_MODEL
      )
      try:
          cls.models = {
              # Instantiate the reference model from an exemplar pre-trained
              # sequence classification model hosted on huggingface.co/models
              "ref": transformers.AutoModelForSequenceClassification.from_pretrained(
                  SEQUENCE_CLASSIFICATION_MODEL,
                  return_dict=False,
                  torchscript=True,
              ).eval()
          }
      except Exception as e:
          raise RuntimeError(
              "Failed to download reference model from huggingface.co/models!"
          ) from e
      logger.info(
          "Downloaded reference model from huggingface.co/models"
      )
  
      # Initialize an ANE equivalent model and restore the checkpoint
      cls.models[
          "test"
      ] = ane_transformers.DistilBertForSequenceClassification(
          cls.models["ref"].config
      ).eval()
      cls.models["test"].load_state_dict(cls.models["ref"].state_dict())
      logger.info("Initialized and restored test model")
  
      # Cache tokenized inputs and forward pass results on both the reference and test networks
      cls.inputs = cls.tokenizer(
          list(SEQUENCE_CLASSIFICATION_TEST_SET.keys()),
          return_tensors="pt",
          max_length=TEST_MAX_SEQ_LEN,
          padding="max_length",
      )
  
      cls.inputs_list = [
          cls.inputs["input_ids"],
          cls.inputs["attention_mask"],
      ]
      cls.outputs = {
          "ref": cls.models["ref"](*cls.inputs_list)[0]
          .softmax(1)
          .numpy(),
          "test": cls.models["test"](*cls.inputs_list)[0]
          .softmax(1)
          .numpy(),
      }
  
      # Keep numpy copies of the inputs for CoreML testing convenience
      cls.np_inputs = {
          f"input_{name}": tensor.numpy().astype(np.int32)
          for name, tensor in cls.inputs.items()
      }
  
file_path: ml-ane-transformers/ane_transformers/huggingface/test_distilbert.py
imports: from ane_transformers import testing_utils
  import collections
  import coremltools
  import logging
  import numpy
  import unittest
  import time
  import torch
  import transformers
  import distilbert
label_desc: Use image node_id 1 for calling the TestDistilBertForSequenceClassification obj's underlying member method code with example usage: obj.setUpClass(cls) without return types