docstr: Trace a Keras model and convert it into an accelerated module for inference.
  
  :param model: The Keras model to trace.
  :param accelerator: The accelerator to use, defaults to None meaning staying in Keras
                      backend. 'openvino' and 'onnxruntime' are supported for now.
  :param input_spec: (optional) A (tuple or list of) ``tf.TensorSpec``
                     defining the shape/dtype of the input. This is only required when
                     you have a custom Keras model (no input/output layer is explicitly
                     defined).
  :param thread_num: (optional) a int represents how many threads(cores) is needed for
                     inference, only valid for accelerator='onnxruntime'
                     or accelerator='openvino'.
  :param device: (optional) A string represents the device of the inference. Default to 'CPU',
                  only valid when accelerator='openvino', otherwise will be ignored.
                  'CPU', 'GPU' are supported for now.
  :param onnxruntime_session_options: The session option for onnxruntime, only valid when
                                      accelerator='onnxruntime', otherwise will be ignored.
  :param openvino_config: The config to be inputted in core.compile_model. Only valid when
                          accelerator='openvino', otherwise will be ignored.
  :param logging: whether to log detailed information of model conversion, only valid when
                  accelerator='openvino', otherwise will be ignored. Default: ``True``.
  :param **kwargs: Other extra advanced settings include those be passed to model optimizer
                   function of openvino, only valid when accelerator='openvino',
                   otherwise will be ignored.
                   Possible arguments are: mean_values, layout, input, output, et al.
                   For more details about model optimizer, you can see mo --help .
  :return: Model with different acceleration(OpenVINO/ONNX Runtime).
docstr_tok: ["Trace","a","Keras","model","and","convert","it","into","an","accelerated","module","for","inference",".",":","param","model",":","The","Keras","model","to","trace",".",":","param","accelerator",":","The","accelerator","to","use",",","defaults","to","None","meaning","staying","in","Keras","backend",".","'openvino","'","and","'onnxruntime","'","are","supported","for","now",".",":","param","input_spec",":","(","optional",")","A","(","tuple","or","list","of",")","``","tf.TensorSpec","``","defining","the","shape\/dtype","of","the","input",".","This","is","only","required","when","you","have","a","custom","Keras","model","(","no","input\/output","layer","is","explicitly","defined",")",".",":","param","thread_num",":","(","optional",")","a","int","represents","how","many","threads","(","cores",")","is","needed","for","inference",",","only","valid","for","accelerator='onnxruntime'","or","accelerator='openvino","'",".",":","param","device",":","(","optional",")","A","string","represents","the","device","of","the","inference",".","Default","to","'CPU","'",",","only","valid","when","accelerator='openvino","'",",","otherwise","will","be","ignored",".","'CPU","'",",","'GPU","'","are","supported","for","now",".",":","param","onnxruntime_session_options",":","The","session","option","for","onnxruntime",",","only","valid","when","accelerator='onnxruntime","'",",","otherwise","will","be","ignored",".",":","param","openvino_config",":","The","config","to","be","inputted","in","core.compile_model",".","Only","valid","when","accelerator='openvino","'",",","otherwise","will","be","ignored",".",":","param","logging",":","whether","to","log","detailed","information","of","model","conversion",",","only","valid","when","accelerator='openvino","'",",","otherwise","will","be","ignored",".","Default",":","``","True","``",".",":","param","*","*","kwargs",":","Other","extra","advanced","settings","include","those","be","passed","to","model","optimizer","function","of","openvino",",","only","valid","when","accelerator='openvino","'",",","otherwise","will","be","ignored",".","Possible","arguments","are",":","mean_values",",","layout",",","input",",","output",",","et","al",".","For","more","details","about","model","optimizer",",","you","can","see","mo","--","help",".",":","return",":","Model","with","different","acceleration","(","OpenVINO\/ONNX","Runtime",")","."]
code: def trace(
      model: Model,
      accelerator: Optional[str] = None,
      input_spec=None,
      thread_num: Optional[int] = None,
      device: Optional[str] = "CPU",
      onnxruntime_session_options=None,
      openvino_config=None,
      logging=True,
      **kwargs,
  ):
      """
      Trace a Keras model and convert it into an accelerated module for inference.
  
      :param model: The Keras model to trace.
      :param accelerator: The accelerator to use, defaults to None meaning staying in Keras
                          backend. 'openvino' and 'onnxruntime' are supported for now.
      :param input_spec: (optional) A (tuple or list of) ``tf.TensorSpec``
                         defining the shape/dtype of the input. This is only required when
                         you have a custom Keras model (no input/output layer is explicitly
                         defined).
      :param thread_num: (optional) a int represents how many threads(cores) is needed for
                         inference, only valid for accelerator='onnxruntime'
                         or accelerator='openvino'.
      :param device: (optional) A string represents the device of the inference. Default to 'CPU',
                      only valid when accelerator='openvino', otherwise will be ignored.
                      'CPU', 'GPU' are supported for now.
      :param onnxruntime_session_options: The session option for onnxruntime, only valid when
                                          accelerator='onnxruntime', otherwise will be ignored.
      :param openvino_config: The config to be inputted in core.compile_model. Only valid when
                              accelerator='openvino', otherwise will be ignored.
      :param logging: whether to log detailed information of model conversion, only valid when
                      accelerator='openvino', otherwise will be ignored. Default: ``True``.
      :param **kwargs: Other extra advanced settings include those be passed to model optimizer
                       function of openvino, only valid when accelerator='openvino',
                       otherwise will be ignored.
                       Possible arguments are: mean_values, layout, input, output, et al.
                       For more details about model optimizer, you can see mo --help .
      :return: Model with different acceleration(OpenVINO/ONNX Runtime).
      """
      # device name might be: CPU, GPU, GPU.0, VPUX ...
      invalidInputError(
          device == "CPU" or "GPU" in device,
          "Now we only support fp32 for CPU and GPU, not {}".format(
              device
          ),
      )
      if device != "CPU" and accelerator != "openvino":
          invalidInputError(
              False,
              "Now we only support {} device when accelerator "
              "is openvino.".format(device),
          )
      if accelerator == "openvino":
          final_openvino_option = (
              {"INFERENCE_PRECISION_HINT": "f32"}
              if device == "CPU"
              else {}
          )
          if openvino_config is not None:
              final_openvino_option.update(openvino_config)
          result = KerasOpenVINOModel(
              model,
              input_spec=input_spec,
              precision="fp32",
              thread_num=thread_num,
              device=device,
              config=final_openvino_option,
              logging=logging,
              **kwargs,
          )
      elif accelerator == "onnxruntime":
          if onnxruntime_session_options is None:
              import onnxruntime
  
              onnxruntime_session_options = onnxruntime.SessionOptions()
          if thread_num is not None:
              onnxruntime_session_options.intra_op_num_threads = (
                  thread_num
              )
              onnxruntime_session_options.inter_op_num_threads = (
                  thread_num
              )
          result = KerasONNXRuntimeModel(
              model, input_spec, onnxruntime_session_options
          )
      else:
          invalidInputError(
              False, "Accelerator {} is invalid.".format(accelerator)
          )
      return patch_compiled_and_attrs(result, model)
  
