


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 			_a				(     UpperCamelCase__     ):

							def  lowerCamelCase_					(				self:      Dict				)     ->  List[str]:





									"""simple docstring"""







									lowercase__				= SMALL_MODEL_IDENTIFIER
									lowercase__				= '''pt'''
									lowercase__				= '''tf'''

							def  lowerCamelCase_					(				self:      List[str]       ,		UpperCamelCase_:      Any				)     ->  int:





									"""simple docstring"""







									lowercase__				= AutoModel.from_pretrained(self.test_model				)
									model_pt.save_pretrained(UpperCamelCase_				)

							def  lowerCamelCase_					(				self:      Optional[Any]       ,		UpperCamelCase_:      Tuple				)     ->  List[Any]:





									"""simple docstring"""







									lowercase__				= TFAutoModel.from_pretrained(self.test_model       ,		from_pt=UpperCamelCase_				)
									model_tf.save_pretrained(UpperCamelCase_				)

							def  lowerCamelCase_					(				self:      str				)     ->  Any:





									"""simple docstring"""







									lowercase__				= '''mock_framework'''

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

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

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

							def  lowerCamelCase_					(				self:      Any				)     ->  Any:





									"""simple docstring"""







									with TemporaryDirectory() as local_pt_ckpt:
											self._setup_pt_ckpt(UpperCamelCase_				)
											lowercase__				= FeaturesManager.determine_framework(UpperCamelCase_				)
											self.assertEqual(UpperCamelCase_       ,		self.framework_pt				)

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

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


							def  lowerCamelCase_					(				self:      int				)     ->  Any:





									"""simple docstring"""







									lowercase__				= MagicMock(return_value=UpperCamelCase_				)
									with patch('''transformers.onnx.features.is_tf_available'''       ,		UpperCamelCase_				):
											lowercase__				= FeaturesManager.determine_framework(self.test_model				)
											self.assertEqual(UpperCamelCase_       ,		self.framework_pt				)

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

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

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




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase    :   Tuple						=			{
    'configuration_luke': ['LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LukeConfig'],
    'tokenization_luke': ['LukeTokenizer'],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase    :   int						=			[
		    'LUKE_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'LukeForEntityClassification',
		    'LukeForEntityPairClassification',
		    'LukeForEntitySpanClassification',
		    'LukeForMultipleChoice',
		    'LukeForQuestionAnswering',
		    'LukeForSequenceClassification',
		    'LukeForTokenClassification',
		    'LukeForMaskedLM',
		    'LukeModel',
		    'LukePreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig
		from .tokenization_luke import LukeTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_luke import (
				    LUKE_PRETRAINED_MODEL_ARCHIVE_LIST,
				    LukeForEntityClassification,
				    LukeForEntityPairClassification,
				    LukeForEntitySpanClassification,
				    LukeForMaskedLM,
				    LukeForMultipleChoice,
				    LukeForQuestionAnswering,
				    LukeForSequenceClassification,
				    LukeForTokenClassification,
				    LukeModel,
				    LukePreTrainedModel,
				)

else:
		import sys

		lowercase    :   Any						=			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)