class_docstr: Parameters
  ----------
  model : pytorch model
      The model to speedup by quantization.
  input_shape : tuple
      The input shape of the model, shall pass it to torch.onnx.export.
      Note, the batch size of input_shape is the inference batch of the created trt engine,
      it should be equal to the batch size of running test with the engine.
  config : dict
      Config recording bits number and name of layers.
  onnx_path : str
      The path user want to store onnx model which is converted from pytorch model.
docstr: Do inference by tensorrt builded engine.
  Note, the batch size of test_data should be equal to the batch size used in building the engine.
  
  Parameters
  ----------
  test_data : pytorch tensor
      Model input tensor, the first dimension should be batch dimension.
  reset_context : bool
      whether reset the engine context.
  
  Returns
  -------
  torch.Tensor
      the flattened tensor (Note, this value may be changed after the next inference).
  float
      the time span of the inference
docstr_tok: ["Do","inference","by","tensorrt","builded","engine",".","Note",",","the","batch","size","of","test_data","should","be","equal","to","the","batch","size","used","in","building","the","engine",".","Parameters","--","--","--","--","--","test_data",":","pytorch","tensor","Model","input","tensor",",","the","first","dimension","should","be","batch","dimension",".","reset_context",":","bool","whether","reset","the","engine","context",".","Returns","--","--","--","-","torch.Tensor","the","flattened","tensor","(","Note",",","this","value","may","be","changed","after","the","next","inference",")",".","float","the","time","span","of","the","inference"]
code: def inference(self, test_data, reset_context=False):
      """
      Do inference by tensorrt builded engine.
      Note, the batch size of test_data should be equal to the batch size used in building the engine.
  
      Parameters
      ----------
      test_data : pytorch tensor
          Model input tensor, the first dimension should be batch dimension.
      reset_context : bool
          whether reset the engine context.
  
      Returns
      -------
      torch.Tensor
          the flattened tensor (Note, this value may be changed after the next inference).
      float
          the time span of the inference
      """
      if self.context is None or reset_context:
          self.context = self.engine.create_execution_context()
          (
              self.inputs,
              self.outputs,
              self.bindings,
              self.stream,
          ) = common.allocate_buffers(self.engine)
          self.context.set_optimization_profile_async(
              0, self.stream.handle
          )
  
      engine_input_shape = self.engine.get_binding_shape(0)
      assert engine_input_shape[0] == test_data.size()[0]
      if test_data.device != torch.device("cpu"):
          logger.warning("test_data should be placed on CPU.")
          test_data = test_data.to(torch.device("cpu"))
      test_data = test_data.numpy()
      assert test_data.dtype == np.float32
  
      np.copyto(self.inputs[0].host, test_data.ravel())
      start_time = time.time()
      trt_outputs = common.do_inference_v2(
          self.context,
          bindings=self.bindings,
          inputs=self.inputs,
          outputs=self.outputs,
          stream=self.stream,
      )
      time_span = time.time() - start_time
      return torch.as_tensor(trt_outputs[0]), time_span
  
imports: import time
  import logging
  import tensorrt
  import numpy
  import torch
  from .None import frontend_to_onnx
  from .None import trt_pycuda
  from .backend import BaseModelSpeedup
label_desc: Use image node_id 4 for calling the ModelSpeedupTensorRT obj's underlying member method code with example usage: obj.inference(test_data, reset_context) and returns: torch,  time_span