from __future__ import annotations

import unittest

import numpy as np

from transformers import OPTConfig, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import GPTaTokenizer, TFOPTForCausalLM, TFOPTModel






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				Any		, _SCREAMING_SNAKE_CASE     :				Tuple		, _SCREAMING_SNAKE_CASE     :				Dict=None		, _SCREAMING_SNAKE_CASE     :				Any=None			):
						if attention_mask is None:
												UpperCamelCase_		:							str  =		tf.cast(tf.math.not_equal(_SCREAMING_SNAKE_CASE		, config.pad_token_id			)		, tf.inta			)
						return {"input_ids": input_ids, "attention_mask": attention_mask}

@require_tf
class        UpperCamelCase						:
						a__		:str      =			OPTConfig
						a__		:Union[str, Any]      =			{}
						a__		:Any      =			'''gelu'''





						def __init__(self			,     __UpperCamelCase			,     __UpperCamelCase=13			,     __UpperCamelCase=7			,     __UpperCamelCase=True			,     __UpperCamelCase=False			,     __UpperCamelCase=99			,     __UpperCamelCase=16			,     __UpperCamelCase=2			,     __UpperCamelCase=4			,     __UpperCamelCase=4			,     __UpperCamelCase="gelu"			,     __UpperCamelCase=0.1			,     __UpperCamelCase=0.1			,     __UpperCamelCase=20			,     __UpperCamelCase=2			,     __UpperCamelCase=1			,     __UpperCamelCase=0			,     __UpperCamelCase=16			,     __UpperCamelCase=16			,     )				->				List[Any]:
												UpperCamelCase_		:							str  =		parent
												UpperCamelCase_		:							List[Any]  =		batch_size
												UpperCamelCase_		:							Optional[Any]  =		seq_length
												UpperCamelCase_		:							Union[str, Any]  =		is_training
												UpperCamelCase_		:							Optional[int]  =		use_labels
												UpperCamelCase_		:							List[Any]  =		vocab_size
												UpperCamelCase_		:							str  =		hidden_size
												UpperCamelCase_		:							Union[str, Any]  =		num_hidden_layers
												UpperCamelCase_		:							Optional[int]  =		num_attention_heads
												UpperCamelCase_		:							Union[str, Any]  =		intermediate_size
												UpperCamelCase_		:							str  =		hidden_act
												UpperCamelCase_		:							Optional[int]  =		hidden_dropout_prob
												UpperCamelCase_		:							Tuple  =		attention_probs_dropout_prob
												UpperCamelCase_		:							Optional[Any]  =		max_position_embeddings
												UpperCamelCase_		:							Optional[Any]  =		eos_token_id
												UpperCamelCase_		:							Dict  =		pad_token_id
												UpperCamelCase_		:							List[str]  =		bos_token_id
												UpperCamelCase_		:							Tuple  =		embed_dim
												UpperCamelCase_		:							List[Any]  =		word_embed_proj_dim
												UpperCamelCase_		:							List[str]  =		False





						def        A_							(self						)				->				Tuple:
												UpperCamelCase_		:							int  =		ids_tensor([self.batch_size, self.seq_length - 1]			,     self.vocab_size						)
												UpperCamelCase_		:							Optional[Any]  =		tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size						)			,     1						)
												UpperCamelCase_		:							Optional[int]  =		tf.concat([input_ids, eos_tensor]			,     axis=1						)

												UpperCamelCase_		:							Optional[Any]  =		self.config_cls(
												    vocab_size=self.vocab_size			,     hidden_size=self.hidden_size			,     num_hidden_layers=self.num_hidden_layers			,     num_attention_heads=self.num_attention_heads			,     ffn_dim=self.intermediate_size			,     dropout=self.hidden_dropout_prob			,     attention_dropout=self.attention_probs_dropout_prob			,     max_position_embeddings=self.max_position_embeddings			,     eos_token_id=self.eos_token_id			,     bos_token_id=self.bos_token_id			,     pad_token_id=self.pad_token_id			,     embed_dim=self.embed_dim			,     word_embed_proj_dim=self.word_embed_proj_dim			,     is_encoder_decoder=__UpperCamelCase			,     **self.config_updates			,     )
												UpperCamelCase_		:							Optional[int]  =		prepare_opt_inputs_dict(__UpperCamelCase			,     __UpperCamelCase						)
												return config, inputs_dict





						def        A_							(self			,     __UpperCamelCase			,     __UpperCamelCase						)				->				int:
												UpperCamelCase_		:							List[Any]  =		TFOPTModel(config=__UpperCamelCase						)
												UpperCamelCase_		:							Any  =		inputs_dict["""input_ids"""]

												UpperCamelCase_		:							Dict  =		input_ids[:1, :]
												UpperCamelCase_		:							Optional[int]  =		inputs_dict["""attention_mask"""][:1, :]
												UpperCamelCase_		:							Any  =		1

												# first forward pass
												UpperCamelCase_		:							Any  =		model(__UpperCamelCase			,     attention_mask=__UpperCamelCase			,     use_cache=__UpperCamelCase						)

												UpperCamelCase_,UpperCamelCase_		:							List[str]  =		outputs.to_tuple()

												# create hypothetical next token and extent to next_input_ids
												UpperCamelCase_		:							Optional[Any]  =		ids_tensor((self.batch_size, 3)			,     config.vocab_size						)
												UpperCamelCase_		:							Union[str, Any]  =		tf.cast(ids_tensor((self.batch_size, 3)			,     2						)			,     tf.inta						)

												# append to next input_ids and
												UpperCamelCase_		:							List[Any]  =		tf.concat([input_ids, next_tokens]			,     axis=-1						)
												UpperCamelCase_		:							List[Any]  =		tf.concat([attention_mask, next_attn_mask]			,     axis=-1						)

												UpperCamelCase_		:							Union[str, Any]  =		model(__UpperCamelCase			,     attention_mask=__UpperCamelCase						)[0]
												UpperCamelCase_		:							Dict  =		model(__UpperCamelCase			,     attention_mask=__UpperCamelCase			,     past_key_values=__UpperCamelCase						)[0]

												self.parent.assertEqual(next_tokens.shape[1]			,     output_from_past.shape[1]						)

												# select random slice
												UpperCamelCase_		:							Optional[int]  =		int(ids_tensor((1,)			,     output_from_past.shape[-1]						)						)
												UpperCamelCase_		:							Any  =		output_from_no_past[:, -3:, random_slice_idx]
												UpperCamelCase_		:							Dict  =		output_from_past[:, :, random_slice_idx]

												# test that outputs are equal for slice
												tf.debugging.assert_near(__UpperCamelCase			,     __UpperCamelCase			,     rtol=1E-3						)


