docstr: Create a OpenVINO model from pytorch.
  
  :param model: Pytorch model to be converted to OpenVINO for inference or
                path to Openvino saved model.
  :param input_sample: A set of inputs for trace, defaults to None if you have trace before or
                       model is a LightningModule with any dataloader attached,
                       defaults to None.
  :param precision: Global precision of model, supported type: 'fp32', 'fp16',
                    defaults to 'fp32'.
  :param thread_num: a int represents how many threads(cores) is needed for
                     inference. default: None.
  :param device: A string represents the device of the inference. Default to 'CPU'.
                 'CPU', 'GPU' and 'VPUX' are supported for now.
  :param dynamic_axes: dict or boolean, default to True. By default the exported onnx model
                       will have the first dim of each Tensor input as a dynamic batch_size.
                       If dynamic_axes=False, the exported model will have the shapes of all
                       input and output tensors set to exactly match those given in
                       input_sample. To specify axes of tensors as dynamic (i.e. known only
                       at run-time), set dynamic_axes to a dict with schema:
  
                       | KEY (str): an input or output name. Each name must also be provided
                       | in input_names or output_names.
                       |
                       | VALUE (dict or list): If a dict, keys are axis indices and values
                       | are axis names. If a list, each element is an axis index.
  
                       If accelerator != 'openvino'/'onnxruntime', it will be ignored.
  :param logging: whether to log detailed information of model conversion. default: True.
  :param config: The config to be inputted in core.compile_model.
  :param output_tensors: boolean, default to True and output of the model will be Tensors. If
                         output_tensors=False, output of the OpenVINO model will be ndarray.
  :param shapes: input shape. For example, 'input1[1,3,224,224],input2[1,4]',
                 '[1,3,224,224]'. This parameter affect model Parameter shape, can be
                 dynamic. For dynamic dimesions use symbol `?`, `-1` or range `low.. up`.'.
                 Only valid for openvino model, otherwise will be ignored.
  :param output_metadata: metadata of model output, defaults to None.
  :param **kwargs: will be passed to torch.onnx.export function or model optimizer function.
