code: def _compare_pytorch_onnx_with_ort(
      onnx_program: torch.onnx.ONNXProgram,
      model: _ModelType,
      input_args: Sequence[_InputArgsType],
      input_kwargs: Mapping[str, _InputArgsType],
      atol: Optional[float] = None,
      rtol: Optional[float] = None,
      has_mutation: bool = False,
  ):
      if has_mutation:
          ref_model = _try_clone_model(model)
          ref_input_args, ref_input_kwargs = _try_clone_inputs(
              input_args, input_kwargs
          )
      else:
          ref_model = model
          ref_input_args = input_args
          ref_input_kwargs = input_kwargs
  
      # NOTE: ONNXProgram holds a reference (not copy) to the original ref_model, including its state_dict.
      # Thus, ONNXProgram() must run before ref_model() to prevent ref_model.forward() from changing the state_dict.
      # Otherwise, the ref_model can change buffers on state_dict which would be used by ONNXProgram.__call__()
      # NOTE: `model_with_state_dict=ref_model` is specified to cover runs with FakeTensor support
      ort_outputs = onnx_program(*input_args, **input_kwargs)
      ref_outputs = ref_model(*ref_input_args, **ref_input_kwargs)
      ref_outputs = onnx_program.adapt_torch_outputs_to_onnx(
          ref_outputs
      )
  
      if len(ref_outputs) != len(ort_outputs):
          raise AssertionError(
              f"Expected {len(ref_outputs)} outputs, got {len(ort_outputs)}"
          )
  
      for ref_output, ort_output in zip(ref_outputs, ort_outputs):
          torch.testing.assert_close(
              ref_output, torch.tensor(ort_output), rtol=rtol, atol=atol
          )
  
imports: from __future__ import annotations
  import contextlib
  import copy
  import dataclasses
  import io
  import logging
  import os
  import unittest
  import warnings
  from typing import Any, Callable, Collection, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, Union
  import numpy
  import onnxruntime
  import pytest
  import pytorch_test_common
  import torch
  from torch import export
  from torch.onnx import _constants, verification
  from torch.onnx._internal import _beartype
  from torch.onnx._internal.fx import diagnostics
  from torch.testing._internal import common_utils
  from torch.testing._internal.opinfo import core
  from torch.types import Number
label_desc: Use image node_id 7 for calling a global function with example usage: _compare_pytorch_onnx_with_ort(onnx_program, model, input_args, input_kwargs, atol, rtol, has_mutation) without return types