





"""simple docstring"""





import functools
import operator

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


__A											=						logging.get_logger(__name__)

__A											=						{
    """facebook/wav2vec2-base-960h""": """https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json""",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:List[Any]						    =   """wav2vec2"""






       def __init__(       self       ,					__UpperCAmelCase=3_2       ,					__UpperCAmelCase=7_6_8       ,					__UpperCAmelCase=1_2       ,					__UpperCAmelCase=1_2       ,					__UpperCAmelCase=3_0_7_2       ,					__UpperCAmelCase="gelu"       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=0.0       ,					__UpperCAmelCase=0.0       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=0.02       ,					__UpperCAmelCase=1E-5       ,					__UpperCAmelCase="group"       ,					__UpperCAmelCase="gelu"       ,					__UpperCAmelCase=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)       ,					__UpperCAmelCase=(5, 2, 2, 2, 2, 2, 2)       ,					__UpperCAmelCase=(1_0, 3, 3, 3, 3, 2, 2)       ,					__UpperCAmelCase=False       ,					__UpperCAmelCase=1_2_8       ,					__UpperCAmelCase=1_6       ,					__UpperCAmelCase=False       ,					__UpperCAmelCase=True       ,					__UpperCAmelCase=0.05       ,					__UpperCAmelCase=1_0       ,					__UpperCAmelCase=2       ,					__UpperCAmelCase=0.0       ,					__UpperCAmelCase=1_0       ,					__UpperCAmelCase=0       ,					__UpperCAmelCase=3_2_0       ,					__UpperCAmelCase=2       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase=1_0_0       ,					__UpperCAmelCase=2_5_6       ,					__UpperCAmelCase=2_5_6       ,					__UpperCAmelCase=0.1       ,					__UpperCAmelCase="sum"       ,					__UpperCAmelCase=False       ,					__UpperCAmelCase=False       ,					__UpperCAmelCase=2_5_6       ,					__UpperCAmelCase=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)       ,					__UpperCAmelCase=(5, 3, 3, 1, 1)       ,					__UpperCAmelCase=(1, 2, 3, 1, 1)       ,					__UpperCAmelCase=5_1_2       ,					__UpperCAmelCase=0       ,					__UpperCAmelCase=1       ,					__UpperCAmelCase=2       ,					__UpperCAmelCase=False       ,					__UpperCAmelCase=3       ,					__UpperCAmelCase=2       ,					__UpperCAmelCase=3       ,					__UpperCAmelCase=None       ,					__UpperCAmelCase=None       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

         super().__init__(**__UpperCAmelCase       ,					pad_token_id=__UpperCAmelCase       ,					bos_token_id=__UpperCAmelCase       ,					eos_token_id=__UpperCAmelCase )
         lowerCAmelCase__     :Optional[Any]											=				hidden_size
         lowerCAmelCase__     :List[str]											=				feat_extract_norm
         lowerCAmelCase__     :Union[str, Any]											=				feat_extract_activation
         lowerCAmelCase__     :List[str]											=				list(__UpperCAmelCase )
         lowerCAmelCase__     :int											=				list(__UpperCAmelCase )
         lowerCAmelCase__     :Dict											=				list(__UpperCAmelCase )
         lowerCAmelCase__     :List[str]											=				conv_bias
         lowerCAmelCase__     :List[Any]											=				num_conv_pos_embeddings
         lowerCAmelCase__     :int											=				num_conv_pos_embedding_groups
         lowerCAmelCase__     :str											=				len(self.conv_dim )
         lowerCAmelCase__     :str											=				num_hidden_layers
         lowerCAmelCase__     :Optional[int]											=				intermediate_size
         lowerCAmelCase__     :List[Any]											=				hidden_act
         lowerCAmelCase__     :int											=				num_attention_heads
         lowerCAmelCase__     :Optional[int]											=				hidden_dropout
         lowerCAmelCase__     :List[str]											=				attention_dropout
         lowerCAmelCase__     :Tuple											=				activation_dropout
         lowerCAmelCase__     :int											=				feat_proj_dropout
         lowerCAmelCase__     :str											=				final_dropout
         lowerCAmelCase__     :Tuple											=				layerdrop
         lowerCAmelCase__     :Tuple											=				layer_norm_eps
         lowerCAmelCase__     :Optional[Any]											=				initializer_range
         lowerCAmelCase__     :List[str]											=				vocab_size
         lowerCAmelCase__     :Any											=				do_stable_layer_norm
         lowerCAmelCase__     :Optional[Any]											=				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
         lowerCAmelCase__     :int											=				apply_spec_augment
         lowerCAmelCase__     :List[str]											=				mask_time_prob
         lowerCAmelCase__     :Dict											=				mask_time_length
         lowerCAmelCase__     :List[Any]											=				mask_time_min_masks
         lowerCAmelCase__     :Tuple											=				mask_feature_prob
         lowerCAmelCase__     :str											=				mask_feature_length
         lowerCAmelCase__     :List[str]											=				mask_feature_min_masks

         # parameters for pretraining with codevector quantized representations
         lowerCAmelCase__     :Optional[Any]											=				num_codevectors_per_group
         lowerCAmelCase__     :Optional[Any]											=				num_codevector_groups
         lowerCAmelCase__     :Optional[int]											=				contrastive_logits_temperature
         lowerCAmelCase__     :List[Any]											=				feat_quantizer_dropout
         lowerCAmelCase__     :Optional[int]											=				num_negatives
         lowerCAmelCase__     :Any											=				codevector_dim
         lowerCAmelCase__     :List[Any]											=				proj_codevector_dim
         lowerCAmelCase__     :str											=				diversity_loss_weight

         # ctc loss
         lowerCAmelCase__     :Tuple											=				ctc_loss_reduction
         lowerCAmelCase__     :Optional[int]											=				ctc_zero_infinity

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

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         lowerCAmelCase__     :Optional[Any]											=				classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         lowerCAmelCase__     :Optional[int]											=				list(__UpperCAmelCase )
         lowerCAmelCase__     :Optional[Any]											=				list(__UpperCAmelCase )
         lowerCAmelCase__     :Optional[Any]											=				list(__UpperCAmelCase )
         lowerCAmelCase__     :Dict											=				xvector_output_dim






       @property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return functools.reduce(operator.mul       ,					self.conv_stride       ,					1 )







