






"""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 							snake_case (  A__      ,A__		):
			UpperCAmelCase_	:					Dict     	=   tuple((re.compile(x + "$"		) for x in qs)		)
			for i in range(len(A__		) - len(A__		) + 1		):
						UpperCAmelCase_	:					str     	=   [x.match(A__		) for x, y in zip(A__      ,ks[i:]		)]
						if matches and all(A__		):
									return True
			return False

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

			return replace

def 							snake_case (  ):
			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 							snake_case (  A__		):
			UpperCAmelCase_	:					Union[str, Any]     	=   _get_partition_rules()
			UpperCAmelCase_	:					Any     	=   _replacement_rules(A__		)
			UpperCAmelCase_	:					Any     	=   {k: _unmatched for k in flatten_dict(A__		)}
			UpperCAmelCase_	:					Dict     	=   {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_tokenizers_available


snake_case   					=				{'''tokenization_herbert''': ['''HerbertTokenizer''']}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     snake_case   					=				['''HerbertTokenizerFast''']


if TYPE_CHECKING:
     from .tokenization_herbert import HerbertTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_herbert_fast import HerbertTokenizerFast

else:
     import sys

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





