



import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs



class        lowerCAmelCase__					(  _lowerCamelCase       ):


				def __init__(							self      :  Union[str, Any]						, __UpperCamelCase      :  str						, __UpperCamelCase      :  int=None						, __UpperCamelCase      :  int=True						, __UpperCamelCase      :  List[Any]=None						, **__UpperCamelCase      :  Union[str, Any]       )		->     Union[str, Any]:
											A      						=    parent
											A      						=    config_class
											A      						=    has_text_modality
											A      						=    kwargs
											A      						=    common_properties


				def __UpperCamelCase						(							self      :  Optional[int]       )		->     Tuple:
											A      						=    self.config_class(**self.inputs_dict       )
											A      						=    (
											    ['hidden_size', 'num_attention_heads', 'num_hidden_layers']
											    if self.common_properties is None
											    else self.common_properties
											)

											# Add common fields for text models
											if self.has_text_modality:
																		common_properties.extend(['vocab_size']       )

											# Test that config has the common properties as getters
											for prop in common_properties:
																		self.parent.assertTrue(hasattr(__UpperCamelCase						, __UpperCamelCase       )						, msg=f'''`{prop}` does not exist'''       )

											# Test that config has the common properties as setter
											for idx, name in enumerate(__UpperCamelCase       ):
																		try:
																									setattr(__UpperCamelCase						, __UpperCamelCase						, __UpperCamelCase       )
																									self.parent.assertEqual(
																									    getattr(__UpperCamelCase						, __UpperCamelCase       )						, __UpperCamelCase						, msg=f'''`{name} value {idx} expected, but was {getattr(__UpperCamelCase						, __UpperCamelCase       )}'''       )
																		except NotImplementedError:
																									# Some models might not be able to implement setters for common_properties
																									# In that case, a NotImplementedError is raised
																									pass

        # Test if config class can be called with Config(prop_name=..)
											for idx, name in enumerate(__UpperCamelCase       ):
																		try:
																									A      						=    self.config_class(**{name: idx}       )
																									self.parent.assertEqual(
																									    getattr(__UpperCamelCase						, __UpperCamelCase       )						, __UpperCamelCase						, msg=f'''`{name} value {idx} expected, but was {getattr(__UpperCamelCase						, __UpperCamelCase       )}'''       )
																		except NotImplementedError:
																									# Some models might not be able to implement setters for common_properties
																									# In that case, a NotImplementedError is raised
																									pass


				def __UpperCamelCase						(							self      :  List[Any]       )		->     str:
											A      						=    self.config_class(**self.inputs_dict       )
											A      						=    json.loads(config.to_json_string()       )
											for key, value in self.inputs_dict.items():
																		self.parent.assertEqual(obj[key]						, __UpperCamelCase       )


				def __UpperCamelCase						(							self      :  Optional[int]       )		->     Optional[int]:
											A      						=    self.config_class(**self.inputs_dict       )

											with tempfile.TemporaryDirectory() as tmpdirname:
																		A      						=    os.path.join(__UpperCamelCase						, 'config.json'       )
																		config_first.to_json_file(__UpperCamelCase       )
																		A      						=    self.config_class.from_json_file(__UpperCamelCase       )

											self.parent.assertEqual(config_second.to_dict()						, config_first.to_dict()       )


				def __UpperCamelCase						(							self      :  List[Any]       )		->     str:
											A      						=    self.config_class(**self.inputs_dict       )

											with tempfile.TemporaryDirectory() as tmpdirname:
																		config_first.save_pretrained(__UpperCamelCase       )
																		A      						=    self.config_class.from_pretrained(__UpperCamelCase       )

											self.parent.assertEqual(config_second.to_dict()						, config_first.to_dict()       )


				def __UpperCamelCase						(							self      :  Dict       )		->     Optional[Any]:
											A      						=    self.config_class(**self.inputs_dict       )

											A      						=    'test'
											with tempfile.TemporaryDirectory() as tmpdirname:
																		A      						=    os.path.join(__UpperCamelCase						, __UpperCamelCase       )
																		config_first.save_pretrained(__UpperCamelCase       )
																		A      						=    self.config_class.from_pretrained(__UpperCamelCase						, subfolder=__UpperCamelCase       )

											self.parent.assertEqual(config_second.to_dict()						, config_first.to_dict()       )


				def __UpperCamelCase						(							self      :  Optional[Any]       )		->     Tuple:
											A      						=    self.config_class(**self.inputs_dict						, num_labels=5       )
											self.parent.assertEqual(len(config.idalabel       )						, 5       )
											self.parent.assertEqual(len(config.labelaid       )						, 5       )

											A      						=    3
											self.parent.assertEqual(len(config.idalabel       )						, 3       )
											self.parent.assertEqual(len(config.labelaid       )						, 3       )


				def __UpperCamelCase						(							self      :  Dict       )		->     str:
											if self.config_class.is_composition:
																		return
											A      						=    self.config_class()
											self.parent.assertIsNotNone(__UpperCamelCase       )


				def __UpperCamelCase						(							self      :  List[str]       )		->     Dict:
											A      						=    copy.deepcopy(__UpperCamelCase       )
											A      						=    self.config_class(**__UpperCamelCase       )
											A      						=    []
											for key, value in config_common_kwargs.items():
																		if key == "torch_dtype":
																									if not is_torch_available():
																																continue
																									else:
																																import torch

																																if config.torch_dtype != torch.floataa:
																																							wrong_values.append(('torch_dtype', config.torch_dtype, torch.floataa)       )
																		elif getattr(__UpperCamelCase						, __UpperCamelCase       ) != value:
																									wrong_values.append((key, getattr(__UpperCamelCase						, __UpperCamelCase       ), value)       )

											if len(__UpperCamelCase       ) > 0:
																		A      						=    '\n'.join([f'''- {v[0]}: got {v[1]} instead of {v[2]}''' for v in wrong_values]       )
																		raise ValueError(f'''The following keys were not properly set in the config:\n{errors}'''       )


				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Optional[int]:
											self.create_and_test_config_common_properties()
											self.create_and_test_config_to_json_string()
											self.create_and_test_config_to_json_file()
											self.create_and_test_config_from_and_save_pretrained()
											self.create_and_test_config_from_and_save_pretrained_subfolder()
											self.create_and_test_config_with_num_labels()
											self.check_config_can_be_init_without_params()
											self.check_config_arguments_init()



