code: def test_onnx_ort():
      with TemporaryDirectory() as tmp_dir:
          model = models.resnet18()
          input_data = [
              ((torch.randn(1, 3, 256, 256),), 0) for i in range(100)
          ]
          model_path = torch_to_onnx(model, input_data, tmp_dir)
  
          input_data = [
              ((np.random.randn(1, 3, 256, 256).astype(np.float32),), 0)
              for i in range(100)
          ]
  
          # Run nebullvm optimization in one line of code
          optimized_model = optimize_model(
              model_path,
              input_data=input_data,
              ignore_compilers=[
                  compiler
                  for compiler in COMPILER_LIST
                  if compiler != "onnxruntime"
              ],
              ignore_compressors=[
                  compressor for compressor in COMPRESSOR_LIST
              ],
          )
  
          with TemporaryDirectory() as tmp_dir:
              optimized_model.save(tmp_dir)
              loaded_model = load_model(tmp_dir)
              assert isinstance(loaded_model, NumpyONNXInferenceLearner)
  
              assert isinstance(loaded_model.get_size(), int)
  
              # Try the optimized model
              device = torch.device(
                  "cuda" if torch.cuda.is_available() else "cpu"
              )
              x = torch.randn(1, 3, 256, 256, requires_grad=False)
              model.to(device).eval()
              with torch.inference_mode():
                  res_original = model(x.to(device))
              res_optimized = optimized_model(x.numpy())[0]
  
              assert (
                  abs(
                      (
                          res_original.detach().cpu().numpy()
                          - res_optimized
                      )
                  ).max()
                  < 1e-2
              )
  
file_path: nebuly/optimization/speedster/speedster/api/tests/test_onnx.py
imports: import cpuinfo
  from tempfile import TemporaryDirectory
  import numpy
  import pytest
  import torch
  from nebullvm.config import COMPILER_LIST, COMPRESSOR_LIST
  from nebullvm.operations.inference_learners.onnx import NumpyONNXInferenceLearner
  from nebullvm.operations.inference_learners.openvino import NumpyOpenVinoInferenceLearner
  from nebullvm.operations.inference_learners.tensor_rt import NumpyONNXTensorRTInferenceLearner
  from nebullvm.operations.inference_learners.tvm import NumpyApacheTVMInferenceLearner
  from nebullvm.operations.optimizations.compilers.utils import tvm_is_available
  from torchvision import models
  from speedster import optimize_model, load_model
  from speedster.api.tests.utils import torch_to_onnx
label_desc: Use image node_id 1 for calling a global function with example usage: test_onnx_ort() without return types