






"""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 							__SCREAMING_SNAKE_CASE						(				UpperCamelCase		):
							snake_case_     =							'bloom'
							snake_case_     =							['past_key_values']
							snake_case_     =							{
							    'num_hidden_layers': 'n_layer',
							    'num_attention_heads': 'n_head',
							}


							def __init__(			self      :						int			,    snake_case      :						Dict=25_0880			,    snake_case      :						List[Any]=64			,    snake_case      :						Tuple=2			,    snake_case      :						Union[str, Any]=8			,    snake_case      :						Dict=1e-5			,    snake_case      :						List[str]=0.02			,    snake_case      :						str=True			,    snake_case      :						Optional[int]=1			,    snake_case      :						List[str]=2			,    snake_case      :						List[Any]=False			,    snake_case      :						List[Any]=0.0			,    snake_case      :						Union[str, Any]=0.0			,    snake_case      :						str=1			,    snake_case      :						Optional[int]=False			,    **snake_case      :						Any			,    ):
													'''simple docstring'''





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

													A__						:  int		  =  bos_token_id
													A__						:  Union[str, Any]		  =  eos_token_id
													A__						:  List[Any]		  =  slow_but_exact

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






class 							__SCREAMING_SNAKE_CASE						(				UpperCamelCase		):
							snake_case_     =							version.parse('1.12'		)


							def __init__(			self      :						List[str]			,    snake_case      :						PretrainedConfig			,    snake_case      :						str = "default"			,    snake_case      :						List[PatchingSpec] = None			,    snake_case      :						bool = False			,    ):
													'''simple docstring'''





													super().__init__(snake_case			,    task=snake_case			,    patching_specs=snake_case			,    use_past=snake_case							)
													if not getattr(self._config			,    """pad_token_id"""			,    snake_case							):
																			# TODO: how to do that better?
																			A__						:  List[str]		  =  0


							@property
							def 						_UpperCamelCase       (			self      :						Tuple							):
													'''simple docstring'''





													A__						:  List[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_(snake_case			,    direction="""inputs"""			,    inverted_values_shape=snake_case							)
																			A__						:  Optional[Any]		  =  {0: """batch""", 1: """past_sequence + sequence"""}
													else:
																			A__						:  int		  =  {0: """batch""", 1: """sequence"""}

													return common_inputs


							@property
							def 						_UpperCamelCase       (			self      :						Union[str, Any]							):
													'''simple docstring'''





													return self._config.n_layer


							@property
							def 						_UpperCamelCase       (			self      :						List[Any]							):
													'''simple docstring'''





													return self._config.n_head


							@property
							def 						_UpperCamelCase       (			self      :						Optional[int]							):
													'''simple docstring'''





													return 1e-3


							def 						_UpperCamelCase       (			self      :						List[str]			,    snake_case      :						"PreTrainedTokenizer"			,    snake_case      :						int = -1			,    snake_case      :						int = -1			,    snake_case      :						bool = False			,    snake_case      :						Optional["TensorType"] = None			,    ):
													'''simple docstring'''





													A__						:  Optional[Any]		  =  super(snake_case			,    self							).generate_dummy_inputs(
													    snake_case			,    batch_size=snake_case			,    seq_length=snake_case			,    is_pair=snake_case			,    framework=snake_case							)

													# We need to order the input in the way they appears in the forward()
													A__						:  Optional[int]		  =  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

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

													A__						:  Dict		  =  common_inputs["""attention_mask"""]
													if self.use_past:
																			A__						:  List[Any]		  =  ordered_inputs["""attention_mask"""].dtype
																			A__						:  Optional[Any]		  =  torch.cat(
																			    [ordered_inputs["""attention_mask"""], torch.ones(snake_case			,    snake_case			,    dtype=snake_case							)]			,    dim=1							)

													return ordered_inputs


							@property
							def 						_UpperCamelCase       (			self      :						Tuple							):
													'''simple docstring'''





													return 13














"""simple docstring"""



def      _lowerCAmelCase		(							UpperCAmelCase__       :					str,						UpperCAmelCase__       :					List[Any]      )		->List[Any]:
						A__						:  Union[str, Any]		  =  [1]
						for i in range(2,						UpperCAmelCase__      ):
												factorials.append(factorials[-1] * i      )
						assert 0 <= k < factorials[-1] * n, "k out of bounds"

						A__						:  Optional[int]		  =  []
						A__						:  List[str]		  =  list(range(UpperCAmelCase__      )      )

						# Find permutation
						while factorials:
												A__						:  Optional[int]		  =  factorials.pop()
												A__  ,  A__						:  Optional[int]		  =  divmod(UpperCAmelCase__,						UpperCAmelCase__      )
												permutation.append(elements[number]      )
												elements.remove(elements[number]      )
						permutation.append(elements[0]      )

						return permutation


if __name__ == "__main__":
						import doctest

						doctest.testmod()






