



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


_snake_case		=  logging.get_logger(__name__)

_snake_case		=  {
    "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   UpperCAmelCase_    (       UpperCAmelCase_):
							lowerCamelCase__   			=		"""bloom"""
							lowerCamelCase__   			=		["""past_key_values"""]
							lowerCamelCase__   			=		{
							    """num_hidden_layers""": """n_layer""",
							    """num_attention_heads""": """n_head""",
							}







							def __init__(   self,			__a=25_0880,			__a=64,			__a=2,			__a=8,			__a=1E-5,			__a=0.02,			__a=True,			__a=1,			__a=2,			__a=False,			__a=0.0,			__a=0.0,			__a=1,			__a=False,			**__a,			):

														'''simple docstring'''

														_lowerCAmelCase     :							Tuple    =    vocab_size
														# Backward compatibility with n_embed kwarg
														_lowerCAmelCase     :							Union[str, Any]    =    kwargs.pop("n_embed",			__lowercase)
														_lowerCAmelCase     :							Any    =    hidden_size if n_embed is None else n_embed
														_lowerCAmelCase     :							List[str]    =    n_layer
														_lowerCAmelCase     :							Optional[int]    =    n_head
														_lowerCAmelCase     :							Optional[Any]    =    layer_norm_epsilon
														_lowerCAmelCase     :							Optional[Any]    =    initializer_range
														_lowerCAmelCase     :							str    =    use_cache
														_lowerCAmelCase     :							List[Any]    =    pretraining_tp
														_lowerCAmelCase     :							Tuple    =    apply_residual_connection_post_layernorm
														_lowerCAmelCase     :							int    =    hidden_dropout
														_lowerCAmelCase     :							Optional[int]    =    attention_dropout

														_lowerCAmelCase     :							Dict    =    bos_token_id
														_lowerCAmelCase     :							List[Any]    =    eos_token_id
														_lowerCAmelCase     :							int    =    slow_but_exact

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



class   UpperCAmelCase_    (       UpperCAmelCase_):
							lowerCamelCase__   			=		version.parse('1.12')







							def __init__(   self,			__a,			__a = "default",			__a = None,			__a = False,			):

														'''simple docstring'''

														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    snake_case__      (   self):

														'''simple docstring'''

														_lowerCAmelCase     :							Union[str, Any]    =    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_(__lowercase,			direction="inputs",			inverted_values_shape=__lowercase)
																					_lowerCAmelCase     :							List[str]    =    {0: '''batch''', 1: '''past_sequence + sequence'''}
														else:
																					_lowerCAmelCase     :							Union[str, Any]    =    {0: '''batch''', 1: '''sequence'''}

														return common_inputs







							@property
							def    snake_case__      (   self):

														'''simple docstring'''

														return self._config.n_layer







							@property
							def    snake_case__      (   self):

														'''simple docstring'''

														return self._config.n_head







							@property
							def    snake_case__      (   self):

														'''simple docstring'''

														return 1E-3







							def    snake_case__      (   self,			__a,			__a = -1,			__a = -1,			__a = False,			__a = None,			):

														'''simple docstring'''

														_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     :							Optional[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     :							Tuple    =    common_inputs['''input_ids'''].shape
																												# Not using the same length for past_key_values
																												_lowerCAmelCase     :							List[str]    =    seqlen + 2
																												_lowerCAmelCase     :							Optional[int]    =    self._config.hidden_size // self.num_attention_heads
																												_lowerCAmelCase     :							Union[str, Any]    =    (
																												    batch * self.num_attention_heads,
																												    head_dim,
																												    past_key_values_length,
																												)
																												_lowerCAmelCase     :							Optional[Any]    =    (
																												    batch * self.num_attention_heads,
																												    past_key_values_length,
																												    head_dim,
																												)
																												_lowerCAmelCase     :							Tuple    =    [
																												    (torch.zeros(__lowercase), torch.zeros(__lowercase)) for _ in range(self.num_layers)
																												]

														_lowerCAmelCase     :							str    =    common_inputs['''attention_mask''']
														if self.use_past:
																					_lowerCAmelCase     :							int    =    ordered_inputs['''attention_mask'''].dtype
																					_lowerCAmelCase     :							Any    =    torch.cat(
																					    [ordered_inputs["attention_mask"], torch.ones(__lowercase,			__lowercase,			dtype=__lowercase)],			dim=1)

														return ordered_inputs







							@property
							def    snake_case__      (   self):

														'''simple docstring'''

														return 13

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


__lowercase							 =					logging.get_logger(__name__)

__lowercase							 =					{'''ctrl''': '''https://huggingface.co/ctrl/resolve/main/config.json'''}


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						str						=      """ctrl"""
    a__	:						Dict						=      ["""past_key_values"""]
    a__	:						Tuple						=      {
        """max_position_embeddings""": """n_positions""",
        """hidden_size""": """n_embd""",
        """num_attention_heads""": """n_head""",
        """num_hidden_layers""": """n_layer""",
    }







    def __init__(	self , __lowercase=246_534 , __lowercase=256 , __lowercase=1_280 , __lowercase=8_192 , __lowercase=48 , __lowercase=16 , __lowercase=0.1 , __lowercase=0.1 , __lowercase=1E-6 , __lowercase=0.02 , __lowercase=True , **__lowercase , )       ->	List[Any]:
        __UpperCamelCase     :List[str]			  =		vocab_size
        __UpperCamelCase     :Optional[Any]			  =		n_positions
        __UpperCamelCase     :Dict			  =		n_embd
        __UpperCamelCase     :Dict			  =		n_layer
        __UpperCamelCase     :List[Any]			  =		n_head
        __UpperCamelCase     :int			  =		dff
        __UpperCamelCase     :Union[str, Any]			  =		resid_pdrop
        __UpperCamelCase     :Optional[int]			  =		embd_pdrop
        __UpperCamelCase     :List[Any]			  =		layer_norm_epsilon
        __UpperCamelCase     :Dict			  =		initializer_range

        __UpperCamelCase     :Any			  =		use_cache

        super().__init__(**__lowercase)





