



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 		snake_case    (						A__	):



   '''simple docstring'''






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

    """simple docstring"""







    _snake_case     :	Optional[Any]											=       SMALL_MODEL_IDENTIFIER
    _snake_case     :	Tuple											=       """pt"""
    _snake_case     :	Union[str, Any]											=       """tf"""

   def   UpperCamelCase_	(       self				:      List[str]					,		lowerCAmelCase				:      Optional[int])					->					Dict:

    """simple docstring"""







    _snake_case     :	Dict											=       AutoModel.from_pretrained(self.test_model)
    model_pt.save_pretrained(snake_case_)

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

    """simple docstring"""







    _snake_case     :	Union[str, Any]											=       TFAutoModel.from_pretrained(self.test_model					,		from_pt=snake_case_)
    model_tf.save_pretrained(snake_case_)

   def   UpperCamelCase_	(       self				:      str)					->					Dict:

    """simple docstring"""







    _snake_case     :	Optional[int]											=       """mock_framework"""

    # Framework provided - return whatever the user provides
    _snake_case     :	str											=       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     :	Optional[int]											=       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     :	str											=       FeaturesManager.determine_framework(snake_case_					,		snake_case_)
     self.assertEqual(snake_case_					,		snake_case_)

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

    """simple docstring"""







    with TemporaryDirectory() as local_pt_ckpt:
     self._setup_pt_ckpt(snake_case_)
     _snake_case     :	str											=       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     :	List[Any]											=       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     :	Optional[Any]											=       FeaturesManager.determine_framework(snake_case_)


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

    """simple docstring"""







    _snake_case     :	Tuple											=       MagicMock(return_value=snake_case_)
    with patch("""transformers.onnx.features.is_tf_available"""					,		snake_case_):
     _snake_case     :	Dict											=       FeaturesManager.determine_framework(self.test_model)
     self.assertEqual(snake_case_					,		self.framework_pt)

    # PyTorch not in environment -> use TensorFlow
    _snake_case     :	Optional[int]											=       MagicMock(return_value=snake_case_)
    with patch("""transformers.onnx.features.is_torch_available"""					,		snake_case_):
     _snake_case     :	Union[str, Any]											=       FeaturesManager.determine_framework(self.test_model)
     self.assertEqual(snake_case_					,		self.framework_tf)

    # Both in environment -> use PyTorch
    _snake_case     :	Dict											=       MagicMock(return_value=snake_case_)
    _snake_case     :	Optional[int]											=       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     :	Any											=       FeaturesManager.determine_framework(self.test_model)
     self.assertEqual(snake_case_					,		self.framework_pt)

    # Both not in environment -> raise error
    _snake_case     :	int											=       MagicMock(return_value=snake_case_)
    _snake_case     :	int											=       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     :	Optional[Any]											=       FeaturesManager.determine_framework(self.test_model)


"""simple docstring"""
from collections import OrderedDict
from typing import List, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_					     =	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_					     =	{
    '''google/efficientnet-b7''': '''https://huggingface.co/google/efficientnet-b7/resolve/main/config.json''',
}
class       lowerCAmelCase_		(				A__ ):



							'''simple docstring'''





							_snake_case						      =		'''efficientnet'''




							def __init__( self    ,				snake_case_ = 3    ,				snake_case_ = 600    ,				snake_case_ = 2.0    ,				snake_case_ = 3.1    ,				snake_case_ = 8    ,				snake_case_ = [3, 3, 5, 3, 5, 5, 3]    ,				snake_case_ = [32, 16, 24, 40, 80, 112, 192]    ,				snake_case_ = [16, 24, 40, 80, 112, 192, 320]    ,				snake_case_ = []    ,				snake_case_ = [1, 2, 2, 2, 1, 2, 1]    ,				snake_case_ = [1, 2, 2, 3, 3, 4, 1]    ,				snake_case_ = [1, 6, 6, 6, 6, 6, 6]    ,				snake_case_ = 0.25    ,				snake_case_ = "swish"    ,				snake_case_ = 2_560    ,				snake_case_ = "mean"    ,				snake_case_ = 0.02    ,				snake_case_ = 0.001    ,				snake_case_ = 0.99    ,				snake_case_ = 0.5    ,				snake_case_ = 0.2    ,				**snake_case_    ,				)       ->  List[str]:
													super().__init__(**snake_case_				)

													__lowerCAmelCase     =  num_channels
													__lowerCAmelCase     =  image_size
													__lowerCAmelCase     =  width_coefficient
													__lowerCAmelCase     =  depth_coefficient
													__lowerCAmelCase     =  depth_divisor
													__lowerCAmelCase     =  kernel_sizes
													__lowerCAmelCase     =  in_channels
													__lowerCAmelCase     =  out_channels
													__lowerCAmelCase     =  depthwise_padding
													__lowerCAmelCase     =  strides
													__lowerCAmelCase     =  num_block_repeats
													__lowerCAmelCase     =  expand_ratios
													__lowerCAmelCase     =  squeeze_expansion_ratio
													__lowerCAmelCase     =  hidden_act
													__lowerCAmelCase     =  hidden_dim
													__lowerCAmelCase     =  pooling_type
													__lowerCAmelCase     =  initializer_range
													__lowerCAmelCase     =  batch_norm_eps
													__lowerCAmelCase     =  batch_norm_momentum
													__lowerCAmelCase     =  dropout_rate
													__lowerCAmelCase     =  drop_connect_rate
													__lowerCAmelCase     =  sum(snake_case_				) * 4
class       lowerCAmelCase_		(				A__ ):



							'''simple docstring'''





							_snake_case						      =		version.parse('''1.11''' )




							@property
							def    A__						( self				)       ->  Mapping[str, Mapping[int, str]]:
													return OrderedDict(
													    [
													        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
													    ]				)




							@property
							def    A__						( self				)       ->  float:
													return 1e-5