docstr_tok: ["Create","a","OpenVINO","model","from","pytorch",".",":","param","model",":","Pytorch","model","to","be","converted","to","OpenVINO","for","inference","or","path","to","Openvino","saved","model",".",":","param","input_sample",":","A","set","of","inputs","for","trace",",","defaults","to","None","if","you","have","trace","before","or","model","is","a","LightningModule","with","any","dataloader","attached",",","defaults","to","None",".",":","param","precision",":","Global","precision","of","model",",","supported","type",":","'fp32","'",",","'fp16","'",",","defaults","to","'fp32","'",".",":","param","thread_num",":","a","int","represents","how","many","threads","(","cores",")","is","needed","for","inference",".","default",":","None",".",":","param","device",":","A","string","represents","the","device","of","the","inference",".","Default","to","'CPU","'",".","'CPU","'",",","'GPU","'","and","'VPUX","'","are","supported","for","now",".",":","param","dynamic_axes",":","dict","or","boolean",",","default","to","True",".","By","default","the","exported","onnx","model","will","have","the","first","dim","of","each","Tensor","input","as","a","dynamic","batch_size",".","If","dynamic_axes=False",",","the","exported","model","will","have","the","shapes","of","all","input","and","output","tensors","set","to","exactly","match","those","given","in","input_sample",".","To","specify","axes","of","tensors","as","dynamic","(","i.e",".","known","only","at","run-time",")",",","set","dynamic_axes","to","a","dict","with","schema",":","|","KEY","(","str",")",":","an","input","or","output","name",".","Each","name","must","also","be","provided","|","in","input_names","or","output_names",".","|","|","VALUE","(","dict","or","list",")",":","If","a","dict",",","keys","are","axis","indices","and","values","|","are","axis","names",".","If","a","list",",","each","element","is","an","axis","index",".","If","accelerator","!","=","'openvino'\/'onnxruntime","'",",","it","will","be","ignored",".",":","param","logging",":","whether","to","log","detailed","information","of","model","conversion",".","default",":","True",".",":","param","config",":","The","config","to","be","inputted","in","core.compile_model",".",":","param","output_tensors",":","boolean",",","default","to","True","and","output","of","the","model","will","be","Tensors",".","If","output_tensors=False",",","output","of","the","OpenVINO","model","will","be","ndarray",".",":","param","shapes",":","input","shape",".","For","example",",","'input1","[","1,3,224,224","]",",","input2","[","1,4","]","'",",","'","[","1,3,224,224","]","'",".","This","parameter","affect","model","Parameter","shape",",","can","be","dynamic",".","For","dynamic","dimesions","use","symbol","`","?","`",",","`","-1","`","or","range","`","low","..","up","`",".","'",".","Only","valid","for","openvino","model",",","otherwise","will","be","ignored",".",":","param","output_metadata",":","metadata","of","model","output",",","defaults","to","None",".",":","param","*","*","kwargs",":","will","be","passed","to","torch.onnx.export","function","or","model","optimizer","function","."]
code: def __init__(
      self,
      model,
      input_sample=None,
      precision="fp32",
      thread_num=None,
      device="CPU",
      dynamic_axes=True,
      logging=True,
      config=None,
      output_tensors=True,
      shapes=None,
      output_metadata=None,
      **kwargs,
  ):
      """
      Create a OpenVINO model from pytorch.
  
      :param model: Pytorch model to be converted to OpenVINO for inference or
                    path to Openvino saved model.
      :param input_sample: A set of inputs for trace, defaults to None if you have trace before or
                           model is a LightningModule with any dataloader attached,
                           defaults to None.
      :param precision: Global precision of model, supported type: 'fp32', 'fp16',
                        defaults to 'fp32'.
      :param thread_num: a int represents how many threads(cores) is needed for
                         inference. default: None.
      :param device: A string represents the device of the inference. Default to 'CPU'.
                     'CPU', 'GPU' and 'VPUX' are supported for now.
      :param dynamic_axes: dict or boolean, default to True. By default the exported onnx model
                           will have the first dim of each Tensor input as a dynamic batch_size.
                           If dynamic_axes=False, the exported model will have the shapes of all
                           input and output tensors set to exactly match those given in
                           input_sample. To specify axes of tensors as dynamic (i.e. known only
                           at run-time), set dynamic_axes to a dict with schema:
  
                           | KEY (str): an input or output name. Each name must also be provided
                           | in input_names or output_names.
                           |
                           | VALUE (dict or list): If a dict, keys are axis indices and values
                           | are axis names. If a list, each element is an axis index.
  
                           If accelerator != 'openvino'/'onnxruntime', it will be ignored.
      :param logging: whether to log detailed information of model conversion. default: True.
      :param config: The config to be inputted in core.compile_model.
      :param output_tensors: boolean, default to True and output of the model will be Tensors. If
                             output_tensors=False, output of the OpenVINO model will be ndarray.
      :param shapes: input shape. For example, 'input1[1,3,224,224],input2[1,4]',
                     '[1,3,224,224]'. This parameter affect model Parameter shape, can be
                     dynamic. For dynamic dimesions use symbol `?`, `-1` or range `low.. up`.'.
                     Only valid for openvino model, otherwise will be ignored.
      :param output_metadata: metadata of model output, defaults to None.
      :param **kwargs: will be passed to torch.onnx.export function or model optimizer function.
      """
      self.output_metadata = output_metadata
      ov_model_path = model
      with TemporaryDirectory() as tmpdir:
          tmpdir = Path(tmpdir)
          if isinstance(model, torch.nn.Module):
              # cope with dynamic axes for GPU
              if device != "CPU":
                  if dynamic_axes is True or (
                      isinstance(dynamic_axes, dict)
                      and len(dynamic_axes) > 0
                  ):
                      invalidInputError(
                          "input_shape" in kwargs,
                          "For model has dynamic axes, if you want to inference on "
                          "non-CPU device, must define input_shape for model "
                          "optimizer. For more details about model optimizer, you "
                          "can see mo --help .",
                      )
              export(
                  model,
                  input_sample,
                  str(tmpdir / "tmp.xml"),
                  precision=precision,
                  dynamic_axes=dynamic_axes,
                  logging=logging,
                  **kwargs,
              )
              ov_model_path = tmpdir / "tmp.xml"
  
              # test run to get output metadata
              with BaseContextManager():
                  forward_args = get_forward_args(model)
                  input_sample = get_input_example(
                      model, input_sample, forward_args
                  )
                  if isinstance(input_sample, (list, tuple)):
                      output = model(*input_sample)
                  else:
                      output = model(input_sample)
                  self.output_metadata = MetaData.construct_matadata(
                      output
                  )
  
          self.ov_model = OpenVINOModel(
              ov_model_path,
              device=device,
              precision=precision,
              thread_num=thread_num,
              config=config,
              shapes=shapes,
          )
          super().__init__(None)
      self._nano_context_manager = generate_context_manager(
          accelerator="openvino",
          precision="fp32",
          thread_num=thread_num,
      )
      if isinstance(model, torch.nn.Module):
          # patch original model's attr to current new model
          patch_attrs_from_model_to_object(model, self)
      self.output_tensors = output_tensors
  
imports: from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import List, Union
  from .dataloader import PytorchOpenVINODataLoader
  from .metric import PytorchOpenVINOMetric
  from ..core.model import OpenVINOModel
  from bigdl.nano.pytorch.model import AcceleratedLightningModule
  from .utils import export
  import torch
  from bigdl.nano.utils.common import invalidInputError
  from ..core.utils import save
  from torch.utils.data.dataloader import DataLoader
  from bigdl.nano.pytorch.context_manager import generate_context_manager, BaseContextManager
  from bigdl.nano.utils.pytorch import get_input_example, get_forward_args, patch_attrs_from_model_to_object, MetaData
  from bigdl.nano.utils.common import SafePickle
label_desc: Use image node_id 1 to create a new PytorchOpenVINOModel object from inherited base classes: AcceleratedLightningModule with example: obj = PytorchOpenVINOModel(model, input_sample, precision, thread_num, device, dynamic_axes, logging, config, output_tensors, shapes, output_metadata)