






'''simple docstring'''







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


__lowerCAmelCase									=   logging.get_logger(__name__)

__lowerCAmelCase									=   {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/config.json'}





class 						SCREAMING_SNAKE_CASE       (       SCREAMING_SNAKE_CASE_							):
			snake_case__	=					"openai-gpt"
			snake_case__	=					{
			    "max_position_embeddings": "n_positions",
			    "hidden_size": "n_embd",
			    "num_attention_heads": "n_head",
			    "num_hidden_layers": "n_layer",
			}






			def __init__(			self   :      Any	,    __SCREAMING_SNAKE_CASE   :      Tuple=4_0478	,    __SCREAMING_SNAKE_CASE   :      Union[str, Any]=512	,    __SCREAMING_SNAKE_CASE   :      Any=768	,    __SCREAMING_SNAKE_CASE   :      Union[str, Any]=12	,    __SCREAMING_SNAKE_CASE   :      Optional[Any]=12	,    __SCREAMING_SNAKE_CASE   :      Any="gelu"	,    __SCREAMING_SNAKE_CASE   :      List[Any]=0.1	,    __SCREAMING_SNAKE_CASE   :      int=0.1	,    __SCREAMING_SNAKE_CASE   :      Tuple=0.1	,    __SCREAMING_SNAKE_CASE   :      Any=1e-5	,    __SCREAMING_SNAKE_CASE   :      int=0.02	,    __SCREAMING_SNAKE_CASE   :      List[str]="cls_index"	,    __SCREAMING_SNAKE_CASE   :      Optional[Any]=True	,    __SCREAMING_SNAKE_CASE   :      int=None	,    __SCREAMING_SNAKE_CASE   :      List[str]=True	,    __SCREAMING_SNAKE_CASE   :      str=0.1	,    **__SCREAMING_SNAKE_CASE   :      List[str]	,    )      ->      Optional[Any]:
							a_		:	List[str]									=   vocab_size
							a_		:	Optional[Any]									=   n_positions
							a_		:	Tuple									=   n_embd
							a_		:	Any									=   n_layer
							a_		:	int									=   n_head
							a_		:	List[Any]									=   afn
							a_		:	Optional[Any]									=   resid_pdrop
							a_		:	List[Any]									=   embd_pdrop
							a_		:	List[Any]									=   attn_pdrop
							a_		:	Dict									=   layer_norm_epsilon
							a_		:	Any									=   initializer_range
							a_		:	List[str]									=   summary_type
							a_		:	Dict									=   summary_use_proj
							a_		:	List[Any]									=   summary_activation
							a_		:	Optional[Any]									=   summary_first_dropout
							a_		:	Union[str, Any]									=   summary_proj_to_labels
							super().__init__(**__SCREAMING_SNAKE_CASE       )












'''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				: List[str]    ,		__A				: Tuple   ):
				a_		:	List[Any]									=   tuple((re.compile(x + '''$'''   ) for x in qs)   )
				for i in range(len(__A   ) - len(__A   ) + 1   ):
								a_		:	Union[str, Any]									=   [x.match(__A   ) for x, y in zip(__A    ,		ks[i:]   )]
								if matches and all(__A   ):
												return True
				return False





def 		_UpperCAmelCase (				__A				: List[str]   ):
				def replace(__A				: int    ,		__A				: Union[str, Any]   ):
								for rule, replacement in rules:
												if _match(__A    ,		__A   ):
																return replacement
								return val

				return replace





def 		_UpperCAmelCase (				):
				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				: Union[str, Any]   ):
				a_		:	Tuple									=   _get_partition_rules()
				a_		:	Tuple									=   _replacement_rules(__A   )
				a_		:	Optional[Any]									=   {k: _unmatched for k in flatten_dict(__A   )}
				a_		:	Optional[Any]									=   {k: replace(__A    ,		__A   ) for k, v in initd.items()}
				assert _unmatched not in result.values(), "Incomplete partition spec."
				return freeze(unflatten_dict(__A   )   )




