docstr: Traces a model and runs a numerical test.
  Args:
      input_as_shape <bool>: If true generates random input data with shape.
      expected_results <iterable, optional>: Expected result from running pytorch model.
      converter_input_type: If not None, then pass it to the "inputs" argument to the
          ct.convert() call.
      frontend: Either TorchFrontend.TORCHSCRIPT or TorchFrontend.EDGEIR
docstr_tok: ["Traces","a","model","and","runs","a","numerical","test",".","Args",":","input_as_shape","<","bool",">",":","If","true","generates","random","input","data","with","shape",".","expected_results","<","iterable",",","optional",">",":","Expected","result","from","running","pytorch","model",".","converter_input_type",":","If","not","None",",","then","pass","it","to","the","``","inputs","''","argument","to","the","ct.convert","(",")","call",".","frontend",":","Either","TorchFrontend.TORCHSCRIPT","or","TorchFrontend.EDGEIR"]
code: def run_compare_torch(
      input_data,
      model,
      expected_results=None,
      atol=1e-04,
      rtol=1e-05,
      input_as_shape=True,
      backend=("neuralnetwork", "fp32"),
      rand_range=(-1.0, 1.0),
      use_scripting=False,
      converter_input_type=None,
      compute_unit=ct.ComputeUnit.CPU_ONLY,
      minimum_deployment_target=None,
      torch_device=torch.device("cpu"),
      frontend=TorchFrontend.TORCHSCRIPT,
  ):
      """
      Traces a model and runs a numerical test.
      Args:
          input_as_shape <bool>: If true generates random input data with shape.
          expected_results <iterable, optional>: Expected result from running pytorch model.
          converter_input_type: If not None, then pass it to the "inputs" argument to the
              ct.convert() call.
          frontend: Either TorchFrontend.TORCHSCRIPT or TorchFrontend.EDGEIR
      """
      if minimum_deployment_target is not None:
          validate_minimum_deployment_target(
              minimum_deployment_target, backend
          )
  
      model.eval()
      if input_as_shape:
          input_data = generate_input_data(
              input_data, rand_range, torch_device
          )
  
      if frontend == TorchFrontend.TORCHSCRIPT:
          if use_scripting:
              model_spec = torch.jit.script(model)
          else:
              model_spec = trace_model(
                  model, _copy_input_data(input_data)
              )
      elif frontend == TorchFrontend.EDGEIR:
          input_data_clone = _copy_input_data(input_data)
          if isinstance(input_data_clone, list):
              input_data_clone = tuple(input_data_clone)
          elif isinstance(input_data_clone, torch.Tensor):
              input_data_clone = (input_data_clone,)
          model_spec = (
              exir.capture(model, input_data_clone, _CAPTURE_CONFIG)
              .to_edge(_EDGE_COMPILE_CONFIG)
              .exported_program
          )
      else:
          raise ValueError(
              f"Unknown value of frontend. Needs to be either TorchFrontend.TORCHSCRIPT or TorchFrontend.EDGEIR. Provided: {frontend}"
          )
  
      (
          model_spec,
          mlmodel,
          coreml_inputs,
          coreml_results,
      ) = convert_and_compare(
          input_data,
          model_spec,
          expected_results=expected_results,
          atol=atol,
          rtol=rtol,
          backend=backend,
          converter_input_type=converter_input_type,
          compute_unit=compute_unit,
          minimum_deployment_target=minimum_deployment_target,
      )
  
      return (
          model_spec,
          mlmodel,
          coreml_inputs,
          coreml_results,
          TorchBaseTest.testclassname,
          TorchBaseTest.testmodelname,
      )
  
imports: import numpy
  import pytest
  import torch
  import torch.nn
  import coremltools
  import coremltools.models.utils
  from coremltools import RangeDim, TensorType
  from coremltools._deps import _HAS_EXECUTORCH, _HAS_TORCH_EXPORT_API, _IS_MACOS
  from coremltools.converters.mil.mil.types.type_mapping import nptype_from_builtin
  from coremltools.converters.mil.testing_utils import ct_convert, validate_minimum_deployment_target
  from ..ops import TorchFrontend
  from ..torchscript_utils import torch_to_mil_types
label_desc: Use image node_id 2 for calling the TorchBaseTest obj's underlying member method code with example usage: obj.run_compare_torch(input_data, model, expected_results, atol, rtol, input_as_shape, backend, rand_range, use_scripting, converter_input_type, compute_unit, minimum_deployment_target, torch_device, frontend) and returns: model_spec,  mlmodel,  coreml_inputs,  coreml_results,  TorchBaseTest,  TorchBaseTest