

"""simple docstring"""





from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


__UpperCamelCase  :      List[str]							      =		logging.get_logger(__name__)


__UpperCamelCase  :      Dict							      =		{
    '''Salesforce/codegen-350M-nl''': '''https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json''',
    '''Salesforce/codegen-350M-multi''': '''https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json''',
    '''Salesforce/codegen-350M-mono''': '''https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json''',
    '''Salesforce/codegen-2B-nl''': '''https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json''',
    '''Salesforce/codegen-2B-multi''': '''https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json''',
    '''Salesforce/codegen-2B-mono''': '''https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json''',
    '''Salesforce/codegen-6B-nl''': '''https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json''',
    '''Salesforce/codegen-6B-multi''': '''https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json''',
    '''Salesforce/codegen-6B-mono''': '''https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json''',
    '''Salesforce/codegen-16B-nl''': '''https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json''',
    '''Salesforce/codegen-16B-multi''': '''https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json''',
    '''Salesforce/codegen-16B-mono''': '''https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json''',
}







class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					lowercase__				 =       "codegen"
					lowercase__				 =       {
					    "max_position_embeddings": "n_positions",
					    "hidden_size": "n_embd",
					    "num_attention_heads": "n_head",
					    "num_hidden_layers": "n_layer",
					}







					def __init__(       self			:				Tuple   ,lowercase_			:				Tuple=5_0_4_0_0   ,lowercase_			:				Any=2_0_4_8   ,lowercase_			:				Union[str, Any]=2_0_4_8   ,lowercase_			:				List[str]=4_0_9_6   ,lowercase_			:				Dict=2_8   ,lowercase_			:				List[Any]=1_6   ,lowercase_			:				Tuple=6_4   ,lowercase_			:				str=None   ,lowercase_			:				List[str]="gelu_new"   ,lowercase_			:				int=0.0   ,lowercase_			:				Optional[Any]=0.0   ,lowercase_			:				Union[str, Any]=0.0   ,lowercase_			:				Tuple=1E-5   ,lowercase_			:				Union[str, Any]=0.02   ,lowercase_			:				str=True   ,lowercase_			:				Any=5_0_2_5_6   ,lowercase_			:				List[str]=5_0_2_5_6   ,lowercase_			:				List[str]=False   ,**lowercase_			:				Tuple   ,):
						lowerCAmelCase__	:						str  				=	vocab_size
						lowerCAmelCase__	:						Union[str, Any]  				=	n_ctx
						lowerCAmelCase__	:						Optional[int]  				=	n_positions
						lowerCAmelCase__	:						Dict  				=	n_embd
						lowerCAmelCase__	:						Any  				=	n_layer
						lowerCAmelCase__	:						Union[str, Any]  				=	n_head
						lowerCAmelCase__	:						List[str]  				=	n_inner
						lowerCAmelCase__	:						Optional[Any]  				=	rotary_dim
						lowerCAmelCase__	:						Union[str, Any]  				=	activation_function
						lowerCAmelCase__	:						Optional[int]  				=	resid_pdrop
						lowerCAmelCase__	:						Optional[Any]  				=	embd_pdrop
						lowerCAmelCase__	:						List[str]  				=	attn_pdrop
						lowerCAmelCase__	:						Union[str, Any]  				=	layer_norm_epsilon
						lowerCAmelCase__	:						Optional[int]  				=	initializer_range
						lowerCAmelCase__	:						Tuple  				=	use_cache

						lowerCAmelCase__	:						List[str]  				=	bos_token_id
						lowerCAmelCase__	:						Optional[Any]  				=	eos_token_id

						super().__init__(
						    bos_token_id=lowercase_   ,eos_token_id=lowercase_   ,tie_word_embeddings=lowercase_   ,**lowercase_		)







