from collections import OrderedDict
from typing import Mapping

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


A   :     List[str]       =				logging.get_logger(__name__)

A   :     Dict       =				{
    "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/config.json",
    "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/config.json",
    "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/config.json",
    "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/config.json",
    "bert-base-multilingual-uncased": "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/config.json",
    "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/config.json",
    "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/config.json",
    "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/config.json",
    "bert-large-uncased-whole-word-masking": (
        "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/config.json"
    ),
    "bert-large-cased-whole-word-masking": (
        "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/config.json"
    ),
    "bert-large-uncased-whole-word-masking-finetuned-squad": (
        "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json"
    ),
    "bert-large-cased-whole-word-masking-finetuned-squad": (
        "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/config.json"
    ),
    "bert-base-cased-finetuned-mrpc": "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/config.json",
    "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/config.json",
    "bert-base-german-dbmdz-uncased": "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/config.json",
    "cl-tohoku/bert-base-japanese": "https://huggingface.co/cl-tohoku/bert-base-japanese/resolve/main/config.json",
    "cl-tohoku/bert-base-japanese-whole-word-masking": (
        "https://huggingface.co/cl-tohoku/bert-base-japanese-whole-word-masking/resolve/main/config.json"
    ),
    "cl-tohoku/bert-base-japanese-char": (
        "https://huggingface.co/cl-tohoku/bert-base-japanese-char/resolve/main/config.json"
    ),
    "cl-tohoku/bert-base-japanese-char-whole-word-masking": (
        "https://huggingface.co/cl-tohoku/bert-base-japanese-char-whole-word-masking/resolve/main/config.json"
    ),
    "TurkuNLP/bert-base-finnish-cased-v1": (
        "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/config.json"
    ),
    "TurkuNLP/bert-base-finnish-uncased-v1": (
        "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/config.json"
    ),
    "wietsedv/bert-base-dutch-cased": "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/config.json",
    # See all BERT models at https://huggingface.co/models?filter=bert
}


class      lowerCamelCase    (SCREAMING_SNAKE_CASE__    ):
  """simple docstring"""







  lowerCamelCase__   =  '''bert'''







  def __init__(							self       :				List[str]     ,   __magic_name__       :				Union[str, Any]=30_522     ,   __magic_name__       :				int=768     ,   __magic_name__       :				Optional[int]=12     ,   __magic_name__       :				Dict=12     ,   __magic_name__       :				int=3_072     ,   __magic_name__       :				Optional[int]="gelu"     ,   __magic_name__       :				int=0.1     ,   __magic_name__       :				int=0.1     ,   __magic_name__       :				Dict=512     ,   __magic_name__       :				List[Any]=2     ,   __magic_name__       :				Optional[Any]=0.02     ,   __magic_name__       :				Tuple=1e-12     ,   __magic_name__       :				int=0     ,   __magic_name__       :				Tuple="absolute"     ,   __magic_name__       :				List[str]=True     ,   __magic_name__       :				Union[str, Any]=None     ,   **__magic_name__       :				str     ,   )     ->		Dict:
        super().__init__(pad_token_id=__magic_name__     ,   **__magic_name__      )

        SCREAMING_SNAKE_CASE_      =     vocab_size
        SCREAMING_SNAKE_CASE_      =     hidden_size
        SCREAMING_SNAKE_CASE_      =     num_hidden_layers
        SCREAMING_SNAKE_CASE_      =     num_attention_heads
        SCREAMING_SNAKE_CASE_      =     hidden_act
        SCREAMING_SNAKE_CASE_      =     intermediate_size
        SCREAMING_SNAKE_CASE_      =     hidden_dropout_prob
        SCREAMING_SNAKE_CASE_      =     attention_probs_dropout_prob
        SCREAMING_SNAKE_CASE_      =     max_position_embeddings
        SCREAMING_SNAKE_CASE_      =     type_vocab_size
        SCREAMING_SNAKE_CASE_      =     initializer_range
        SCREAMING_SNAKE_CASE_      =     layer_norm_eps
        SCREAMING_SNAKE_CASE_      =     position_embedding_type
        SCREAMING_SNAKE_CASE_      =     use_cache
        SCREAMING_SNAKE_CASE_      =     classifier_dropout



