'''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
lowercase_     		= object()

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



def 							UpperCamelCase__			(			a__			,      a__      ):


						'''simple docstring'''






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



def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						def replace(a__			,      a__      ):
												for rule, replacement in rules:
																		if _match(a__			,      a__      ):
																								return replacement
												return val

						return replace



def 							UpperCamelCase__			(			):


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


						'''simple docstring'''






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






'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


lowercase_     		= {'''configuration_vit_mae''': ['''VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTMAEConfig''']}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowercase_     		= [
							    '''VIT_MAE_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''ViTMAEForPreTraining''',
							    '''ViTMAELayer''',
							    '''ViTMAEModel''',
							    '''ViTMAEPreTrainedModel''',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowercase_     		= [
							    '''TFViTMAEForPreTraining''',
							    '''TFViTMAEModel''',
							    '''TFViTMAEPreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_vit_mae import VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTMAEConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_vit_mae import (
														    VIT_MAE_PRETRAINED_MODEL_ARCHIVE_LIST,
														    ViTMAEForPreTraining,
														    ViTMAELayer,
														    ViTMAEModel,
														    ViTMAEPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_vit_mae import TFViTMAEForPreTraining, TFViTMAEModel, TFViTMAEPreTrainedModel


else:
							import sys

							lowercase_     		= _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





