



'''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


UpperCamelCase__       :	Any    = logging.get_logger(__name__)

UpperCamelCase__       :	Any    = {
    '''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    ):


			'''simple docstring'''

			_A      :		str			    =		'bloom'
			_A      :		Any			    =		['past_key_values']
			_A      :		List[str]			    =		{
			    'num_hidden_layers': 'n_layer',
			    'num_attention_heads': 'n_head',
			}

			def __init__(							self     : Optional[Any]							,     lowerCAmelCase__     : List[Any]=2_5_0_8_8_0							,     lowerCAmelCase__     : Dict=6_4							,     lowerCAmelCase__     : List[str]=2							,     lowerCAmelCase__     : int=8							,     lowerCAmelCase__     : Dict=1E-5							,     lowerCAmelCase__     : Tuple=0.02							,     lowerCAmelCase__     : Union[str, Any]=True							,     lowerCAmelCase__     : Dict=1							,     lowerCAmelCase__     : str=2							,     lowerCAmelCase__     : str=False							,     lowerCAmelCase__     : Union[str, Any]=0.0							,     lowerCAmelCase__     : Optional[int]=0.0							,     lowerCAmelCase__     : Tuple=1							,     lowerCAmelCase__     : Optional[int]=False							,     **lowerCAmelCase__     : Dict							,     ):





					"""simple docstring"""






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

					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		bos_token_id
					__SCREAMING_SNAKE_CASE       :		Dict           =		eos_token_id
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		slow_but_exact

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






class 						_UpperCamelCase  (							__UpperCamelCase    ):


			'''simple docstring'''

			_A      :		Tuple			    =		version.parse('''1.12'''    )

			def __init__(							self     : Optional[int]							,     lowerCAmelCase__     : str							,     lowerCAmelCase__     : Tuple = "default"							,     lowerCAmelCase__     : List[Any] = None							,     lowerCAmelCase__     : Union[str, Any] = False							,     ):





					"""simple docstring"""






					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?
							__SCREAMING_SNAKE_CASE       :		int           =		0

			@property
			def UpperCamelCase__					(							self     : List[str]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Tuple           =		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__						)
							__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		{0: 'batch', 1: 'past_sequence + sequence'}
					else:
							__SCREAMING_SNAKE_CASE       :		Tuple           =		{0: 'batch', 1: 'sequence'}

					return common_inputs

			@property
			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					return self._config.n_layer

			@property
			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					return self._config.n_head

			@property
			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					return 1E-3

			def UpperCamelCase__					(							self     : int							,     lowerCAmelCase__     : str							,     lowerCAmelCase__     : Tuple = -1							,     lowerCAmelCase__     : Optional[Any] = -1							,     lowerCAmelCase__     : Tuple = False							,     lowerCAmelCase__     : Optional[int] = None							,     ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		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()
					__SCREAMING_SNAKE_CASE       :		Tuple           =		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

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

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

					return ordered_inputs



			@property
			def UpperCamelCase__					(							self     : Tuple						):





					"""simple docstring"""






					return 1_3



import math




def    snake_case_     (  snake_case			,							snake_case     )  ->				float:
       return math.pow(snake_case			,							2     ) - a




def    snake_case_     (  snake_case     )  ->				float:
       return 2 * x




def    snake_case_     (  snake_case     )  ->				float:
       lowercase__:   Dict  			=   2.0

       while start <= a:
              lowercase__:   str  			=   math.pow(snake_case			,							2     )

       return start




def    snake_case_     (  snake_case			,							snake_case = 99_99			,							snake_case = 0.0_0_0_0_0_0_0_0_0_0_0_0_0_1     )  ->				float:

       if a < 0:
              raise ValueError('math domain error'     )

       lowercase__:   Tuple  			=   get_initial_point(snake_case     )

       for _ in range(snake_case     ):
              lowercase__:   List[Any]  			=   value
              lowercase__:   Any  			=   value - fx(snake_case			,							snake_case     ) / fx_derivative(snake_case     )
              if abs(prev_value - value     ) < tolerance:
                     return value

       return value


if __name__ == "__main__":
 from doctest import testmod

 testmod()


