code: def test_model_outputs_equivalence(self):
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
  
      def set_nan_tensor_to_zero(t):
          t[t != t] = 0
          return t
  
      def check_equivalence(
          model, tuple_inputs, dict_inputs, additional_kwargs={}
      ):
          with torch.no_grad():
              tuple_output = model(
                  **tuple_inputs, return_dict=False, **additional_kwargs
              )
              dict_output = model(
                  **dict_inputs, return_dict=True, **additional_kwargs
              ).to_tuple()
  
              def recursive_check(tuple_object, dict_object):
                  if isinstance(tuple_object, (List, Tuple)):
                      for (
                          tuple_iterable_value,
                          dict_iterable_value,
                      ) in zip(tuple_object, dict_object):
                          recursive_check(
                              tuple_iterable_value, dict_iterable_value
                          )
                  elif tuple_object is None:
                      return
                  else:
                      self.assertTrue(
                          torch.allclose(
                              set_nan_tensor_to_zero(tuple_object),
                              set_nan_tensor_to_zero(dict_object),
                              atol=1e-5,
                          ),
                          msg=(
                              "Tuple and dict output are not equal. Difference:"
                              f" {torch.max(torch.abs(tuple_object - dict_object))}. Tuple has `nan`:"
                              f" {torch.isnan(tuple_object).any()} and `inf`: {torch.isinf(tuple_object)}. Dict has"
                              f" `nan`: {torch.isnan(dict_object).any()} and `inf`: {torch.isinf(dict_object)}."
                          ),
                      )
  
              recursive_check(tuple_output, dict_output)
  
      for model_class in self.all_model_classes:
          print(model_class)
          model = model_class(config)
          model.to(torch_device)
          model.eval()
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class
          )
          check_equivalence(model, tuple_inputs, dict_inputs)
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          check_equivalence(model, tuple_inputs, dict_inputs)
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class
          )
          check_equivalence(
              model,
              tuple_inputs,
              dict_inputs,
              {"output_hidden_states": True},
          )
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class
          )
          check_equivalence(
              model,
              tuple_inputs,
              dict_inputs,
              {"output_attentions": True},
          )
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          check_equivalence(
              model,
              tuple_inputs,
              dict_inputs,
              {"output_hidden_states": True},
          )
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          check_equivalence(
              model,
              tuple_inputs,
              dict_inputs,
              {"output_attentions": True},
          )
  
          tuple_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          dict_inputs = self._prepare_for_class(
              inputs_dict, model_class, return_labels=True
          )
          check_equivalence(
              model,
              tuple_inputs,
              dict_inputs,
              {"output_hidden_states": True, "output_attentions": True},
          )
  
imports: import unittest
  from typing import List, Tuple
  from transformers import CanineConfig, is_torch_available
  from transformers.testing_utils import require_torch, slow, torch_device
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, _config_zero_init, global_rng, ids_tensor, random_attention_mask
label_desc: Use image node_id 10 for calling the CanineModelTest obj's underlying member method code with example usage: obj.test_model_outputs_equivalence() and returns: t