@require_tf
class        UpperCamelCase						(				__a	,	__a	,	unittest.TestCase				):
						a__		:str      =			(TFOPTModel, TFOPTForCausalLM) if is_tf_available() else ()
						a__		:Union[str, Any]      =			(TFOPTForCausalLM,) if is_tf_available() else ()
						a__		:Optional[Any]      =			(
						    {'''feature-extraction''': TFOPTModel, '''text-generation''': TFOPTForCausalLM} if is_tf_available() else {}
						)
						a__		:Dict      =			False
						a__		:Union[str, Any]      =			False
						a__		:Any      =			False
						a__		:int      =			10





						def        A_							(self						)				->				Tuple:
												UpperCamelCase_		:							Dict  =		TFOPTModelTester(self						)
												UpperCamelCase_		:							Tuple  =		ConfigTester(self			,     config_class=__UpperCamelCase						)





						def        A_							(self						)				->				Tuple:
												self.config_tester.run_common_tests()





						def        A_							(self						)				->				Dict:
												UpperCamelCase_		:							Dict  =		self.model_tester.prepare_config_and_inputs_for_common()
												self.model_tester.check_decoder_model_past_large_inputs(*__UpperCamelCase						)





						def        A_							(self						)				->				int:
												UpperCamelCase_,UpperCamelCase_		:							List[str]  =		self.model_tester.prepare_config_and_inputs_for_common()

												def _get_word_embedding_weight(__UpperCamelCase			,     __UpperCamelCase						):
																		if hasattr(__UpperCamelCase			,     """weight"""						):
																								return embedding_layer.weight
																		else:
																								# Here we build the word embeddings weights if not exists.
																								# And then we retry to get the attribute once built.
																								model.build()
																								if hasattr(__UpperCamelCase			,     """weight"""						):
																														return embedding_layer.weight
																								else:
																														return None

												for model_class in self.all_model_classes:
																		for size in [config.vocab_size - 10, config.vocab_size + 10]:
																								# build the embeddings
																								UpperCamelCase_		:							int  =		model_class(config=__UpperCamelCase						)
																								UpperCamelCase_		:							Any  =		_get_word_embedding_weight(__UpperCamelCase			,     model.get_input_embeddings()						)
																								UpperCamelCase_		:							Union[str, Any]  =		_get_word_embedding_weight(__UpperCamelCase			,     model.get_output_embeddings()						)

																								# reshape the embeddings
																								model.resize_token_embeddings(__UpperCamelCase						)
																								UpperCamelCase_		:							Optional[Any]  =		_get_word_embedding_weight(__UpperCamelCase			,     model.get_input_embeddings()						)
																								UpperCamelCase_		:							Optional[Any]  =		_get_word_embedding_weight(__UpperCamelCase			,     model.get_output_embeddings()						)

																								# check that the resized embeddings size matches the desired size.
																								UpperCamelCase_		:							Optional[Any]  =		size if size is not None else config.vocab_size

																								self.assertEqual(new_input_embeddings.shape[0]			,     __UpperCamelCase						)

																								# check that weights remain the same after resizing
																								UpperCamelCase_		:							Optional[int]  =		True
																								for pa, pa in zip(old_input_embeddings.value()			,     new_input_embeddings.value()						):
																														if tf.math.reduce_sum(tf.math.abs(pa - pa						)						) > 0:
																																				UpperCamelCase_		:							str  =		False
																								self.assertTrue(__UpperCamelCase						)

																								if old_output_embeddings is not None and new_output_embeddings is not None:
																														self.assertEqual(new_output_embeddings.shape[0]			,     __UpperCamelCase						)

																														UpperCamelCase_		:							List[Any]  =		True
																														for pa, pa in zip(old_output_embeddings.value()			,     new_output_embeddings.value()						):
																																				if tf.math.reduce_sum(tf.math.abs(pa - pa						)						) > 0:
																																										UpperCamelCase_		:							Optional[Any]  =		False
																														self.assertTrue(__UpperCamelCase						)






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				List[Any]			):
						return tf.constant(_SCREAMING_SNAKE_CASE		, dtype=tf.intaa			)

