


"""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_			     =  logging.get_logger(__name__)

lowercase_			     =  {
    "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					(   __SCREAMING_SNAKE_CASE       ):


		'''simple docstring'''



		__UpperCAmelCase		:			Dict										=				'bloom'
		__UpperCAmelCase		:			str										=				['past_key_values']
		__UpperCAmelCase		:			Union[str, Any]										=				{
		    'num_hidden_layers': 'n_layer',
		    'num_attention_heads': 'n_head',
		}

		def __init__(  self							, _a=250_880							, _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							, ):
				__a           =			vocab_size
				# Backward compatibility with n_embed kwarg
				__a           =			kwargs.pop('''n_embed'''							, _a      )
				__a           =			hidden_size if n_embed is None else n_embed
				__a           =			n_layer
				__a           =			n_head
				__a           =			layer_norm_epsilon
				__a           =			initializer_range
				__a           =			use_cache
				__a           =			pretraining_tp
				__a           =			apply_residual_connection_post_layernorm
				__a           =			hidden_dropout
				__a           =			attention_dropout

				__a           =			bos_token_id
				__a           =			eos_token_id
				__a           =			slow_but_exact

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







class 					__lowerCAmelCase					(   __SCREAMING_SNAKE_CASE       ):


		'''simple docstring'''



		__UpperCAmelCase		:			Union[str, Any]										=				version.parse('1.12'       )

		def __init__(  self							, _a							, _a = "default"							, _a = None							, _a = False							, ):
				super().__init__(_a							, task=_a							, patching_specs=_a							, use_past=_a      )
				if not getattr(self._config							, '''pad_token_id'''							, _a      ):
						# TODO: how to do that better?
						__a           =			0

		@property
		def 			__UpperCAmelCase       (  self      ):
				__a           =			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_(_a							, direction='''inputs'''							, inverted_values_shape=_a      )
						__a           =			{0: '''batch''', 1: '''past_sequence + sequence'''}
				else:
						__a           =			{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							, _a							, _a = -1							, _a = -1							, _a = False							, _a = None							, ):
				__a           =			super(_a							, self      ).generate_dummy_inputs(
				    _a							, batch_size=_a							, seq_length=_a							, is_pair=_a							, framework=_a      )

				# We need to order the input in the way they appears in the forward()
				__a           =			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           =			common_inputs['''input_ids'''].shape
								# Not using the same length for past_key_values
								__a           =			seqlen + 2
								__a           =			self._config.hidden_size // self.num_attention_heads
								__a           =			(
								    batch * self.num_attention_heads,
								    head_dim,
								    past_key_values_length,
								)
								__a           =			(
								    batch * self.num_attention_heads,
								    past_key_values_length,
								    head_dim,
								)
								__a           =			[
								    (torch.zeros(_a      ), torch.zeros(_a      )) for _ in range(self.num_layers      )
								]

				__a           =			common_inputs['''attention_mask''']
				if self.use_past:
						__a           =			ordered_inputs['''attention_mask'''].dtype
						__a           =			torch.cat(
						    [ordered_inputs['''attention_mask'''], torch.ones(_a							, _a							, dtype=_a      )]							, dim=1      )

				return ordered_inputs





		@property
		def 			__UpperCAmelCase       (  self      ):
				return 13










"""simple docstring"""




from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union

import pyarrow as pa


if TYPE_CHECKING:
				from .features import FeatureType
@dataclass
class 					__lowerCAmelCase					:


		'''simple docstring'''



		__UpperCAmelCase		:			List[str]
		__UpperCAmelCase		:			Optional[str]										=				None
		# Automatically constructed
		__UpperCAmelCase		:			ClassVar[str]										=				"dict"
		__UpperCAmelCase		:			ClassVar[Any]										=				None
		__UpperCAmelCase		:			str										=				field(default='Translation'     ,			init=__SCREAMING_SNAKE_CASE     ,			repr=__SCREAMING_SNAKE_CASE       )

		def __call__(  self      ):
				return pa.struct({lang: pa.string() for lang in sorted(self.languages      )}      )





		def 			__UpperCAmelCase       (  self      ):
				from .features import Value

				return {k: Value('''string'''      ) for k in sorted(self.languages      )}







@dataclass
class 					__lowerCAmelCase					:


		'''simple docstring'''



		__UpperCAmelCase		:			Optional[List]										=				None
		__UpperCAmelCase		:			Optional[int]										=				None
		__UpperCAmelCase		:			Optional[str]										=				None
		# Automatically constructed
		__UpperCAmelCase		:			ClassVar[str]										=				"dict"
		__UpperCAmelCase		:			ClassVar[Any]										=				None
		__UpperCAmelCase		:			str										=				field(default='TranslationVariableLanguages'     ,			init=__SCREAMING_SNAKE_CASE     ,			repr=__SCREAMING_SNAKE_CASE       )

		def 			__UpperCAmelCase       (  self      ):
				__a           =			sorted(set(self.languages      )      ) if self.languages else None
				__a           =			len(self.languages      ) if self.languages else None

		def __call__(  self      ):
				return pa.struct({'''language''': pa.list_(pa.string()      ), '''translation''': pa.list_(pa.string()      )}      )

		def 			__UpperCAmelCase       (  self							, _a      ):
				__a           =			set(self.languages      )
				if self.languages and set(_a      ) - lang_set:
						raise ValueError(
						    f'''Some languages in example ({', '.join(sorted(set(_a      ) - lang_set      )      )}) are not in valid set ({', '.join(_a      )}).'''      )

				# Convert dictionary into tuples, splitting out cases where there are
				# multiple translations for a single language.
				__a           =			[]
				for lang, text in translation_dict.items():
						if isinstance(_a							, _a      ):
								translation_tuples.append((lang, text)      )
						else:
								translation_tuples.extend([(lang, el) for el in text]      )

        # Ensure translations are in ascending order by language code.
				__a      ,     __a           =			zip(*sorted(_a      )      )

				return {"language": languages, "translation": translations}





		def 			__UpperCAmelCase       (  self      ):
				from .features import Sequence, Value

				return {
				    "language": Sequence(Value('''string'''      )      ),
				    "translation": Sequence(Value('''string'''      )      ),
				}






