





import math

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCamelCase       :     Dict   =     logging.get_logger(__name__)

__lowerCamelCase       :     Optional[int]   =     {
    """facebook/data2vec-base-960h""": """https://huggingface.co/facebook/data2vec-audio-base-960h/resolve/main/config.json""",
    # See all Data2VecAudio models at https://huggingface.co/models?filter=data2vec-audio
}



class 					A__   (       __snake_case			):
      _UpperCAmelCase	:Any						    =   'data2vec-audio'





      def __init__( self       ,							A_=32       ,							A_=768       ,							A_=12       ,							A_=12       ,							A_=3072       ,							A_="gelu"       ,							A_=0.1       ,							A_=0.1       ,							A_=0.1       ,							A_=0.0       ,							A_=0.1       ,							A_=0.1       ,							A_=0.02       ,							A_=1e-5       ,							A_="gelu"       ,							A_=(512, 512, 512, 512, 512, 512, 512)       ,							A_=(5, 2, 2, 2, 2, 2, 2)       ,							A_=(10, 3, 3, 3, 3, 2, 2)       ,							A_=False       ,							A_=16       ,							A_=19       ,							A_=5       ,							A_=0.05       ,							A_=10       ,							A_=2       ,							A_=0.0       ,							A_=10       ,							A_=0       ,							A_="sum"       ,							A_=False       ,							A_=False       ,							A_=256       ,							A_=(512, 512, 512, 512, 1500)       ,							A_=(5, 3, 3, 1, 1)       ,							A_=(1, 2, 3, 1, 1)       ,							A_=512       ,							A_=0       ,							A_=1       ,							A_=2       ,							A_=False       ,							A_=3       ,							A_=2       ,							A_=3       ,							A_=None       ,							**A_       ,							):
       '''simple docstring'''




       super().__init__(**A_       ,							pad_token_id=A_       ,							bos_token_id=A_       ,							eos_token_id=A_   )
       UpperCamelCase	:					str       	=   hidden_size
       UpperCamelCase	:					Optional[Any]       	=   feat_extract_activation
       UpperCamelCase	:					Optional[Any]       	=   list(A_   )
       UpperCamelCase	:					Optional[int]       	=   list(A_   )
       UpperCamelCase	:					Optional[Any]       	=   list(A_   )
       UpperCamelCase	:					Optional[Any]       	=   conv_bias
       UpperCamelCase	:					int       	=   num_conv_pos_embeddings
       UpperCamelCase	:					List[Any]       	=   num_conv_pos_embedding_groups
       UpperCamelCase	:					int       	=   conv_pos_kernel_size
       UpperCamelCase	:					Any       	=   len(self.conv_dim   )
       UpperCamelCase	:					int       	=   num_hidden_layers
       UpperCamelCase	:					int       	=   intermediate_size
       UpperCamelCase	:					int       	=   hidden_act
       UpperCamelCase	:					int       	=   num_attention_heads
       UpperCamelCase	:					Any       	=   hidden_dropout
       UpperCamelCase	:					Dict       	=   attention_dropout
       UpperCamelCase	:					List[str]       	=   activation_dropout
       UpperCamelCase	:					Optional[Any]       	=   feat_proj_dropout
       UpperCamelCase	:					List[str]       	=   final_dropout
       UpperCamelCase	:					Union[str, Any]       	=   layerdrop
       UpperCamelCase	:					Tuple       	=   layer_norm_eps
       UpperCamelCase	:					List[Any]       	=   initializer_range
       UpperCamelCase	:					str       	=   vocab_size
       UpperCamelCase	:					Tuple       	=   use_weighted_layer_sum

       if (
           (len(self.conv_stride   ) != self.num_feat_extract_layers)
           or (len(self.conv_kernel   ) != self.num_feat_extract_layers)
           or (len(self.conv_dim   ) != self.num_feat_extract_layers)
       ):
        raise ValueError(
            "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
            " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
            F""" {len(self.conv_dim   )}`, `len(config.conv_stride) = {len(self.conv_stride   )}`,"""
            F""" `len(config.conv_kernel) = {len(self.conv_kernel   )}`."""   )

       # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
       UpperCamelCase	:					Tuple       	=   mask_time_prob
       UpperCamelCase	:					Dict       	=   mask_time_length
       UpperCamelCase	:					Dict       	=   mask_time_min_masks
       UpperCamelCase	:					int       	=   mask_feature_prob
       UpperCamelCase	:					Tuple       	=   mask_feature_length
       UpperCamelCase	:					Tuple       	=   mask_feature_min_masks

       # ctc loss
       UpperCamelCase	:					Union[str, Any]       	=   ctc_loss_reduction
       UpperCamelCase	:					Tuple       	=   ctc_zero_infinity

       # adapter
       UpperCamelCase	:					Any       	=   add_adapter
       UpperCamelCase	:					List[Any]       	=   adapter_kernel_size
       UpperCamelCase	:					Optional[int]       	=   adapter_stride
       UpperCamelCase	:					int       	=   num_adapter_layers
       UpperCamelCase	:					List[str]       	=   output_hidden_size or hidden_size

       # SequenceClassification-specific parameter. Feel free to ignore for other classes.
       UpperCamelCase	:					Tuple       	=   classifier_proj_size

       # XVector-specific parameters. Feel free to ignore for other classes.
       UpperCamelCase	:					Any       	=   list(A_   )
       UpperCamelCase	:					Tuple       	=   list(A_   )
       UpperCamelCase	:					Optional[int]       	=   list(A_   )
       UpperCamelCase	:					Union[str, Any]       	=   xvector_output_dim





      @property
      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       return math.prod(self.conv_stride   )


