

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 			lowercase    (	lowercase_      ):




				def    a							( self	):
											snake_case_          =   SMALL_MODEL_IDENTIFIER
											snake_case_          =   'pt'
											snake_case_          =   'tf'




				def    a							( self				,       snake_case	):
											snake_case_          =   AutoModel.from_pretrained(self.test_model	)
											model_pt.save_pretrained(snake_case	)




				def    a							( self				,       snake_case	):
											snake_case_          =   TFAutoModel.from_pretrained(self.test_model				,       from_pt=snake_case	)
											model_tf.save_pretrained(snake_case	)




				def    a							( self	):
											snake_case_          =   'mock_framework'

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

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

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




				def    a							( self	):
											# PyTorch checkpoint
											with TemporaryDirectory() as local_pt_ckpt:
																		self._setup_pt_ckpt(snake_case	)
																		snake_case_          =   FeaturesManager.determine_framework(snake_case	)
																		self.assertEqual(snake_case				,       self.framework_pt	)

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

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




				def    a							( self	):
											snake_case_          =   MagicMock(return_value=snake_case	)
											with patch('transformers.onnx.features.is_tf_available'				,       snake_case	):
																		snake_case_          =   FeaturesManager.determine_framework(self.test_model	)
																		self.assertEqual(snake_case				,       self.framework_pt	)

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

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

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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_UpperCAmelCase		:       Tuple						    =	{
    """configuration_xlm_roberta_xl""": [
        """XLM_ROBERTA_XL_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """XLMRobertaXLConfig""",
        """XLMRobertaXLOnnxConfig""",
    ],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCAmelCase		:       int						    =	[
					    """XLM_ROBERTA_XL_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """XLMRobertaXLForCausalLM""",
					    """XLMRobertaXLForMaskedLM""",
					    """XLMRobertaXLForMultipleChoice""",
					    """XLMRobertaXLForQuestionAnswering""",
					    """XLMRobertaXLForSequenceClassification""",
					    """XLMRobertaXLForTokenClassification""",
					    """XLMRobertaXLModel""",
					    """XLMRobertaXLPreTrainedModel""",
					]

if TYPE_CHECKING:
					from .configuration_xlm_roberta_xl import (
					    XLM_ROBERTA_XL_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    XLMRobertaXLConfig,
					    XLMRobertaXLOnnxConfig,
					)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_xlm_roberta_xl import (
										    XLM_ROBERTA_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
										    XLMRobertaXLForCausalLM,
										    XLMRobertaXLForMaskedLM,
										    XLMRobertaXLForMultipleChoice,
										    XLMRobertaXLForQuestionAnswering,
										    XLMRobertaXLForSequenceClassification,
										    XLMRobertaXLForTokenClassification,
										    XLMRobertaXLModel,
										    XLMRobertaXLPreTrainedModel,
										)

else:
					import sys

					_UpperCAmelCase		:       Optional[Any]						    =	_LazyModule(__name__, globals()["""__file__"""], _import_structure)




