





"""simple docstring"""

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


__UpperCAmelCase        =logging.get_logger(__name__)

__UpperCAmelCase        ={
    """google/fnet-base""": """https://huggingface.co/google/fnet-base/resolve/main/config.json""",
    """google/fnet-large""": """https://huggingface.co/google/fnet-large/resolve/main/config.json"""
    # See all FNet models at https://huggingface.co/models?filter=fnet
}


class       lowerCAmelCase__				(   lowercase__  ):
 lowercase__     :  Optional[Any]				=   """fnet"""







 def __init__(   self		,	UpperCamelCase__=3_20_00		,	UpperCamelCase__=7_68		,	UpperCamelCase__=12		,	UpperCamelCase__=30_72		,	UpperCamelCase__="gelu_new"		,	UpperCamelCase__=0.1		,	UpperCamelCase__=5_12		,	UpperCamelCase__=4		,	UpperCamelCase__=0.02		,	UpperCamelCase__=1e-12		,	UpperCamelCase__=False		,	UpperCamelCase__=5_12		,	UpperCamelCase__=3		,	UpperCamelCase__=1		,	UpperCamelCase__=2		,	**UpperCamelCase__		,	):

    '''simple docstring'''


    super().__init__(pad_token_id=UpperCAmelCase__		,	bos_token_id=UpperCAmelCase__		,	eos_token_id=UpperCAmelCase__		,	**UpperCAmelCase__					)

    A__											=					vocab_size
    A__											=					max_position_embeddings
    A__											=					hidden_size
    A__											=					num_hidden_layers
    A__											=					intermediate_size
    A__											=					hidden_act
    A__											=					hidden_dropout_prob
    A__											=					initializer_range
    A__											=					type_vocab_size
    A__											=					layer_norm_eps
    A__											=					use_tpu_fourier_optimizations
    A__											=					tpu_short_seq_length


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

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






def 				_lowerCAmelCase			(   __magic_name__						:     int   , __magic_name__						:     int						)				->  Optional[int]:
						lowercase :							Optional[Any]    		=tuple((re.compile(x + '''$'''						) for x in qs)						)
						for i in range(len(__magic_name__						) - len(__magic_name__						) + 1						):
												lowercase :							Union[str, Any]    		=[x.match(__magic_name__						) for x, y in zip(__magic_name__   , ks[i:]						)]
												if matches and all(__magic_name__						):
																		return True
						return False






def 				_lowerCAmelCase			(   __magic_name__						:     Dict						)				->  List[str]:
						def replace(__magic_name__						:     Optional[int]   , __magic_name__						:     Optional[Any]						):
												for rule, replacement in rules:
																		if _match(__magic_name__   , __magic_name__						):
																								return replacement
												return val

						return replace






def 				_lowerCAmelCase			(   )				->  int:
						return [
						    # embeddings
						    (("transformer", "wpe", "embedding"), P('''mp'''   , __magic_name__						)),
						    (("transformer", "wte", "embedding"), P('''mp'''   , __magic_name__						)),
						    # atention
						    (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(__magic_name__   , '''mp'''						)),
						    (("attention", "out_proj", "kernel"), P('''mp'''   , __magic_name__						)),
						    (("attention", "out_proj", "bias"), None),
						    # mlp
						    (("mlp", "c_fc", "kernel"), P(__magic_name__   , '''mp'''						)),
						    (("mlp", "c_fc", "bias"), P('''mp'''						)),
						    (("mlp", "c_proj", "kernel"), P('''mp'''   , __magic_name__						)),
						    (("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			(   __magic_name__						:     str						)				->  int:
						lowercase :							int    		=_get_partition_rules()
						lowercase :							Tuple    		=_replacement_rules(__magic_name__						)
						lowercase :							Any    		={k: _unmatched for k in flatten_dict(__magic_name__						)}
						lowercase :							Any    		={k: replace(__magic_name__   , __magic_name__						) for k, v in initd.items()}
						assert _unmatched not in result.values(), "Incomplete partition spec."
						return freeze(unflatten_dict(__magic_name__						)						)