@require_tf
class        UpperCamelCase						(				unittest.TestCase				):
						a__		:Tuple      =			99





						def        A_							(self						)				->				Optional[Any]:
												UpperCamelCase_		:							Any  =		tf.ones((4, 1)			,     dtype=tf.intaa						) * 2
												UpperCamelCase_		:							int  =		tf.concat([ids_tensor((4, 6)			,     self.vocab_size - 3						) + 3, eos_column_vector]			,     axis=1						)
												UpperCamelCase_		:							List[str]  =		input_ids.shape[0]
												UpperCamelCase_		:							Dict  =		OPTConfig(
												    vocab_size=self.vocab_size			,     hidden_size=24			,     num_hidden_layers=2			,     num_attention_heads=2			,     ffn_dim=32			,     max_position_embeddings=48			,     eos_token_id=2			,     pad_token_id=1			,     bos_token_id=0			,     )
												return config, input_ids, batch_size


@require_sentencepiece
@require_tf
class        UpperCamelCase						(				unittest.TestCase				):





						@slow
						def        A_							(self						)				->				Optional[int]:
												UpperCamelCase_		:							Dict  =		TFOPTModel.from_pretrained("""facebook/opt-350m"""						)
												UpperCamelCase_		:							Union[str, Any]  =		_long_tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]						)
												UpperCamelCase_		:							Optional[Any]  =		tf.not_equal(__UpperCamelCase			,     model.config.pad_token_id						)
												with tf.GradientTape():
																		UpperCamelCase_		:							List[Any]  =		model(input_ids=__UpperCamelCase			,     attention_mask=__UpperCamelCase						).last_hidden_state
												UpperCamelCase_		:							Any  =		(1, 11, 512)
												self.assertEqual(output.shape			,     __UpperCamelCase						)
												UpperCamelCase_		:							int  =		tf.constant(
												    [[-0.2_873, -1.9_218, -0.3_033], [-1.2_710, -0.1_338, -0.1_902], [0.4_095, 0.1_214, -1.3_121]]						)
												self.assertTrue(np.allclose(output[:, :3, :3]			,     __UpperCamelCase			,     atol=4E-3						)						)

												UpperCamelCase_		:							List[Any]  =		tf.function(__UpperCamelCase			,     jit_compile=__UpperCamelCase						)
												UpperCamelCase_		:							List[Any]  =		xla_generate(__UpperCamelCase			,     __UpperCamelCase						)[0]
												self.assertTrue(np.allclose(output[:, :3, :3]			,     __UpperCamelCase			,     atol=4E-2						)						)


