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


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

_lowercase :  List[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  lowerCAmelCase__   (  lowerCamelCase_     ):
					lowerCAmelCase_        =     '''bloom'''
					lowerCAmelCase_        =     ['''past_key_values''']
					lowerCAmelCase_        =     {
					    '''num_hidden_layers''': '''n_layer''',
					    '''num_attention_heads''': '''n_head''',
					}






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


											"""simple docstring"""





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

											lowercase_	:     Dict													=       bos_token_id
											lowercase_	:     int													=       eos_token_id
											lowercase_	:     Any													=       slow_but_exact

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







class  lowerCAmelCase__   (  lowerCamelCase_     ):
					lowerCAmelCase_        =     version.parse('''1.12'''     )






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


											"""simple docstring"""





											super().__init__(__SCREAMING_SNAKE_CASE				,							task=__SCREAMING_SNAKE_CASE				,							patching_specs=__SCREAMING_SNAKE_CASE				,							use_past=__SCREAMING_SNAKE_CASE		)
											if not getattr(self._config				,							'''pad_token_id'''				,							__SCREAMING_SNAKE_CASE		):
																	# TODO: how to do that better?
																	lowercase_	:     Any													=       0






					@property
					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     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_(__SCREAMING_SNAKE_CASE				,							direction='''inputs'''				,							inverted_values_shape=__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     List[str]													=       {0: '''batch''', 1: '''past_sequence + sequence'''}
											else:
																	lowercase_	:     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				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE = -1				,							__SCREAMING_SNAKE_CASE = -1				,							__SCREAMING_SNAKE_CASE = False				,							__SCREAMING_SNAKE_CASE = None				,							):


											"""simple docstring"""





											lowercase_	:     Optional[int]													=       super(__SCREAMING_SNAKE_CASE				,							self		).generate_dummy_inputs(
											    __SCREAMING_SNAKE_CASE				,							batch_size=__SCREAMING_SNAKE_CASE				,							seq_length=__SCREAMING_SNAKE_CASE				,							is_pair=__SCREAMING_SNAKE_CASE				,							framework=__SCREAMING_SNAKE_CASE		)

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

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

											lowercase_	:     Union[str, Any]													=       common_inputs['''attention_mask''']
											if self.use_past:
																	lowercase_	:     Any													=       ordered_inputs['''attention_mask'''].dtype
																	lowercase_	:     Union[str, Any]													=       torch.cat(
																	    [ordered_inputs['''attention_mask'''], torch.ones(__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE				,							dtype=__SCREAMING_SNAKE_CASE		)]				,							dim=1		)

											return ordered_inputs






					@property
					def 	_snake_case    (   self		):


											"""simple docstring"""





											return 13





'''simple docstring'''







import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format






class  lowerCAmelCase__   :
					lowerCAmelCase_        =     None






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Tuple													=       self.feature_extraction_class(**self.feat_extract_dict		)
											lowercase_	:     Any													=       json.loads(feat_extract.to_json_string()		)
											for key, value in self.feat_extract_dict.items():
																	self.assertEqual(obj[key]				,							__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     str													=       self.feature_extraction_class(**self.feat_extract_dict		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																	lowercase_	:     str													=       os.path.join(__SCREAMING_SNAKE_CASE				,							'''feat_extract.json'''		)
																	feat_extract_first.to_json_file(__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     str													=       self.feature_extraction_class.from_json_file(__SCREAMING_SNAKE_CASE		)

											self.assertEqual(feat_extract_second.to_dict()				,							feat_extract_first.to_dict()		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Tuple													=       self.feature_extraction_class(**self.feat_extract_dict		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																	lowercase_	:     Union[str, Any]													=       feat_extract_first.save_pretrained(__SCREAMING_SNAKE_CASE		)[0]
																	check_json_file_has_correct_format(__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     str													=       self.feature_extraction_class.from_pretrained(__SCREAMING_SNAKE_CASE		)

											self.assertEqual(feat_extract_second.to_dict()				,							feat_extract_first.to_dict()		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       self.feature_extraction_class()
											self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)