class      lowerCamelCase    (SCREAMING_SNAKE_CASE__    ):
  """simple docstring"""







  @property
  def       __A   (							self       :				int      )     ->		Mapping[str, Mapping[int, str]]:
        if self.task == "multiple-choice":
              SCREAMING_SNAKE_CASE_      =     {0: "batch", 1: "choice", 2: "sequence"}
        else:
              SCREAMING_SNAKE_CASE_      =     {0: "batch", 1: "sequence"}
        return OrderedDict(
            [
                ("input_ids", dynamic_axis),
                ("attention_mask", dynamic_axis),
                ("token_type_ids", dynamic_axis),
            ]      )



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


A   :     Tuple       =				get_tests_dir("fixtures")


class      lowerCamelCase    (unittest.TestCase    ):
  """simple docstring"""







  def       __A   (							self       :				Union[str, Any]      )     ->		Union[str, Any]:
        # A mock response for an HTTP head request to emulate server down
        SCREAMING_SNAKE_CASE_      =     mock.Mock()
        SCREAMING_SNAKE_CASE_      =     500
        SCREAMING_SNAKE_CASE_      =     {}
        SCREAMING_SNAKE_CASE_      =     HTTPError
        SCREAMING_SNAKE_CASE_      =     {}

        # Download this model to make sure it's in the cache.
        SCREAMING_SNAKE_CASE_      =     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=__magic_name__      ) as mock_head:
              SCREAMING_SNAKE_CASE_      =     WavaVecaFeatureExtractor.from_pretrained("hf-internal-testing/tiny-random-wav2vec2"      )
              # This check we did call the fake head request
              mock_head.assert_called()







  def       __A   (							self       :				Optional[int]      )     ->		Tuple:
        # This test is for deprecated behavior and can be removed in v5
        SCREAMING_SNAKE_CASE_      =     WavaVecaFeatureExtractor.from_pretrained(
            "https://huggingface.co/hf-internal-testing/tiny-random-wav2vec2/resolve/main/preprocessor_config.json"      )



@is_staging_test
class      lowerCamelCase    (unittest.TestCase    ):
  """simple docstring"""







  @classmethod
  def       __A   (							cls       :				Any      )     ->		Union[str, Any]:
        SCREAMING_SNAKE_CASE_      =     TOKEN
        HfFolder.save_token(__magic_name__      )







  @classmethod
  def       __A   (							cls       :				int      )     ->		Optional[Any]:
        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       __A   (							self       :				str      )     ->		List[Any]:
        SCREAMING_SNAKE_CASE_      =     WavaVecaFeatureExtractor.from_pretrained(__magic_name__      )
        feature_extractor.push_to_hub("test-feature-extractor"     ,   use_auth_token=self._token      )

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

        # 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(
                  __magic_name__     ,   repo_id="test-feature-extractor"     ,   push_to_hub=__magic_name__     ,   use_auth_token=self._token      )

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







  def       __A   (							self       :				Dict      )     ->		str:
        SCREAMING_SNAKE_CASE_      =     WavaVecaFeatureExtractor.from_pretrained(__magic_name__      )
        feature_extractor.push_to_hub("valid_org/test-feature-extractor"     ,   use_auth_token=self._token      )

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

        # 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(
                  __magic_name__     ,   repo_id="valid_org/test-feature-extractor-org"     ,   push_to_hub=__magic_name__     ,   use_auth_token=self._token      )

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







  def       __A   (							self       :				List[Any]      )     ->		Dict:
        CustomFeatureExtractor.register_for_auto_class()
        SCREAMING_SNAKE_CASE_      =     CustomFeatureExtractor.from_pretrained(__magic_name__      )

        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"}     ,   )

        SCREAMING_SNAKE_CASE_      =     AutoFeatureExtractor.from_pretrained(
            F'''{USER}/test-dynamic-feature-extractor'''     ,   trust_remote_code=__magic_name__      )
        # 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"      )


