






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


SCREAMING_SNAKE_CASE__		:							Tuple 				=				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__		:							List[Any] 				=				{
    """MIT/ast-finetuned-audioset-10-10-0.4593""": (
        """https://huggingface.co/MIT/ast-finetuned-audioset-10-10-0.4593/resolve/main/config.json"""
    ),
}







class 				UpperCAmelCase_  (		__lowerCamelCase		):
     __lowerCamelCase      				=  'audio-spectrogram-transformer'




     def __init__(				self	,						_lowerCAmelCase=768	,						_lowerCAmelCase=12	,						_lowerCAmelCase=12	,						_lowerCAmelCase=3072	,						_lowerCAmelCase="gelu"	,						_lowerCAmelCase=0.0	,						_lowerCAmelCase=0.0	,						_lowerCAmelCase=0.0_2	,						_lowerCAmelCase=1e-12	,						_lowerCAmelCase=16	,						_lowerCAmelCase=True	,						_lowerCAmelCase=10	,						_lowerCAmelCase=10	,						_lowerCAmelCase=1024	,						_lowerCAmelCase=128	,						**_lowerCAmelCase	,						):
          super().__init__(**_lowerCAmelCase		)

          UpperCAmelCase__      :  Optional[int]				      =			hidden_size
          UpperCAmelCase__      :  int				      =			num_hidden_layers
          UpperCAmelCase__      :  List[Any]				      =			num_attention_heads
          UpperCAmelCase__      :  Dict				      =			intermediate_size
          UpperCAmelCase__      :  Dict				      =			hidden_act
          UpperCAmelCase__      :  str				      =			hidden_dropout_prob
          UpperCAmelCase__      :  str				      =			attention_probs_dropout_prob
          UpperCAmelCase__      :  Tuple				      =			initializer_range
          UpperCAmelCase__      :  Dict				      =			layer_norm_eps
          UpperCAmelCase__      :  Optional[Any]				      =			patch_size
          UpperCAmelCase__      :  Tuple				      =			qkv_bias
          UpperCAmelCase__      :  Tuple				      =			frequency_stride
          UpperCAmelCase__      :  Union[str, Any]				      =			time_stride
          UpperCAmelCase__      :  Optional[Any]				      =			max_length
          UpperCAmelCase__      :  Optional[int]				      =			num_mel_bins












'''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
UpperCamelCase_		:     Optional[int]          =		object()

# For specifying empty leaf dict `{}`
UpperCamelCase_		:     Optional[int]          =		object()





def       __a      (  _UpperCamelCase:       Union[str, Any]   ,		_UpperCamelCase:       Optional[Any]       )		->					Optional[Any]:

     """simple docstring"""




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





def       __a      (  _UpperCamelCase:       Optional[Any]       )		->					Union[str, Any]:

     """simple docstring"""




     def replace(_UpperCamelCase:       Tuple   ,		_UpperCamelCase:       List[str]       ):
          for rule, replacement in rules:
               if _match(_UpperCamelCase   ,		_UpperCamelCase       ):
                    return replacement
          return val

     return replace





def       __a      (  )		->					Any:

     """simple docstring"""




     return [
         # embeddings
         (("transformer", "wpe", "embedding"), P("mp"   ,		_UpperCamelCase       )),
         (("transformer", "wte", "embedding"), P("mp"   ,		_UpperCamelCase       )),
         # atention
         (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(_UpperCamelCase   ,		"mp"       )),
         (("attention", "out_proj", "kernel"), P("mp"   ,		_UpperCamelCase       )),
         (("attention", "out_proj", "bias"), None),
         # mlp
         (("mlp", "c_fc", "kernel"), P(_UpperCamelCase   ,		"mp"       )),
         (("mlp", "c_fc", "bias"), P("mp"       )),
         (("mlp", "c_proj", "kernel"), P("mp"   ,		_UpperCamelCase       )),
         (("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       __a      (  _UpperCamelCase:       Union[str, Any]       )		->					Any:

     """simple docstring"""




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