@require_tf
@slow
class        UpperCamelCase						(				unittest.TestCase				):





						def        A_							(self						)				->				List[Any]:
												super().setUp()
												UpperCamelCase_		:							int  =		"""facebook/opt-350m"""





						def        A_							(self						)				->				Tuple:
												UpperCamelCase_		:							Optional[Any]  =		TFOPTForCausalLM.from_pretrained(self.path_model						)
												UpperCamelCase_		:							Optional[Any]  =		GPTaTokenizer.from_pretrained(self.path_model						)

												UpperCamelCase_		:							Tuple  =		[
												    """Today is a beautiful day and I want to""",
												    """In the city of""",
												    """Paris is the capital of France and""",
												    """Computers and mobile phones have taken""",
												]
												# verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
												UpperCamelCase_		:							Optional[int]  =		tokenizer(__UpperCamelCase			,     return_tensors="""tf"""			,     padding=__UpperCamelCase			,     add_special_tokens=__UpperCamelCase						)
												UpperCamelCase_		:							str  =		tf.math.reduce_mean(model(inputs.input_ids			,     attention_mask=inputs.attention_mask						)[0]			,     axis=-1						)
												UpperCamelCase_		:							Any  =		tf.constant(
												    [
												        [1.3_851, -13.8_923, -10.5_229, -10.7_533, -0.2_309, -10.2_384, -0.5_365, -9.0_947, -5.1_670],
												        [-4.7_073, -10.6_276, -3.9_415, -21.5_242, -0.2_822, -0.2_822, -0.2_822, -0.2_822, -0.2_822],
												        [0.6_247, -3.4_229, -8.9_179, -1.4_297, -14.1_650, 1.4_146, -9.0_218, -0.2_703, -0.2_703],
												        [6.4_783, -1.9_913, -10.7_926, -2.3_336, 1.5_092, -0.9_974, -6.8_213, 1.3_477, 1.3_477],
												    ]						)
												self.assertTrue(np.allclose(__UpperCamelCase			,     __UpperCamelCase			,     atol=1E-4						)						)

												UpperCamelCase_		:							str  =		tf.function(__UpperCamelCase			,     jit_compile=__UpperCamelCase						)
												UpperCamelCase_		:							List[Any]  =		tf.math.reduce_mean(xla_generate(inputs.input_ids			,     attention_mask=inputs.attention_mask						)[0]			,     axis=-1						)
												self.assertTrue(np.allclose(__UpperCamelCase			,     __UpperCamelCase			,     atol=1E-4						)						)