import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
		import jax

		from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel




class  lowerCamelCase__							(				unittest.TestCase):




	'''simple docstring'''




	def __init__(					self		:List[str]     ,   a		:Any     ,   a		:List[Any]=1_3     ,   a		:Any=3_0     ,   a		:Dict=2     ,   a		:List[str]=3     ,   a		:Union[str, Any]=True     ,   a		:Optional[int]=True     ,   a		:Tuple=3_2     ,   a		:Any=5     ,   a		:List[str]=4     ,   a		:Optional[Any]=3_7     ,   a		:List[Any]="gelu"     ,   a		:Any=0.1     ,   a		:Any=0.1     ,   a		:List[str]=1_0     ,   a		:str=0.02     ,   )		-> Union[str, Any]:
								__UpperCamelCase	:   int			   =					parent
								__UpperCamelCase	:   List[Any]			   =					batch_size
								__UpperCamelCase	:   Optional[Any]			   =					image_size
								__UpperCamelCase	:   int			   =					patch_size
								__UpperCamelCase	:   Optional[Any]			   =					num_channels
								__UpperCamelCase	:   Optional[int]			   =					is_training
								__UpperCamelCase	:   Union[str, Any]			   =					use_labels
								__UpperCamelCase	:   Tuple			   =					hidden_size
								__UpperCamelCase	:   List[Any]			   =					num_hidden_layers
								__UpperCamelCase	:   List[Any]			   =					num_attention_heads
								__UpperCamelCase	:   Dict			   =					intermediate_size
								__UpperCamelCase	:   Optional[int]			   =					hidden_act
								__UpperCamelCase	:   List[Any]			   =					hidden_dropout_prob
								__UpperCamelCase	:   str			   =					attention_probs_dropout_prob
								__UpperCamelCase	:   List[str]			   =					type_sequence_label_size
								__UpperCamelCase	:   List[str]			   =					initializer_range

								# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
								__UpperCamelCase	:   Union[str, Any]			   =					(image_size // patch_size) ** 2
								__UpperCamelCase	:   Optional[int]			   =					num_patches + 1







	def    _lowerCamelCase				(					self		:Optional[int]						)		-> Union[str, Any]:
								__UpperCamelCase	:   Optional[int]			   =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

								__UpperCamelCase	:   Tuple			   =					ViTConfig(
								    image_size=self.image_size     ,   patch_size=self.patch_size     ,   num_channels=self.num_channels     ,   hidden_size=self.hidden_size     ,   num_hidden_layers=self.num_hidden_layers     ,   num_attention_heads=self.num_attention_heads     ,   intermediate_size=self.intermediate_size     ,   hidden_act=self.hidden_act     ,   hidden_dropout_prob=self.hidden_dropout_prob     ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,   is_decoder=a     ,   initializer_range=self.initializer_range     ,   )

								return config, pixel_values







	def    _lowerCamelCase				(					self		:Tuple     ,   a		:Optional[int]     ,   a		:Optional[int]						)		-> Optional[int]:
								__UpperCamelCase	:   Optional[Any]			   =					FlaxViTModel(config=a						)
								__UpperCamelCase	:   int			   =					model(a						)
								# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
								__UpperCamelCase	:   Any			   =					(self.image_size, self.image_size)
								__UpperCamelCase	:   Optional[int]			   =					(self.patch_size, self.patch_size)
								__UpperCamelCase	:   Optional[int]			   =					(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
								self.parent.assertEqual(result.last_hidden_state.shape     ,   (self.batch_size, num_patches + 1, self.hidden_size)						)







	def    _lowerCamelCase				(					self		:Dict     ,   a		:List[str]     ,   a		:Any						)		-> str:
								__UpperCamelCase	:   Dict			   =					self.type_sequence_label_size
								__UpperCamelCase	:   Dict			   =					FlaxViTForImageClassification(config=a						)
								__UpperCamelCase	:   Tuple			   =					model(a						)
								self.parent.assertEqual(result.logits.shape     ,   (self.batch_size, self.type_sequence_label_size)						)

								# test greyscale images
								__UpperCamelCase	:   Dict			   =					1
								__UpperCamelCase	:   Optional[Any]			   =					FlaxViTForImageClassification(a						)

								__UpperCamelCase	:   List[str]			   =					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
								__UpperCamelCase	:   str			   =					model(a						)







	def    _lowerCamelCase				(					self		:str						)		-> Optional[int]:
								__UpperCamelCase	:   str			   =					self.prepare_config_and_inputs()
								(
								    (
								    __UpperCamelCase
								)   ,						(
								    __UpperCamelCase
								)   ,						
								)	:   List[Any]			   =					config_and_inputs
								__UpperCamelCase	:   str			   =					{"pixel_values": pixel_values}
								return config, inputs_dict




@require_flax
class  lowerCamelCase__							(				__lowercase     ,						unittest.TestCase):




	'''simple docstring'''




	_A								=     (FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()







	def    _lowerCamelCase				(					self		:Optional[int]						)		-> None:
								__UpperCamelCase	:   int			   =					FlaxViTModelTester(self						)
								__UpperCamelCase	:   Any			   =					ConfigTester(self     ,   config_class=a     ,   has_text_modality=a     ,   hidden_size=3_7						)







	def    _lowerCamelCase				(					self		:List[Any]						)		-> str:
								self.config_tester.run_common_tests()







	def    _lowerCamelCase				(					self		:List[Any]						)		-> List[str]:
								__UpperCamelCase	:   int			   =					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*a						)







	def    _lowerCamelCase				(					self		:List[str]						)		-> Union[str, Any]:
								__UpperCamelCase	:   Any			   =					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*a						)







	def    _lowerCamelCase				(					self		:Tuple						)		-> Any:
								__UpperCamelCase   ,						__UpperCamelCase	:   Optional[Any]			   =					self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															__UpperCamelCase	:   List[Any]			   =					model_class(a						)
															__UpperCamelCase	:   Optional[int]			   =					inspect.signature(model.__call__						)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															__UpperCamelCase	:   Dict			   =					[*signature.parameters.keys()]

															__UpperCamelCase	:   Any			   =					["pixel_values"]
															self.assertListEqual(arg_names[:1]     ,   a						)







	def    _lowerCamelCase				(					self		:str						)		-> Any:
								__UpperCamelCase   ,						__UpperCamelCase	:   List[str]			   =					self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															with self.subTest(model_class.__name__						):
																						__UpperCamelCase	:   List[Any]			   =					self._prepare_for_class(a     ,   a						)
																						__UpperCamelCase	:   List[Any]			   =					model_class(a						)

																						@jax.jit
																						def model_jitted(a		:List[str]     ,   **a		:List[Any]						):
																													return model(pixel_values=a     ,   **a						)

																						with self.subTest("JIT Enabled"						):
																													__UpperCamelCase	:   int			   =					model_jitted(**a						).to_tuple()

																						with self.subTest("JIT Disabled"						):
																													with jax.disable_jit():
																																				__UpperCamelCase	:   Optional[Any]			   =					model_jitted(**a						).to_tuple()

																						self.assertEqual(len(a						)     ,   len(a						)						)
																						for jitted_output, output in zip(a     ,   a						):
																													self.assertEqual(jitted_output.shape     ,   output.shape						)







	@slow
	def    _lowerCamelCase				(					self		:Dict						)		-> str:
								for model_class_name in self.all_model_classes:
															__UpperCamelCase	:   List[Any]			   =					model_class_name.from_pretrained("google/vit-base-patch16-224"						)
															__UpperCamelCase	:   Optional[int]			   =					model(np.ones((1, 3, 2_2_4, 2_2_4)						)						)
															self.assertIsNotNone(a						)