


from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch






@require_torch
@require_tf
class    _UpperCamelCase     (       __snake_case					):

				"""simple docstring"""







				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					SMALL_MODEL_IDENTIFIER
					A             =					"""pt"""
					A             =					"""tf"""

				def   _UpperCAmelCase       (    self					, a__ )						->					List[str]:
					A             =					AutoModel.from_pretrained(self.test_model )
					model_pt.save_pretrained(a__ )

				def   _UpperCAmelCase       (    self					, a__ )						->					int:
					A             =					TFAutoModel.from_pretrained(self.test_model					, from_pt=a__ )
					model_tf.save_pretrained(a__ )

				def   _UpperCAmelCase       (    self )						->					List[Any]:
					A             =					"""mock_framework"""

					# Framework provided - return whatever the user provides
					A             =					FeaturesManager.determine_framework(self.test_model					, a__ )
					self.assertEqual(a__					, a__ )

					# Local checkpoint and framework provided - return provided framework
					# PyTorch checkpoint
					with TemporaryDirectory() as local_pt_ckpt:
						self._setup_pt_ckpt(a__ )
						A             =					FeaturesManager.determine_framework(a__					, a__ )
						self.assertEqual(a__					, a__ )

					# TensorFlow checkpoint
					with TemporaryDirectory() as local_tf_ckpt:
						self._setup_tf_ckpt(a__ )
						A             =					FeaturesManager.determine_framework(a__					, a__ )
						self.assertEqual(a__					, a__ )

				def   _UpperCAmelCase       (    self )						->					int:
					# PyTorch checkpoint
					with TemporaryDirectory() as local_pt_ckpt:
						self._setup_pt_ckpt(a__ )
						A             =					FeaturesManager.determine_framework(a__ )
						self.assertEqual(a__					, self.framework_pt )

					# TensorFlow checkpoint
					with TemporaryDirectory() as local_tf_ckpt:
						self._setup_tf_ckpt(a__ )
						A             =					FeaturesManager.determine_framework(a__ )
						self.assertEqual(a__					, self.framework_tf )

					# Invalid local checkpoint
					with TemporaryDirectory() as local_invalid_ckpt:
						with self.assertRaises(a__ ):
							A             =					FeaturesManager.determine_framework(a__ )

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					MagicMock(return_value=a__ )
					with patch("""transformers.onnx.features.is_tf_available"""					, a__ ):
						A             =					FeaturesManager.determine_framework(self.test_model )
						self.assertEqual(a__					, self.framework_pt )

					# PyTorch not in environment -> use TensorFlow
					A             =					MagicMock(return_value=a__ )
					with patch("""transformers.onnx.features.is_torch_available"""					, a__ ):
						A             =					FeaturesManager.determine_framework(self.test_model )
						self.assertEqual(a__					, self.framework_tf )

					# Both in environment -> use PyTorch
					A             =					MagicMock(return_value=a__ )
					A             =					MagicMock(return_value=a__ )
					with patch("""transformers.onnx.features.is_tf_available"""					, a__ ), patch(
					    """transformers.onnx.features.is_torch_available"""					, a__ ):
						A             =					FeaturesManager.determine_framework(self.test_model )
						self.assertEqual(a__					, self.framework_pt )

					# Both not in environment -> raise error
					A             =					MagicMock(return_value=a__ )
					A             =					MagicMock(return_value=a__ )
					with patch("""transformers.onnx.features.is_tf_available"""					, a__ ), patch(
					    """transformers.onnx.features.is_torch_available"""					, a__ ):
						with self.assertRaises(a__ ):
							A             =					FeaturesManager.determine_framework(self.test_model )







def 	_lowerCAmelCase					( UpperCamelCase__:  Union[str, Any]    )			-> Dict:





	"""simple docstring"""







	return [
	    {
	        0: [1, 2],
	        1: [0, 2],
	        2: [0, 1, 3, 5],
	        3: [2, 4],
	        4: [3],
	        5: [2, 6, 8],
	        6: [5, 7],
	        7: [6, 8],
	        8: [5, 7],
	    },
	    {
	        0: [6],
	        1: [9],
	        2: [4, 5],
	        3: [4],
	        4: [2, 3],
	        5: [2],
	        6: [0, 7],
	        7: [6],
	        8: [],
	        9: [1],
	    },
	    {
	        0: [4],
	        1: [6],
	        2: [],
	        3: [5, 6, 7],
	        4: [0, 6],
	        5: [3, 8, 9],
	        6: [1, 3, 4, 7],
	        7: [3, 6, 8, 9],
	        8: [5, 7],
	        9: [5, 7],
	    },
	    {
	        0: [1, 3],
	        1: [0, 2, 4],
	        2: [1, 3, 4],
	        3: [0, 2, 4],
	        4: [1, 2, 3],
	    },
	][index]





def 	_lowerCAmelCase					( UpperCamelCase__:  dict[int, list[int]]    )			-> list[tuple[int, int]]:





	"""simple docstring"""







	A             =					0
	A             =					len(UpperCamelCase__    )  # No of vertices in graph
	A             =					[0] * n
	A             =					[False] * n

	def dfs(UpperCamelCase__:  Union[str, Any]				,       UpperCamelCase__:  str				,       UpperCamelCase__:  Union[str, Any]				,       UpperCamelCase__:  Any    ):
		A             =					True
		A             =					id_
		id_ += 1
		for to in graph[at]:
			if to == parent:
				pass
			elif not visited[to]:
				dfs(UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__				,       id_    )
				A             =					min(low[at]				,       low[to]    )
				if id_ <= low[to]:
					bridges.append((at, to) if at < to else (to, at)    )
			else:
				# This edge is a back edge and cannot be a bridge
				A             =					min(low[at]				,       low[to]    )

	A             =					[]
	for i in range(UpperCamelCase__    ):
		if not visited[i]:
			dfs(UpperCamelCase__				,       -1				,       UpperCamelCase__				,       id_    )
	return bridges


if __name__ == "__main__":
				import doctest

				doctest.testmod()



