

import math

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


_lowerCAmelCase         =						logging.get_logger(__name__)

_lowerCAmelCase         =						{
    "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   _SCREAMING_SNAKE_CASE   (   __a     ):
 __SCREAMING_SNAKE_CASE					:Optional[Any]      	=					"""data2vec-audio"""



 def __init__(   self		:   Optional[int]			,				a__		:   int=32			,				a__		:   str=768			,				a__		:   Any=12			,				a__		:   List[Any]=12			,				a__		:   Optional[Any]=3072			,				a__		:   Optional[Any]="gelu"			,				a__		:   int=0.1			,				a__		:   Optional[Any]=0.1			,				a__		:   Any=0.1			,				a__		:   Any=0.0			,				a__		:   Union[str, Any]=0.1			,				a__		:   Dict=0.1			,				a__		:   List[Any]=0.02			,				a__		:   Dict=1E-5			,				a__		:   Tuple="gelu"			,				a__		:   str=(512, 512, 512, 512, 512, 512, 512)			,				a__		:   List[str]=(5, 2, 2, 2, 2, 2, 2)			,				a__		:   Any=(10, 3, 3, 3, 3, 2, 2)			,				a__		:   Optional[int]=False			,				a__		:   Union[str, Any]=16			,				a__		:   List[str]=19			,				a__		:   Optional[Any]=5			,				a__		:   int=0.05			,				a__		:   List[Any]=10			,				a__		:   Optional[int]=2			,				a__		:   Optional[Any]=0.0			,				a__		:   List[Any]=10			,				a__		:   str=0			,				a__		:   Any="sum"			,				a__		:   List[str]=False			,				a__		:   int=False			,				a__		:   Any=256			,				a__		:   List[str]=(512, 512, 512, 512, 1500)			,				a__		:   Union[str, Any]=(5, 3, 3, 1, 1)			,				a__		:   Union[str, Any]=(1, 2, 3, 1, 1)			,				a__		:   Tuple=512			,				a__		:   Optional[Any]=0			,				a__		:   Optional[int]=1			,				a__		:   Dict=2			,				a__		:   Any=False			,				a__		:   List[Any]=3			,				a__		:   Optional[int]=2			,				a__		:   List[Any]=3			,				a__		:   int=None			,				**a__		:   List[str]			,				):
      super().__init__(**a__			,				pad_token_id=a__			,				bos_token_id=a__			,				eos_token_id=a__      )
      __magic_name__						       =    hidden_size
      __magic_name__						       =    feat_extract_activation
      __magic_name__						       =    list(a__      )
      __magic_name__						       =    list(a__      )
      __magic_name__						       =    list(a__      )
      __magic_name__						       =    conv_bias
      __magic_name__						       =    num_conv_pos_embeddings
      __magic_name__						       =    num_conv_pos_embedding_groups
      __magic_name__						       =    conv_pos_kernel_size
      __magic_name__						       =    len(self.conv_dim      )
      __magic_name__						       =    num_hidden_layers
      __magic_name__						       =    intermediate_size
      __magic_name__						       =    hidden_act
      __magic_name__						       =    num_attention_heads
      __magic_name__						       =    hidden_dropout
      __magic_name__						       =    attention_dropout
      __magic_name__						       =    activation_dropout
      __magic_name__						       =    feat_proj_dropout
      __magic_name__						       =    final_dropout
      __magic_name__						       =    layerdrop
      __magic_name__						       =    layer_norm_eps
      __magic_name__						       =    initializer_range
      __magic_name__						       =    vocab_size
      __magic_name__						       =    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
      __magic_name__						       =    mask_time_prob
      __magic_name__						       =    mask_time_length
      __magic_name__						       =    mask_time_min_masks
      __magic_name__						       =    mask_feature_prob
      __magic_name__						       =    mask_feature_length
      __magic_name__						       =    mask_feature_min_masks

      # ctc loss
      __magic_name__						       =    ctc_loss_reduction
      __magic_name__						       =    ctc_zero_infinity

      # adapter
      __magic_name__						       =    add_adapter
      __magic_name__						       =    adapter_kernel_size
      __magic_name__						       =    adapter_stride
      __magic_name__						       =    num_adapter_layers
      __magic_name__						       =    output_hidden_size or hidden_size

      # SequenceClassification-specific parameter. Feel free to ignore for other classes.
      __magic_name__						       =    classifier_proj_size

      # XVector-specific parameters. Feel free to ignore for other classes.
      __magic_name__						       =    list(a__      )
      __magic_name__						       =    list(a__      )
      __magic_name__						       =    list(a__      )
      __magic_name__						       =    xvector_output_dim



 @property
 def 			snake_case__  (   self		:   Optional[int]      ):
      return math.prod(self.conv_stride      )









'''simple docstring'''




import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
_lowerCAmelCase         =						object()

# For specifying empty leaf dict `{}`
_lowerCAmelCase         =						object()




def 						UpperCamelCase	(			a		,						a			)				->     Union[str, Any]:






     '''simple docstring'''
     __magic_name__						       =    tuple((re.compile(x + '''$'''			) for x in qs)			)
     for i in range(len(a			) - len(a			) + 1			):
          __magic_name__						       =    [x.match(a			) for x, y in zip(a		,						ks[i:]			)]
          if matches and all(a			):
               return True
     return False




def 						UpperCamelCase	(			a			)				->     Tuple:






     '''simple docstring'''
     def replace(a		,						a			):
          for rule, replacement in rules:
               if _match(a		,						a			):
                    return replacement
          return val

     return replace




def 						UpperCamelCase	(			)				->     Union[str, Any]:






     '''simple docstring'''
     return [
         # embeddings
         (("transformer", "wpe", "embedding"), P('''mp'''		,						a			)),
         (("transformer", "wte", "embedding"), P('''mp'''		,						a			)),
         # atention
         (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(a		,						'''mp'''			)),
         (("attention", "out_proj", "kernel"), P('''mp'''		,						a			)),
         (("attention", "out_proj", "bias"), None),
         # mlp
         (("mlp", "c_fc", "kernel"), P(a		,						'''mp'''			)),
         (("mlp", "c_fc", "bias"), P('''mp'''			)),
         (("mlp", "c_proj", "kernel"), P('''mp'''		,						a			)),
         (("mlp", "c_proj", "bias"), None),
         # layer norms
         ((r"ln_\d+", "bias"), None),
         ((r"\d+", r"ln_\d+", "scale"), None),
         (("ln_f", "bias"), None),
         (("ln_f", "scale"), None),
     ]




def 						UpperCamelCase	(			a			)				->     str:






     '''simple docstring'''
     __magic_name__						       =    _get_partition_rules()
     __magic_name__						       =    _replacement_rules(a			)
     __magic_name__						       =    {k: _unmatched for k in flatten_dict(a			)}
     __magic_name__						       =    {k: replace(a		,						a			) for k, v in initd.items()}
     assert _unmatched not in result.values(), "Incomplete partition spec."
     return freeze(unflatten_dict(a			)			)






