



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


a_			   =					logging.get_logger(__name__)

a_			   =					{
    '''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    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







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







						def __init__(self   ,		lowercase__=25_08_80   ,		lowercase__=64   ,		lowercase__=2   ,		lowercase__=8   ,		lowercase__=1e-5   ,		lowercase__=0.02   ,		lowercase__=True   ,		lowercase__=1   ,		lowercase__=2   ,		lowercase__=False   ,		lowercase__=0.0   ,		lowercase__=0.0   ,		lowercase__=1   ,		lowercase__=False   ,		**lowercase__   ,		):
											snake_case_					:		Any 					=					vocab_size
											# Backward compatibility with n_embed kwarg
											snake_case_					:		Union[str, Any] 					=					kwargs.pop("""n_embed"""   ,		lowercase__       )
											snake_case_					:		Any 					=					hidden_size if n_embed is None else n_embed
											snake_case_					:		Optional[Any] 					=					n_layer
											snake_case_					:		Any 					=					n_head
											snake_case_					:		Optional[int] 					=					layer_norm_epsilon
											snake_case_					:		Optional[Any] 					=					initializer_range
											snake_case_					:		Any 					=					use_cache
											snake_case_					:		str 					=					pretraining_tp
											snake_case_					:		Dict 					=					apply_residual_connection_post_layernorm
											snake_case_					:		Tuple 					=					hidden_dropout
											snake_case_					:		str 					=					attention_dropout

											snake_case_					:		Union[str, Any] 					=					bos_token_id
											snake_case_					:		Any 					=					eos_token_id
											snake_case_					:		Any 					=					slow_but_exact

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







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Union[str, Any]							       =		version.parse("""1.12""")







						def __init__(self   ,		lowercase__   ,		lowercase__ = "default"   ,		lowercase__ = None   ,		lowercase__ = 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?
																snake_case_					:		Optional[Any] 					=					0







						@property
						def 						__UpperCamelCase							(self       ):
											snake_case_					:		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__       )
																snake_case_					:		Tuple 					=					{0: """batch""", 1: """past_sequence + sequence"""}
											else:
																snake_case_					:		int 					=					{0: """batch""", 1: """sequence"""}

											return common_inputs







						@property
						def 						__UpperCamelCase							(self       ):
											return self._config.n_layer







						@property
						def 						__UpperCamelCase							(self       ):
											return self._config.n_head







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







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__ = -1   ,		lowercase__ = -1   ,		lowercase__ = False   ,		lowercase__ = None   ,		):
											snake_case_					:		Any 					=					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()
											snake_case_					:		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

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

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

											return ordered_inputs







						@property
						def 						__UpperCamelCase							(self       ):
											return 13









"""simple docstring"""

from copy import deepcopy







class    __lowercase     :







						"""simple docstring"""







						def __init__(self   ,		lowercase__ = None   ,		lowercase__ = None       ):

											if arr is None and size is not None:
																snake_case_					:		str 					=					size
																snake_case_					:		Optional[Any] 					=					[0] * size
											elif arr is not None:
																self.init(lowercase__       )
											else:
																raise ValueError("""Either arr or size must be specified"""       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											snake_case_					:		Optional[Any] 					=					len(lowercase__       )
											snake_case_					:		int 					=					deepcopy(lowercase__       )
											for i in range(1   ,		self.size       ):
																snake_case_					:		Optional[Any] 					=					self.next_(lowercase__       )
																if j < self.size:
																					self.tree[j] += self.tree[i]







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Dict 					=					self.tree[:]
											for i in range(self.size - 1   ,		0   ,		-1       ):
																snake_case_					:		Optional[int] 					=					self.next_(lowercase__       )
																if j < self.size:
																					arr[j] -= arr[i]
											return arr







						@staticmethod
						def 						__UpperCamelCase							(lowercase__       ):
											return index + (index & (-index))







						@staticmethod
						def 						__UpperCamelCase							(lowercase__       ):
											return index - (index & (-index))







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											if index == 0:
																self.tree[0] += value
																return
											while index < self.size:
																self.tree[index] += value
																snake_case_					:		Tuple 					=					self.next_(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											self.add(lowercase__   ,		value - self.get(lowercase__       )       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											if right == 0:
																return 0
											snake_case_					:		List[str] 					=					self.tree[0]
											right -= 1  # make right inclusive
											while right > 0:
																result += self.tree[right]
																snake_case_					:		Optional[int] 					=					self.prev(lowercase__       )
											return result







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											return self.prefix(lowercase__       ) - self.prefix(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											return self.query(lowercase__   ,		index + 1       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											value -= self.tree[0]
											if value < 0:
																return -1

											snake_case_					:		Tuple 					=					1  # Largest power of 2 <= size
											while j * 2 < self.size:
																j *= 2

											snake_case_					:		Tuple 					=					0

											while j > 0:
																if i + j < self.size and self.tree[i + j] <= value:
																					value -= self.tree[i + j]
																					i += j
																j //= 2
											return i


if __name__ == "__main__":
			import doctest

			doctest.testmod()




