
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


SCREAMING_SNAKE_CASE							:Union[str, Any]							 =				get_tests_dir('fixtures')





class 							UpperCAmelCase      (  unittest.TestCase  ):




	'''simple docstring'''





	def 				UpperCamelCase_  (       self					: List[str] ):
					# A mock response for an HTTP head request to emulate server down
					__A   			= mock.Mock()
					__A   			= 5_00
					__A   			= {}
					__A   			= HTTPError
					__A   			= {}

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







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





@is_staging_test
class 							UpperCAmelCase      (  unittest.TestCase  ):




	'''simple docstring'''





	@classmethod
	def 				UpperCamelCase_  (       cls					: List[str] ):
					__A   			= TOKEN
					HfFolder.save_token(A )






	@classmethod
	def 				UpperCamelCase_  (       cls					: Union[str, 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 				UpperCamelCase_  (       self					: Dict ):
					__A   			= WavaVecaFeatureExtractor.from_pretrained(A )
					feature_extractor.push_to_hub("test-feature-extractor"							,use_auth_token=self._token )

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

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

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






	def 				UpperCamelCase_  (       self					: Optional[Any] ):
					__A   			= WavaVecaFeatureExtractor.from_pretrained(A )
					feature_extractor.push_to_hub("valid_org/test-feature-extractor"							,use_auth_token=self._token )

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

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

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







	def 				UpperCamelCase_  (       self					: Tuple ):
					CustomFeatureExtractor.register_for_auto_class()
					__A   			= CustomFeatureExtractor.from_pretrained(A )

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

					__A   			= AutoFeatureExtractor.from_pretrained(
					    f'''{USER}/test-dynamic-feature-extractor'''							,trust_remote_code=A )
					# 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 ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase							:   Tuple  						=	logging.get_logger(__name__)

lowerCamelCase							:   Dict  						=	{
    'microsoft/cvt-13': 'https://huggingface.co/microsoft/cvt-13/resolve/main/config.json',
    # See all Cvt models at https://huggingface.co/models?filter=cvt
}
class   __lowerCAmelCase						(lowercase_     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Tuple  					=							"""cvt"""



      def __init__(self    :    int   ,						UpperCamelCase    :    List[Any]=3   ,						UpperCamelCase    :    int=[7, 3, 3]   ,						UpperCamelCase    :    str=[4, 2, 2]   ,						UpperCamelCase    :    Dict=[2, 1, 1]   ,						UpperCamelCase    :    Dict=[64, 192, 384]   ,						UpperCamelCase    :    Dict=[1, 3, 6]   ,						UpperCamelCase    :    Dict=[1, 2, 10]   ,						UpperCamelCase    :    Any=[4.0, 4.0, 4.0]   ,						UpperCamelCase    :    Optional[int]=[0.0, 0.0, 0.0]   ,						UpperCamelCase    :    Optional[int]=[0.0, 0.0, 0.0]   ,						UpperCamelCase    :    int=[0.0, 0.0, 0.1]   ,						UpperCamelCase    :    Any=[True, True, True]   ,						UpperCamelCase    :    int=[False, False, True]   ,						UpperCamelCase    :    Union[str, Any]=["dw_bn", "dw_bn", "dw_bn"]   ,						UpperCamelCase    :    Optional[int]=[3, 3, 3]   ,						UpperCamelCase    :    Tuple=[1, 1, 1]   ,						UpperCamelCase    :    Any=[2, 2, 2]   ,						UpperCamelCase    :    Dict=[1, 1, 1]   ,						UpperCamelCase    :    List[str]=[1, 1, 1]   ,						UpperCamelCase    :    str=0.02   ,						UpperCamelCase    :    int=1E-12   ,						**UpperCamelCase    :    Union[str, Any]   ,						):

             '''simple docstring'''







             super().__init__(**UpperCamelCase )
             lowercase__      			= num_channels
             lowercase__      			= patch_sizes
             lowercase__      			= patch_stride
             lowercase__      			= patch_padding
             lowercase__      			= embed_dim
             lowercase__      			= num_heads
             lowercase__      			= depth
             lowercase__      			= mlp_ratio
             lowercase__      			= attention_drop_rate
             lowercase__      			= drop_rate
             lowercase__      			= drop_path_rate
             lowercase__      			= qkv_bias
             lowercase__      			= cls_token
             lowercase__      			= qkv_projection_method
             lowercase__      			= kernel_qkv
             lowercase__      			= padding_kv
             lowercase__      			= stride_kv
             lowercase__      			= padding_q
             lowercase__      			= stride_q
             lowercase__      			= initializer_range
             lowercase__      			= layer_norm_eps




