code: def test_if_inference_output_is_valid(tmpdir):
      """Test that the output inferred from ONNX model is same as from PyTorch."""
      model = BoringModel()
      model.example_input_array = torch.randn(5, 32)
  
      trainer = Trainer(fast_dev_run=True)
      trainer.fit(model)
  
      model.eval()
      with torch.no_grad():
          torch_out = model(model.example_input_array)
  
      file_path = os.path.join(tmpdir, "model.onnx")
      model.to_onnx(
          file_path, model.example_input_array, export_params=True
      )
  
      ort_kwargs = (
          {"providers": "CPUExecutionProvider"}
          if compare_version("onnxruntime", operator.ge, "1.16.0")
          else {}
      )
      ort_session = onnxruntime.InferenceSession(
          file_path, **ort_kwargs
      )
  
      def to_numpy(tensor):
          return (
              tensor.detach().cpu().numpy()
              if tensor.requires_grad
              else tensor.cpu().numpy()
          )
  
      # compute ONNX Runtime output prediction
      ort_inputs = {
          ort_session.get_inputs()[0].name: to_numpy(
              model.example_input_array
          )
      }
      ort_outs = ort_session.run(None, ort_inputs)
  
      # compare ONNX Runtime and PyTorch results
      assert np.allclose(
          to_numpy(torch_out), ort_outs[0], rtol=1e-03, atol=1e-05
      )
  
file_path: pytorch-lightning/tests/tests_pytorch/models/test_onnx.py
imports: import operator
  import os
  from unittest.mock import patch
  import numpy
  import onnxruntime
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning_utilities import compare_version
  import tests_pytorch.helpers.pipelines
  from tests_pytorch.helpers.runif import RunIf
  from tests_pytorch.utilities.test_model_summary import UnorderedModel
label_desc: Use image node_id 7 for calling a global function with example usage: test_if_inference_output_is_valid(tmpdir) and returns: unknown