





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    (    lowerCAmelCase ):

			'''simple docstring'''







			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				lowerCamelCase__								=		SMALL_MODEL_IDENTIFIER
				lowerCamelCase__								=		'''pt'''
				lowerCamelCase__								=		'''tf'''





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__								=		AutoModel.from_pretrained(self.test_model							)
				model_pt.save_pretrained(__lowerCAmelCase							)





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__								=		TFAutoModel.from_pretrained(self.test_model       ,  from_pt=__lowerCAmelCase							)
				model_tf.save_pretrained(__lowerCAmelCase							)





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				lowerCamelCase__								=		'''mock_framework'''

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

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

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





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







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

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

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





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







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

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

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

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










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_a 						=      {
    "configuration_lxmert": ["LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LxmertConfig"],
    "tokenization_lxmert": ["LxmertTokenizer"],
}

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_a 						=      ["LxmertTokenizerFast"]

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_a 						=      [
			    "LxmertEncoder",
			    "LxmertForPreTraining",
			    "LxmertForQuestionAnswering",
			    "LxmertModel",
			    "LxmertPreTrainedModel",
			    "LxmertVisualFeatureEncoder",
			    "LxmertXLayer",
			]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_a 						=      [
			    "TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "TFLxmertForPreTraining",
			    "TFLxmertMainLayer",
			    "TFLxmertModel",
			    "TFLxmertPreTrainedModel",
			    "TFLxmertVisualFeatureEncoder",
			]


if TYPE_CHECKING:
			from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
			from .tokenization_lxmert import LxmertTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_lxmert_fast import LxmertTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_lxmert import (
						    LxmertEncoder,
						    LxmertForPreTraining,
						    LxmertForQuestionAnswering,
						    LxmertModel,
						    LxmertPreTrainedModel,
						    LxmertVisualFeatureEncoder,
						    LxmertXLayer,
						)

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_lxmert import (
						    TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFLxmertForPreTraining,
						    TFLxmertMainLayer,
						    TFLxmertModel,
						    TFLxmertPreTrainedModel,
						    TFLxmertVisualFeatureEncoder,
						)

else:
			import sys

			_a 						=      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