@require_tf
@slow
class        UpperCamelCase						(				unittest.TestCase				):





						@property
						def        A_							(self						)				->				str:
												return [
												    "Today is a beautiful day and I want",
												    "In the city of",
												    "Paris is the capital of France and",
												    "Computers and mobile phones have taken",
												]





						def        A_							(self						)				->				str:
												UpperCamelCase_		:							Tuple  =		"""facebook/opt-125m"""

												UpperCamelCase_		:							int  =		[
												    """Today is a beautiful day and I want to""",
												    """In the city of New York, the city""",
												    """Paris is the capital of France and the capital""",
												    """Computers and mobile phones have taken over the""",
												]

												UpperCamelCase_		:							Optional[Any]  =		[]
												UpperCamelCase_		:							Any  =		GPTaTokenizer.from_pretrained(__UpperCamelCase						)
												UpperCamelCase_		:							Optional[Any]  =		TFOPTForCausalLM.from_pretrained(__UpperCamelCase						)

												for prompt in self.prompts:
																		UpperCamelCase_		:							List[str]  =		tokenizer(__UpperCamelCase			,     return_tensors="""tf"""						).input_ids

																		UpperCamelCase_		:							Dict  =		model.generate(__UpperCamelCase			,     max_length=10						)

																		UpperCamelCase_		:							Any  =		tokenizer.batch_decode(__UpperCamelCase			,     skip_special_tokens=__UpperCamelCase						)
																		predicted_outputs += generated_string

												self.assertListEqual(__UpperCamelCase			,     __UpperCamelCase						)





						def        A_							(self						)				->				str:
												UpperCamelCase_		:							Optional[int]  =		"""facebook/opt-350m"""

												UpperCamelCase_		:							Tuple  =		GPTaTokenizer.from_pretrained(__UpperCamelCase						)
												UpperCamelCase_		:							Dict  =		TFOPTForCausalLM.from_pretrained(__UpperCamelCase						)

												UpperCamelCase_		:							Any  =		"""left"""

												# use different length sentences to test batching
												UpperCamelCase_		:							List[Any]  =		[
												    """Hello, my dog is a little""",
												    """Today, I""",
												]

												UpperCamelCase_		:							List[str]  =		tokenizer(__UpperCamelCase			,     return_tensors="""tf"""			,     padding=__UpperCamelCase						)
												UpperCamelCase_		:							Tuple  =		inputs["""input_ids"""]

												UpperCamelCase_		:							str  =		model.generate(input_ids=__UpperCamelCase			,     attention_mask=inputs["""attention_mask"""]						)

												UpperCamelCase_		:							int  =		tokenizer(sentences[0]			,     return_tensors="""tf"""						).input_ids
												UpperCamelCase_		:							Dict  =		model.generate(input_ids=__UpperCamelCase						)

												UpperCamelCase_		:							Dict  =		inputs_non_padded.shape[-1] - tf.math.reduce_sum(
												    tf.cast(inputs["""attention_mask"""][-1]			,     tf.intaa						)						)
												UpperCamelCase_		:							Tuple  =		tokenizer(sentences[1]			,     return_tensors="""tf"""						).input_ids
												UpperCamelCase_		:							int  =		model.generate(input_ids=__UpperCamelCase			,     max_length=model.config.max_length - num_paddings						)

												UpperCamelCase_		:							Union[str, Any]  =		tokenizer.batch_decode(__UpperCamelCase			,     skip_special_tokens=__UpperCamelCase						)
												UpperCamelCase_		:							List[str]  =		tokenizer.decode(output_non_padded[0]			,     skip_special_tokens=__UpperCamelCase						)
												UpperCamelCase_		:							Optional[int]  =		tokenizer.decode(output_padded[0]			,     skip_special_tokens=__UpperCamelCase						)

												UpperCamelCase_		:							List[Any]  =		[
												    """Hello, my dog is a little bit of a dork.\nI'm a little bit""",
												    """Today, I was in the middle of a conversation with a friend about the""",
												]
												self.assertListEqual(__UpperCamelCase			,     __UpperCamelCase						)
												self.assertListEqual(__UpperCamelCase			,     [non_padded_sentence, padded_sentence]						)





						def        A_							(self						)				->				str:
												UpperCamelCase_		:							Optional[int]  =		"""facebook/opt-350m"""

												UpperCamelCase_		:							Any  =		[
												    """Today is a beautiful day and I want to""",
												    """In the city of San Francisco, the city""",
												    """Paris is the capital of France and the capital""",
												    """Computers and mobile phones have taken over the""",
												]

												UpperCamelCase_		:							Optional[int]  =		[]
												UpperCamelCase_		:							Optional[int]  =		GPTaTokenizer.from_pretrained(__UpperCamelCase						)
												UpperCamelCase_		:							Optional[int]  =		TFOPTForCausalLM.from_pretrained(__UpperCamelCase						)

												for prompt in self.prompts:
																		UpperCamelCase_		:							Union[str, Any]  =		tokenizer(__UpperCamelCase			,     return_tensors="""tf"""						).input_ids

																		UpperCamelCase_		:							Union[str, Any]  =		model.generate(__UpperCamelCase			,     max_length=10						)

																		UpperCamelCase_		:							Optional[int]  =		tokenizer.batch_decode(__UpperCamelCase			,     skip_special_tokens=__UpperCamelCase						)
																		predicted_outputs += generated_string

												self.assertListEqual(__UpperCamelCase			,     __UpperCamelCase						)







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


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