"""simple docstring"""





import tempfile
import unittest

from make_student import create_student_by_copying_alternating_layers

from transformers import AutoConfig
from transformers.file_utils import cached_property
from transformers.testing_utils import require_torch


__A											=						"""sshleifer/bart-tiny-random"""
__A											=						"""patrickvonplaten/t5-tiny-random"""






@require_torch
class    _lowerCAmelCase  (	unittest.TestCase			):
       """simple docstring"""




       @cached_property
       def 	snake_case		(       self ):



         '''simple docstring'''

         return AutoConfig.from_pretrained(__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__				,							*lowerCAmelCase__     :List[str]											=				create_student_by_copying_alternating_layers(__UpperCAmelCase       ,					tempfile.mkdtemp()       ,					e=1       ,					d=1 )
         self.assertEqual(student.config.num_hidden_layers       ,					1 )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__				,							*lowerCAmelCase__     :Optional[int]											=				create_student_by_copying_alternating_layers(__UpperCAmelCase       ,					tempfile.mkdtemp()       ,					e=1       ,					d=__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__				,							*lowerCAmelCase__     :List[Any]											=				create_student_by_copying_alternating_layers(__UpperCAmelCase       ,					tempfile.mkdtemp()       ,					e=1       ,					d=__UpperCAmelCase )
         self.assertEqual(student.config.encoder_layers       ,					1 )
         self.assertEqual(student.config.decoder_layers       ,					self.teacher_config.encoder_layers )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__				,							*lowerCAmelCase__     :Optional[int]											=				create_student_by_copying_alternating_layers(__UpperCAmelCase       ,					tempfile.mkdtemp()       ,					e=1       ,					d=1 )
         self.assertEqual(student.config.encoder_layers       ,					1 )
         self.assertEqual(student.config.decoder_layers       ,					1 )






       def 	snake_case		(       self ):



         '''simple docstring'''

         with self.assertRaises(__UpperCAmelCase ):
           create_student_by_copying_alternating_layers(__UpperCAmelCase       ,					tempfile.mkdtemp()       ,					e=__UpperCAmelCase       ,					d=__UpperCAmelCase )