class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					def __init__(       self			:				Optional[int]   ,lowercase_			:				PretrainedConfig   ,lowercase_			:				str = "default"   ,lowercase_			:				List[PatchingSpec] = None   ,lowercase_			:				bool = False   ,):
						super().__init__(lowercase_   ,task=lowercase_   ,patching_specs=lowercase_   ,use_past=lowercase_		)
						if not getattr(self._config   ,'''pad_token_id'''   ,lowercase_		):
							# TODO: how to do that better?
							lowerCAmelCase__	:						List[Any]  				=	0







					@property
					def        __lowerCAmelCase (       self			:				Tuple		):
						lowerCAmelCase__	:						Union[str, Any]  				=	OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}		)
						if self.use_past:
							self.fill_with_past_key_values_(lowercase_   ,direction='''inputs'''		)
							lowerCAmelCase__	:						Union[str, Any]  				=	{0: '''batch''', 1: '''past_sequence + sequence'''}
						else:
							lowerCAmelCase__	:						List[Any]  				=	{0: '''batch''', 1: '''sequence'''}

						return common_inputs







					@property
					def        __lowerCAmelCase (       self			:				int		):
						return self._config.n_layer







					@property
					def        __lowerCAmelCase (       self			:				List[Any]		):
						return self._config.n_head







					def        __lowerCAmelCase (       self			:				Optional[Any]   ,lowercase_			:				PreTrainedTokenizer   ,lowercase_			:				int = -1   ,lowercase_			:				int = -1   ,lowercase_			:				bool = False   ,lowercase_			:				Optional[TensorType] = None   ,):
						lowerCAmelCase__	:						str  				=	super(lowercase_   ,self		).generate_dummy_inputs(
						    lowercase_   ,batch_size=lowercase_   ,seq_length=lowercase_   ,is_pair=lowercase_   ,framework=lowercase_		)

						# We need to order the input in the way they appears in the forward()
						lowerCAmelCase__	:						Any  				=	OrderedDict({'''input_ids''': common_inputs['''input_ids''']}		)

						# Need to add the past_keys
						if self.use_past:
							if not is_torch_available():
								raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''		)
							else:
								import torch

								lowerCAmelCase__				,lowerCAmelCase__	:						Union[str, Any]  				=	common_inputs['''input_ids'''].shape
								# Not using the same length for past_key_values
								lowerCAmelCase__	:						Optional[Any]  				=	seqlen + 2
								lowerCAmelCase__	:						Union[str, Any]  				=	(
								    batch,
								    self.num_attention_heads,
								    past_key_values_length,
								    self._config.hidden_size // self.num_attention_heads,
								)
								lowerCAmelCase__	:						Dict  				=	[
								    (torch.zeros(lowercase_		), torch.zeros(lowercase_		)) for _ in range(self.num_layers		)
								]

						lowerCAmelCase__	:						Any  				=	common_inputs['''attention_mask''']
						if self.use_past:
							lowerCAmelCase__	:						List[str]  				=	ordered_inputs['''attention_mask'''].dtype
							lowerCAmelCase__	:						Dict  				=	torch.cat(
							    [ordered_inputs['''attention_mask'''], torch.ones(lowercase_   ,lowercase_   ,dtype=lowercase_		)]   ,dim=1		)

						return ordered_inputs







					@property
					def        __lowerCAmelCase (       self			:				Any		):
						return 1_3







'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowerCamelCase :      List[str]					 =     logging.get_logger(__name__)

lowerCamelCase :      List[Any]					 =     {
    "facebook/convnextv2-tiny-1k-224": "https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json",
}







class 							A__    (       A__     ,   A__  ):
  A__		 =				'convnextv2'





  def __init__(		self      :	Tuple							,					_a      :	Optional[int]=3							,					_a      :	Any=4							,					_a      :	int=4							,					_a      :	Union[str, Any]=None							,					_a      :	List[str]=None							,					_a      :	Optional[Any]="gelu"							,					_a      :	Any=0.02							,					_a      :	Any=1e-12							,					_a      :	Tuple=0.0							,					_a      :	int=224							,					_a      :	Any=None							,					_a      :	Optional[int]=None							,					**_a      :	List[str]							,					)	->    Optional[Any]:





       '''simple docstring'''






       super().__init__(**_a )

       _SCREAMING_SNAKE_CASE							    =num_channels
       _SCREAMING_SNAKE_CASE							    =patch_size
       _SCREAMING_SNAKE_CASE							    =num_stages
       _SCREAMING_SNAKE_CASE							    =[96, 192, 384, 768] if hidden_sizes is None else hidden_sizes
       _SCREAMING_SNAKE_CASE							    =[3, 3, 9, 3] if depths is None else depths
       _SCREAMING_SNAKE_CASE							    =hidden_act
       _SCREAMING_SNAKE_CASE							    =initializer_range
       _SCREAMING_SNAKE_CASE							    =layer_norm_eps
       _SCREAMING_SNAKE_CASE							    =drop_path_rate
       _SCREAMING_SNAKE_CASE							    =image_size
       _SCREAMING_SNAKE_CASE							    =['stem'] + [f"stage{idx}" for idx in range(1							,					len(self.depths ) + 1 )]
       _SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE							    =get_aligned_output_features_output_indices(
           out_features=_a							,					out_indices=_a							,					stage_names=self.stage_names )