import functools
import operator

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


snake_case							:       Optional[int]										=	logging.get_logger(__name__)

snake_case							:       Optional[Any]										=	{
    '''microsoft/wavlm-base''': '''https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json''',
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}







class 						_snake_case    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			'wavlm'




 def __init__(						self   ,    _lowerCamelCase=32   ,    _lowerCamelCase=768   ,    _lowerCamelCase=12   ,    _lowerCamelCase=12   ,    _lowerCamelCase=3072   ,    _lowerCamelCase="gelu"   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.0   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.02   ,    _lowerCamelCase=1e-5   ,    _lowerCamelCase="group"   ,    _lowerCamelCase="gelu"   ,    _lowerCamelCase=(512, 512, 512, 512, 512, 512, 512)   ,    _lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)   ,    _lowerCamelCase=(10, 3, 3, 3, 3, 2, 2)   ,    _lowerCamelCase=False   ,    _lowerCamelCase=128   ,    _lowerCamelCase=16   ,    _lowerCamelCase=320   ,    _lowerCamelCase=800   ,    _lowerCamelCase=False   ,    _lowerCamelCase=True   ,    _lowerCamelCase=0.05   ,    _lowerCamelCase=10   ,    _lowerCamelCase=2   ,    _lowerCamelCase=0.0   ,    _lowerCamelCase=10   ,    _lowerCamelCase=320   ,    _lowerCamelCase=2   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=100   ,    _lowerCamelCase=256   ,    _lowerCamelCase=256   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase="mean"   ,    _lowerCamelCase=False   ,    _lowerCamelCase=False   ,    _lowerCamelCase=256   ,    _lowerCamelCase=(512, 512, 512, 512, 1500)   ,    _lowerCamelCase=(5, 3, 3, 1, 1)   ,    _lowerCamelCase=(1, 2, 3, 1, 1)   ,    _lowerCamelCase=512   ,    _lowerCamelCase=80   ,    _lowerCamelCase=0   ,    _lowerCamelCase=1   ,    _lowerCamelCase=2   ,    _lowerCamelCase=False   ,    _lowerCamelCase=3   ,    _lowerCamelCase=2   ,    _lowerCamelCase=3   ,    _lowerCamelCase=None   ,    **_lowerCamelCase   ,    ):
       super().__init__(**_lowerCamelCase   ,    pad_token_id=_lowerCamelCase   ,    bos_token_id=_lowerCamelCase   ,    eos_token_id=_lowerCamelCase       )
       a		:Union[str, Any]									=			hidden_size
       a		:List[Any]									=			feat_extract_norm
       a		:Tuple									=			feat_extract_activation
       a		:Tuple									=			list(_lowerCamelCase       )
       a		:Optional[Any]									=			list(_lowerCamelCase       )
       a		:Optional[Any]									=			list(_lowerCamelCase       )
       a		:int									=			conv_bias
       a		:Tuple									=			num_buckets
       a		:Tuple									=			max_bucket_distance
       a		:int									=			num_conv_pos_embeddings
       a		:List[str]									=			num_conv_pos_embedding_groups
       a		:Tuple									=			len(self.conv_dim       )
       a		:Any									=			num_hidden_layers
       a		:Tuple									=			intermediate_size
       a		:Any									=			hidden_act
       a		:List[str]									=			num_attention_heads
       a		:int									=			hidden_dropout
       a		:Optional[Any]									=			attention_dropout
       a		:Dict									=			activation_dropout
       a		:Any									=			feat_proj_dropout
       a		:Dict									=			final_dropout
       a		:int									=			layerdrop
       a		:Tuple									=			layer_norm_eps
       a		:Union[str, Any]									=			initializer_range
       a		:Union[str, Any]									=			num_ctc_classes
       a		:Optional[Any]									=			vocab_size
       a		:str									=			do_stable_layer_norm
       a		:Dict									=			use_weighted_layer_sum
       a		:Any									=			classifier_proj_size

       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
       a		:List[Any]									=			apply_spec_augment
       a		:Optional[int]									=			mask_time_prob
       a		:Optional[Any]									=			mask_time_length
       a		:Tuple									=			mask_time_min_masks
       a		:Dict									=			mask_feature_prob
       a		:List[Any]									=			mask_feature_length

       # parameters for pretraining with codevector quantized representations
       a		:Tuple									=			num_codevectors_per_group
       a		:List[str]									=			num_codevector_groups
       a		:List[Any]									=			contrastive_logits_temperature
       a		:Union[str, Any]									=			num_negatives
       a		:Union[str, Any]									=			codevector_dim
       a		:Dict									=			proj_codevector_dim
       a		:Union[str, Any]									=			diversity_loss_weight

       # ctc loss
       a		:Dict									=			ctc_loss_reduction
       a		:Optional[int]									=			ctc_zero_infinity

       # adapter
       a		:Any									=			add_adapter
       a		:str									=			adapter_kernel_size
       a		:Tuple									=			adapter_stride
       a		:Dict									=			num_adapter_layers
       a		:Any									=			output_hidden_size or hidden_size

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

       # XVector-specific parameters. Feel free to ignore for other classes.
       a		:List[Any]									=			list(_lowerCamelCase       )
       a		:Optional[int]									=			list(_lowerCamelCase       )
       a		:List[str]									=			list(_lowerCamelCase       )
       a		:Optional[int]									=			xvector_output_dim




 @property
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       return functools.reduce(operator.mul   ,    self.conv_stride   ,    1       )