imports: import os
  import subprocess
  import tempfile
  import cloudpickle
  import copy
  import time
  import operator
  from pathlib import Path
  import numpy
  import traceback
  import inspect
  import sigfig
  import tensorflow
  import keras
  from typing import Dict, Optional, List, Union, Callable
  from bigdl.nano.utils.common import BaseInferenceOptimizer, available_acceleration_combination, AccelerationOption, latency_calculate_helper, format_optimize_result
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.nano.utils.tf import _ModuleWrapper
  from bigdl.nano.utils.tf import patch_compiled_and_attrs, patch_attrs
  from tensorflow.keras import Model
  from tensorflow.data import Dataset
  from tensorflow.keras.metrics import Metric
  from bigdl.nano.deps.neural_compressor.inc_api import quantize
  from bigdl.nano.deps.openvino.openvino_api import KerasOpenVINOModel
  from bigdl.nano.deps.onnxruntime.onnxruntime_api import KerasONNXRuntimeModel
  from bigdl.nano.deps.openvino.openvino_api import load_openvino_model
  from bigdl.nano.deps.onnxruntime.onnxruntime_api import load_onnxruntime_model
  from bigdl.nano.deps.neural_compressor.inc_api import load_inc_model
  from bigdl.nano.tf.keras.amp import BF16Model, load_bf16_model
  from bigdl.nano.utils.common import compare_version
  from bigdl.nano.utils.tf import try_fake_inference
label_desc: Use image node_id 2 for calling the InferenceOptimizer obj's underlying member method code with example usage: obj.trace(model, accelerator, input_spec, thread_num, device, onnxruntime_session_options, openvino_config, logging) and returns: patch_compiled_and_attrs