SCREAMING_SNAKE_CASE		:     str         =	{
    "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						(				__a				):
						a__		:Any      =			'''bloom'''
						a__		:Optional[int]      =			['''past_key_values''']
						a__		:Tuple      =			{
						    '''num_hidden_layers''': '''n_layer''',
						    '''num_attention_heads''': '''n_head''',
						}





						def __init__(self			,     __UpperCamelCase=250_880			,     __UpperCamelCase=64			,     __UpperCamelCase=2			,     __UpperCamelCase=8			,     __UpperCamelCase=1E-5			,     __UpperCamelCase=0.02			,     __UpperCamelCase=True			,     __UpperCamelCase=1			,     __UpperCamelCase=2			,     __UpperCamelCase=False			,     __UpperCamelCase=0.0			,     __UpperCamelCase=0.0			,     __UpperCamelCase=1			,     __UpperCamelCase=False			,     **__UpperCamelCase			,     )				->				List[Any]:
												UpperCamelCase_		:							Dict  =		vocab_size
												# Backward compatibility with n_embed kwarg
												UpperCamelCase_		:							Optional[Any]  =		kwargs.pop("""n_embed"""			,     __UpperCamelCase						)
												UpperCamelCase_		:							List[Any]  =		hidden_size if n_embed is None else n_embed
												UpperCamelCase_		:							List[Any]  =		n_layer
												UpperCamelCase_		:							Optional[Any]  =		n_head
												UpperCamelCase_		:							List[str]  =		layer_norm_epsilon
												UpperCamelCase_		:							int  =		initializer_range
												UpperCamelCase_		:							List[str]  =		use_cache
												UpperCamelCase_		:							List[Any]  =		pretraining_tp
												UpperCamelCase_		:							Optional[int]  =		apply_residual_connection_post_layernorm
												UpperCamelCase_		:							Any  =		hidden_dropout
												UpperCamelCase_		:							Optional[Any]  =		attention_dropout

												UpperCamelCase_		:							List[str]  =		bos_token_id
												UpperCamelCase_		:							Optional[Any]  =		eos_token_id
												UpperCamelCase_		:							str  =		slow_but_exact

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


class        UpperCamelCase						(				__a				):
						a__		:Dict      =			version.parse('''1.12'''				)





						def __init__(self			,     __UpperCamelCase			,     __UpperCamelCase = "default"			,     __UpperCamelCase = None			,     __UpperCamelCase = False			,     )				->				List[str]:
												super().__init__(__UpperCamelCase			,     task=__UpperCamelCase			,     patching_specs=__UpperCamelCase			,     use_past=__UpperCamelCase						)
												if not getattr(self._config			,     """pad_token_id"""			,     __UpperCamelCase						):
																		# TODO: how to do that better?
																		UpperCamelCase_		:							Optional[Any]  =		0





						@property
						def        A_							(self						)				->				Mapping[str, Mapping[int, str]]:
												UpperCamelCase_		:							str  =		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_(__UpperCamelCase			,     direction="""inputs"""			,     inverted_values_shape=__UpperCamelCase						)
																		UpperCamelCase_		:							int  =		{0: """batch""", 1: """past_sequence + sequence"""}
												else:
																		UpperCamelCase_		:							Dict  =		{0: """batch""", 1: """sequence"""}

												return common_inputs





						@property
						def        A_							(self						)				->				int:
												return self._config.n_layer





						@property
						def        A_							(self						)				->				int:
												return self._config.n_head





						@property
						def        A_							(self						)				->				float:
												return 1E-3





						def        A_							(self			,     __UpperCamelCase			,     __UpperCamelCase = -1			,     __UpperCamelCase = -1			,     __UpperCamelCase = False			,     __UpperCamelCase = None			,     )				->				Mapping[str, Any]:
												UpperCamelCase_		:							Union[str, Any]  =		super(__UpperCamelCase			,     self						).generate_dummy_inputs(
												    __UpperCamelCase			,     batch_size=__UpperCamelCase			,     seq_length=__UpperCamelCase			,     is_pair=__UpperCamelCase			,     framework=__UpperCamelCase						)

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

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

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

												return ordered_inputs





						@property
						def        A_							(self						)				->				int:
												return 13






