
"""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
_a														=		object()

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



def 				lowerCamelCase__		(      __snake_case,					__snake_case     )							->		Dict:


					"""simple docstring"""





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



def 				lowerCamelCase__		(      __snake_case     )							->		Tuple:


					"""simple docstring"""





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

					return replace



def 				lowerCamelCase__		(      )							->		str:


					"""simple docstring"""





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


					"""simple docstring"""





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








"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


_a														=		{
    """configuration_trocr""": ["""TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TrOCRConfig"""],
    """processing_trocr""": ["""TrOCRProcessor"""],
}


try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_a														=		[
				    """TROCR_PRETRAINED_MODEL_ARCHIVE_LIST""",
				    """TrOCRForCausalLM""",
				    """TrOCRPreTrainedModel""",
				]


if TYPE_CHECKING:
				from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
				from .processing_trocr import TrOCRProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
				import sys

				_a														=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






