"""simple docstring"""






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

from packaging import version


if TYPE_CHECKING:
						from ... import PreTrainedTokenizer, TensorType

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


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

lowerCAmelCase__						:						Tuple		  =			{
    'bigscience/bloom': 'https://huggingface.co/bigscience/bloom/resolve/main/config.json',
    'bigscience/bloom-560m': 'https://huggingface.co/bigscience/bloom-560m/blob/main/config.json',
    'bigscience/bloom-1b1': 'https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json',
    'bigscience/bloom-1b7': 'https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json',
    'bigscience/bloom-3b': 'https://huggingface.co/bigscience/bloom-3b/blob/main/config.json',
    'bigscience/bloom-7b1': 'https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json',
}
class        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				"bloom"
					snake_case__       					=				["past_key_values"]
					snake_case__       					=				{
					    "num_hidden_layers": "n_layer",
					    "num_attention_heads": "n_head",
					}







					def __init__(       self     :			List[Any]					,lowerCamelCase__     :			Optional[Any]=250_880					,lowerCamelCase__     :			int=64					,lowerCamelCase__     :			List[Any]=2					,lowerCamelCase__     :			int=8					,lowerCamelCase__     :			int=1e-5					,lowerCamelCase__     :			Dict=0.0_2					,lowerCamelCase__     :			int=True					,lowerCamelCase__     :			Optional[int]=1					,lowerCamelCase__     :			Tuple=2					,lowerCamelCase__     :			str=False					,lowerCamelCase__     :			Optional[Any]=0.0					,lowerCamelCase__     :			List[Any]=0.0					,lowerCamelCase__     :			Any=1					,lowerCamelCase__     :			Tuple=False					,**lowerCamelCase__     :			str					,):
									UpperCAmelCase__    =							vocab_size
									# Backward compatibility with n_embed kwarg
									UpperCAmelCase__    =							kwargs.pop('n_embed'					,lowerCamelCase__    )
									UpperCAmelCase__    =							hidden_size if n_embed is None else n_embed
									UpperCAmelCase__    =							n_layer
									UpperCAmelCase__    =							n_head
									UpperCAmelCase__    =							layer_norm_epsilon
									UpperCAmelCase__    =							initializer_range
									UpperCAmelCase__    =							use_cache
									UpperCAmelCase__    =							pretraining_tp
									UpperCAmelCase__    =							apply_residual_connection_post_layernorm
									UpperCAmelCase__    =							hidden_dropout
									UpperCAmelCase__    =							attention_dropout

									UpperCAmelCase__    =							bos_token_id
									UpperCAmelCase__    =							eos_token_id
									UpperCAmelCase__    =							slow_but_exact

									super().__init__(bos_token_id=lowerCamelCase__					,eos_token_id=lowerCamelCase__					,**lowerCamelCase__    )






class        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				version.parse("1.12"       )







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







					@property
					def 	__lowerCAmelCase		(       self     :			Tuple    ):
									UpperCAmelCase__    =							OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}    )
									if self.use_past:
													# BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
													self.fill_with_past_key_values_(lowerCamelCase__					,direction='inputs'					,inverted_values_shape=lowerCamelCase__    )
													UpperCAmelCase__    =							{0: 'batch', 1: 'past_sequence + sequence'}
									else:
													UpperCAmelCase__    =							{0: 'batch', 1: 'sequence'}

									return common_inputs







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







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







					@property
					def 	__lowerCAmelCase		(       self     :			Any    ):
									return 1e-3







					def 	__lowerCAmelCase		(       self     :			List[Any]					,lowerCamelCase__     :			"PreTrainedTokenizer"					,lowerCamelCase__     :			int = -1					,lowerCamelCase__     :			int = -1					,lowerCamelCase__     :			bool = False					,lowerCamelCase__     :			Optional["TensorType"] = None					,):
									UpperCAmelCase__    =							super(lowerCamelCase__					,self    ).generate_dummy_inputs(
									    lowerCamelCase__					,batch_size=lowerCamelCase__					,seq_length=lowerCamelCase__					,is_pair=lowerCamelCase__					,framework=lowerCamelCase__    )

									# We need to order the input in the way they appears in the forward()
									UpperCAmelCase__    =							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

																	UpperCAmelCase__   ,			UpperCAmelCase__    =							common_inputs['input_ids'].shape
																	# Not using the same length for past_key_values
																	UpperCAmelCase__    =							seqlen + 2
																	UpperCAmelCase__    =							self._config.hidden_size // self.num_attention_heads
																	UpperCAmelCase__    =							(
																	    batch * self.num_attention_heads,
																	    head_dim,
																	    past_key_values_length,
																	)
																	UpperCAmelCase__    =							(
																	    batch * self.num_attention_heads,
																	    past_key_values_length,
																	    head_dim,
																	)
																	UpperCAmelCase__    =							[
																	    (torch.zeros(lowerCamelCase__    ), torch.zeros(lowerCamelCase__    )) for _ in range(self.num_layers    )
																	]

									UpperCAmelCase__    =							common_inputs['attention_mask']
									if self.use_past:
													UpperCAmelCase__    =							ordered_inputs['attention_mask'].dtype
													UpperCAmelCase__    =							torch.cat(
													    [ordered_inputs['attention_mask'], torch.ones(lowerCamelCase__					,lowerCamelCase__					,dtype=lowerCamelCase__    )]					,dim=1    )

									return ordered_inputs







					@property
					def 	__lowerCAmelCase		(       self     :			str    ):
									return 13




"""simple docstring"""






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


lowerCAmelCase__						:						Any		  =			logging.get_logger(__name__)

lowerCAmelCase__						:						str		  =			{'ctrl': 'https://huggingface.co/ctrl/resolve/main/config.json'}
class        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				"ctrl"
					snake_case__       					=				["past_key_values"]
					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					,lowerCamelCase__     :			str=246_534					,lowerCamelCase__     :			List[str]=256					,lowerCamelCase__     :			Optional[int]=1_280					,lowerCamelCase__     :			Any=8_192					,lowerCamelCase__     :			int=48					,lowerCamelCase__     :			Optional[Any]=16					,lowerCamelCase__     :			Union[str, Any]=0.1					,lowerCamelCase__     :			Dict=0.1					,lowerCamelCase__     :			List[str]=1e-6					,lowerCamelCase__     :			List[str]=0.0_2					,lowerCamelCase__     :			Tuple=True					,**lowerCamelCase__     :			Optional[Any]					,):
									UpperCAmelCase__    =							vocab_size
									UpperCAmelCase__    =							n_positions
									UpperCAmelCase__    =							n_embd
									UpperCAmelCase__    =							n_layer
									UpperCAmelCase__    =							n_head
									UpperCAmelCase__    =							dff
									UpperCAmelCase__    =							resid_pdrop
									UpperCAmelCase__    =							embd_pdrop
									UpperCAmelCase__    =							layer_norm_epsilon
									UpperCAmelCase__    =							initializer_range

									UpperCAmelCase__    =							use_cache

									super().__init__(**lowerCamelCase__    )



