'''simple docstring'''
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		(						_lowerCamelCase						):







     """simple docstring"""






     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Tuple		    =  SMALL_MODEL_IDENTIFIER
         __UpperCamelCase	:	List[str]		    =  'pt'
         __UpperCamelCase	:	List[str]		    =  'tf'







     def lowerCAmelCase     (		self     ,			_lowerCamelCase    ):
         __UpperCamelCase	:	Union[str, Any]		    =  AutoModel.from_pretrained(self.test_model    )
         model_pt.save_pretrained(_lowerCamelCase    )







     def lowerCAmelCase     (		self     ,			_lowerCamelCase    ):
         __UpperCamelCase	:	Optional[int]		    =  TFAutoModel.from_pretrained(self.test_model     ,			from_pt=_lowerCamelCase    )
         model_tf.save_pretrained(_lowerCamelCase    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	int		    =  'mock_framework'

         # Framework provided - return whatever the user provides
         __UpperCamelCase	:	Tuple		    =  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    )
             __UpperCamelCase	:	int		    =  FeaturesManager.determine_framework(_lowerCamelCase     ,			_lowerCamelCase    )
             self.assertEqual(_lowerCamelCase     ,			_lowerCamelCase    )

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
             self._setup_tf_ckpt(_lowerCamelCase    )
             __UpperCamelCase	:	Tuple		    =  FeaturesManager.determine_framework(_lowerCamelCase     ,			_lowerCamelCase    )
             self.assertEqual(_lowerCamelCase     ,			_lowerCamelCase    )







     def lowerCAmelCase     (		self    ):
         # PyTorch checkpoint
         with TemporaryDirectory() as local_pt_ckpt:
             self._setup_pt_ckpt(_lowerCamelCase    )
             __UpperCamelCase	:	Any		    =  FeaturesManager.determine_framework(_lowerCamelCase    )
             self.assertEqual(_lowerCamelCase     ,			self.framework_pt    )

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
             self._setup_tf_ckpt(_lowerCamelCase    )
             __UpperCamelCase	:	int		    =  FeaturesManager.determine_framework(_lowerCamelCase    )
             self.assertEqual(_lowerCamelCase     ,			self.framework_tf    )

         # Invalid local checkpoint
         with TemporaryDirectory() as local_invalid_ckpt:
             with self.assertRaises(_lowerCamelCase    ):
                 __UpperCamelCase	:	Union[str, Any]		    =  FeaturesManager.determine_framework(_lowerCamelCase    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Any		    =  MagicMock(return_value=_lowerCamelCase    )
         with patch('transformers.onnx.features.is_tf_available'     ,			_lowerCamelCase    ):
             __UpperCamelCase	:	Optional[int]		    =  FeaturesManager.determine_framework(self.test_model    )
             self.assertEqual(_lowerCamelCase     ,			self.framework_pt    )

         # PyTorch not in environment -> use TensorFlow
         __UpperCamelCase	:	List[Any]		    =  MagicMock(return_value=_lowerCamelCase    )
         with patch('transformers.onnx.features.is_torch_available'     ,			_lowerCamelCase    ):
             __UpperCamelCase	:	List[str]		    =  FeaturesManager.determine_framework(self.test_model    )
             self.assertEqual(_lowerCamelCase     ,			self.framework_tf    )

         # Both in environment -> use PyTorch
         __UpperCamelCase	:	Any		    =  MagicMock(return_value=_lowerCamelCase    )
         __UpperCamelCase	:	Dict		    =  MagicMock(return_value=_lowerCamelCase    )
         with patch('transformers.onnx.features.is_tf_available'     ,			_lowerCamelCase    ), patch(
             'transformers.onnx.features.is_torch_available'     ,			_lowerCamelCase    ):
             __UpperCamelCase	:	Union[str, Any]		    =  FeaturesManager.determine_framework(self.test_model    )
             self.assertEqual(_lowerCamelCase     ,			self.framework_pt    )

         # Both not in environment -> raise error
         __UpperCamelCase	:	Tuple		    =  MagicMock(return_value=_lowerCamelCase    )
         __UpperCamelCase	:	str		    =  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    ):
                 __UpperCamelCase	:	Any		    =  FeaturesManager.determine_framework(self.test_model    )




'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a=  {'''configuration_vit_msn''': ['''VIT_MSN_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTMSNConfig''']}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a=  [
      '''VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''ViTMSNModel''',
      '''ViTMSNForImageClassification''',
      '''ViTMSNPreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_vit_msn import VIT_MSN_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTMSNConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_vit_msn import (
        VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST,
        ViTMSNForImageClassification,
        ViTMSNModel,
        ViTMSNPreTrainedModel,
    )

else:
  import sys

  a=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



