"""simple docstring"""


import sys
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from huggingface_hub import HfFolder, delete_repo
from requests.exceptions import HTTPError

from transformers import AutoFeatureExtractor, WavaVecaFeatureExtractor
from transformers.testing_utils import TOKEN, USER, get_tests_dir, is_staging_test


sys.path.append(str(Path(__file__).parent.parent / """utils"""))

from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


UpperCAmelCase__     						=  get_tests_dir("""fixtures""")


class 				a (						unittest.TestCase      ):


    def    lowerCAmelCase_     (    self		:     Optional[int]    ):
      # A mock response for an HTTP head request to emulate server down
      _UpperCAmelCase         =					mock.Mock()
      _UpperCAmelCase         =					500
      _UpperCAmelCase         =					{}
      _UpperCAmelCase         =					HTTPError
      _UpperCAmelCase         =					{}

      # Download this model to make sure it's in the cache.
      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained("""hf-internal-testing/tiny-random-wav2vec2"""    )
      # Under the mock environment we get a 500 error when trying to reach the model.
      with mock.patch("""requests.Session.request"""      , return_value=__lowerCAmelCase    ) as mock_head:
        _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained("""hf-internal-testing/tiny-random-wav2vec2"""    )
        # This check we did call the fake head request
        mock_head.assert_called()


    def    lowerCAmelCase_     (    self		:     Dict    ):
      # This test is for deprecated behavior and can be removed in v5
      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained(
          """https://huggingface.co/hf-internal-testing/tiny-random-wav2vec2/resolve/main/preprocessor_config.json"""    )



@is_staging_test
class 				a (						unittest.TestCase      ):


    @classmethod
    def    lowerCAmelCase_     (    cls		:     Any    ):
      _UpperCAmelCase         =					TOKEN
      HfFolder.save_token(__lowerCAmelCase    )


    @classmethod
    def    lowerCAmelCase_     (    cls		:     Optional[int]    ):
      try:
        delete_repo(token=cls._token      , repo_id="""test-feature-extractor"""    )
      except HTTPError:
        pass

      try:
        delete_repo(token=cls._token      , repo_id="""valid_org/test-feature-extractor-org"""    )
      except HTTPError:
        pass

      try:
        delete_repo(token=cls._token      , repo_id="""test-dynamic-feature-extractor"""    )
      except HTTPError:
        pass


    def    lowerCAmelCase_     (    self		:     Tuple    ):
      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained(__lowerCAmelCase    )
      feature_extractor.push_to_hub("""test-feature-extractor"""      , use_auth_token=self._token    )

      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained(f'''{USER}/test-feature-extractor'''    )
      for k, v in feature_extractor.__dict__.items():
        self.assertEqual(__lowerCAmelCase      , getattr(__lowerCAmelCase      , __lowerCAmelCase    )    )

      # Reset repo
      delete_repo(token=self._token      , repo_id="""test-feature-extractor"""    )

      # Push to hub via save_pretrained
      with tempfile.TemporaryDirectory() as tmp_dir:
        feature_extractor.save_pretrained(
            __lowerCAmelCase      , repo_id="""test-feature-extractor"""      , push_to_hub=__lowerCAmelCase      , use_auth_token=self._token    )

      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained(f'''{USER}/test-feature-extractor'''    )
      for k, v in feature_extractor.__dict__.items():
        self.assertEqual(__lowerCAmelCase      , getattr(__lowerCAmelCase      , __lowerCAmelCase    )    )


    def    lowerCAmelCase_     (    self		:     Dict    ):
      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained(__lowerCAmelCase    )
      feature_extractor.push_to_hub("""valid_org/test-feature-extractor"""      , use_auth_token=self._token    )

      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained("""valid_org/test-feature-extractor"""    )
      for k, v in feature_extractor.__dict__.items():
        self.assertEqual(__lowerCAmelCase      , getattr(__lowerCAmelCase      , __lowerCAmelCase    )    )

      # Reset repo
      delete_repo(token=self._token      , repo_id="""valid_org/test-feature-extractor"""    )

      # Push to hub via save_pretrained
      with tempfile.TemporaryDirectory() as tmp_dir:
        feature_extractor.save_pretrained(
            __lowerCAmelCase      , repo_id="""valid_org/test-feature-extractor-org"""      , push_to_hub=__lowerCAmelCase      , use_auth_token=self._token    )

      _UpperCAmelCase         =					WavaVecaFeatureExtractor.from_pretrained("""valid_org/test-feature-extractor-org"""    )
      for k, v in feature_extractor.__dict__.items():
        self.assertEqual(__lowerCAmelCase      , getattr(__lowerCAmelCase      , __lowerCAmelCase    )    )


    def    lowerCAmelCase_     (    self		:     List[Any]    ):
      CustomFeatureExtractor.register_for_auto_class()
      _UpperCAmelCase         =					CustomFeatureExtractor.from_pretrained(__lowerCAmelCase    )

      feature_extractor.push_to_hub("""test-dynamic-feature-extractor"""      , use_auth_token=self._token    )

      # This has added the proper auto_map field to the config
      self.assertDictEqual(
          feature_extractor.auto_map      , {"""AutoFeatureExtractor""": """custom_feature_extraction.CustomFeatureExtractor"""}      , )

      _UpperCAmelCase         =					AutoFeatureExtractor.from_pretrained(
          f'''{USER}/test-dynamic-feature-extractor'''      , trust_remote_code=__lowerCAmelCase    )
      # Can't make an isinstance check because the new_feature_extractor is from the CustomFeatureExtractor class of a dynamic module
      self.assertEqual(new_feature_extractor.__class__.__name__      , """CustomFeatureExtractor"""    )

"""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


UpperCAmelCase__     						=  logging.get_logger(__name__)

UpperCAmelCase__     						=  {
    """google/efficientnet-b7""": """https://huggingface.co/google/efficientnet-b7/resolve/main/config.json""",
}


class 				a (						lowerCAmelCase_      ):
    _snake_case   :     Any   							=							'efficientnet'


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

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



class 				a (						lowerCAmelCase_      ):
    _snake_case   :     Dict   							=							version.parse('1.11'      )


    @property
    def    lowerCAmelCase_     (    self		:     Any    ):
      return OrderedDict(
          [
              ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
          ]    )


    @property
    def    lowerCAmelCase_     (    self		:     int    ):
      return 1e-5
