

from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_lowerCAmelCase         =						logging.get_logger(__name__)

_lowerCAmelCase         =						{
    'facebook/deit-base-distilled-patch16-224': (
        'https://huggingface.co/facebook/deit-base-patch16-224/resolve/main/config.json'
    ),
    # See all DeiT models at https://huggingface.co/models?filter=deit
}






class   _SCREAMING_SNAKE_CASE   (   lowerCAmelCase__     ):
 __SCREAMING_SNAKE_CASE					:Optional[int]      	=					"deit"



 def __init__(   self		:   List[Any]			,				a__		:   int=768			,				a__		:   Optional[int]=12			,				a__		:   Dict=12			,				a__		:   Any=3072			,				a__		:   int="gelu"			,				a__		:   Optional[Any]=0.0			,				a__		:   List[str]=0.0			,				a__		:   Optional[Any]=0.02			,				a__		:   str=1E-12			,				a__		:   Any=224			,				a__		:   List[str]=16			,				a__		:   List[str]=3			,				a__		:   Optional[Any]=True			,				a__		:   Any=16			,				**a__		:   Optional[int]			,				):
      super().__init__(**_SCREAMING_SNAKE_CASE      )

      __magic_name__						       =    hidden_size
      __magic_name__						       =    num_hidden_layers
      __magic_name__						       =    num_attention_heads
      __magic_name__						       =    intermediate_size
      __magic_name__						       =    hidden_act
      __magic_name__						       =    hidden_dropout_prob
      __magic_name__						       =    attention_probs_dropout_prob
      __magic_name__						       =    initializer_range
      __magic_name__						       =    layer_norm_eps
      __magic_name__						       =    image_size
      __magic_name__						       =    patch_size
      __magic_name__						       =    num_channels
      __magic_name__						       =    qkv_bias
      __magic_name__						       =    encoder_stride






class   _SCREAMING_SNAKE_CASE   (   lowerCAmelCase__     ):
 __SCREAMING_SNAKE_CASE					:Tuple      	=					version.parse("""1.11"""     )



 @property
 def 			snake_case__  (   self		:   str      ):
      return OrderedDict(
          [
              ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
          ]      )



 @property
 def 			snake_case__  (   self		:   Optional[int]      ):
      return 1E-4









'''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			)			)






