





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     :    int         =						logging.get_logger(__name__)

_a     :    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   a_ (			__a      ):
			A__      :			List[str]       	=  'bloom'
			A__      :			Union[str, Any]       	=  ['past_key_values']
			A__      :			Optional[int]       	=  {
			    'num_hidden_layers': 'n_layer',
			    'num_attention_heads': 'n_head',
			}

			def __init__(   self   :  Optional[int]     , UpperCAmelCase__   :  Union[str, Any]=250_880     , UpperCAmelCase__   :  Dict=64     , UpperCAmelCase__   :  Optional[int]=2     , UpperCAmelCase__   :  Dict=8     , UpperCAmelCase__   :  List[str]=1e-5     , UpperCAmelCase__   :  Optional[Any]=0.02     , UpperCAmelCase__   :  str=True     , UpperCAmelCase__   :  str=1     , UpperCAmelCase__   :  Optional[int]=2     , UpperCAmelCase__   :  Union[str, Any]=False     , UpperCAmelCase__   :  int=0.0     , UpperCAmelCase__   :  Tuple=0.0     , UpperCAmelCase__   :  List[str]=1     , UpperCAmelCase__   :  Dict=False     , **UpperCAmelCase__   :  Optional[int]     , ):






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

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

							super().__init__(bos_token_id=_UpperCamelCase     , eos_token_id=_UpperCamelCase     , **_UpperCamelCase						)
class   a_ (			__a      ):
			A__      :			List[Any]       	=  version.parse('1.12'      )

			def __init__(   self   :  int     , UpperCAmelCase__   :  Union[str, Any]     , UpperCAmelCase__   :  Tuple = "default"     , UpperCAmelCase__   :  Optional[Any] = None     , UpperCAmelCase__   :  List[Any] = False     , ):






							"""simple docstring"""
							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?
											snake_case   :					List[str]    						=				0

			@property
			def      lowerCAmelCase(   self   :  List[Any]						):






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

							return common_inputs

			@property
			def      lowerCAmelCase(   self   :  List[str]						):






							"""simple docstring"""
							return self._config.n_layer

			@property
			def      lowerCAmelCase(   self   :  List[Any]						):






							"""simple docstring"""
							return self._config.n_head

			@property
			def      lowerCAmelCase(   self   :  Union[str, Any]						):






							"""simple docstring"""
							return 1e-3

			def      lowerCAmelCase(   self   :  Optional[int]     , UpperCAmelCase__   :  int     , UpperCAmelCase__   :  str = -1     , UpperCAmelCase__   :  Dict = -1     , UpperCAmelCase__   :  Union[str, Any] = False     , UpperCAmelCase__   :  str = None     , ):






							"""simple docstring"""
							snake_case   :					str    						=				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()
							snake_case   :					Dict    						=				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   :					Tuple    						=				common_inputs['''input_ids'''].shape
															# Not using the same length for past_key_values
															snake_case   :					Dict    						=				seqlen + 2
															snake_case   :					Optional[int]    						=				self._config.hidden_size // self.num_attention_heads
															snake_case   :					str    						=				(
															    batch * self.num_attention_heads,
															    head_dim,
															    past_key_values_length,
															)
															snake_case   :					Union[str, Any]    						=				(
															    batch * self.num_attention_heads,
															    past_key_values_length,
															    head_dim,
															)
															snake_case   :					Any    						=				[
															    (torch.zeros(_UpperCamelCase						), torch.zeros(_UpperCamelCase						)) for _ in range(self.num_layers						)
															]

							snake_case   :					int    						=				common_inputs['''attention_mask''']
							if self.use_past:
											snake_case   :					Any    						=				ordered_inputs['''attention_mask'''].dtype
											snake_case   :					List[Any]    						=				torch.cat(
											    [ordered_inputs['''attention_mask'''], torch.ones(_UpperCamelCase     , _UpperCamelCase     , dtype=_UpperCamelCase						)]     , dim=1						)

							return ordered_inputs



			@property
			def      lowerCAmelCase(   self   :  Dict						):






							"""simple docstring"""
							return 13


from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
			import tensorflow as tf

			from transformers import (
			    TFDebertaVaForMaskedLM,
			    TFDebertaVaForQuestionAnswering,
			    TFDebertaVaForSequenceClassification,
			    TFDebertaVaForTokenClassification,
			    TFDebertaVaModel,
			)





class       _lowerCAmelCase   :




				def __init__(   self							,							_UpperCamelCase							,							_UpperCamelCase=13							,							_UpperCamelCase=7							,							_UpperCamelCase=True							,							_UpperCamelCase=True							,							_UpperCamelCase=True							,							_UpperCamelCase=True							,							_UpperCamelCase=99							,							_UpperCamelCase=32							,							_UpperCamelCase=2							,							_UpperCamelCase=4							,							_UpperCamelCase=37							,							_UpperCamelCase="gelu"							,							_UpperCamelCase=0.1							,							_UpperCamelCase=0.1							,							_UpperCamelCase=512							,							_UpperCamelCase=16							,							_UpperCamelCase=2							,							_UpperCamelCase=0.02							,							_UpperCamelCase=False							,							_UpperCamelCase=True							,							_UpperCamelCase="None"							,							_UpperCamelCase=3							,							_UpperCamelCase=4							,							_UpperCamelCase=None							,							)							-> Tuple:
							lowerCAmelCase_         =      parent
							lowerCAmelCase_         =      batch_size
							lowerCAmelCase_         =      seq_length
							lowerCAmelCase_         =      is_training
							lowerCAmelCase_         =      use_input_mask
							lowerCAmelCase_         =      use_token_type_ids
							lowerCAmelCase_         =      use_labels
							lowerCAmelCase_         =      vocab_size
							lowerCAmelCase_         =      hidden_size
							lowerCAmelCase_         =      num_hidden_layers
							lowerCAmelCase_         =      num_attention_heads
							lowerCAmelCase_         =      intermediate_size
							lowerCAmelCase_         =      hidden_act
							lowerCAmelCase_         =      hidden_dropout_prob
							lowerCAmelCase_         =      attention_probs_dropout_prob
							lowerCAmelCase_         =      max_position_embeddings
							lowerCAmelCase_         =      type_vocab_size
							lowerCAmelCase_         =      type_sequence_label_size
							lowerCAmelCase_         =      initializer_range
							lowerCAmelCase_         =      num_labels
							lowerCAmelCase_         =      num_choices
							lowerCAmelCase_         =      relative_attention
							lowerCAmelCase_         =      position_biased_input
							lowerCAmelCase_         =      pos_att_type
							lowerCAmelCase_         =      scope




				def 	__a		(   self	)							-> List[str]:
							lowerCAmelCase_         =      ids_tensor([self.batch_size, self.seq_length]							,							self.vocab_size	)

							lowerCAmelCase_         =      None
							if self.use_input_mask:
										lowerCAmelCase_         =      random_attention_mask([self.batch_size, self.seq_length]	)

							lowerCAmelCase_         =      None
							if self.use_token_type_ids:
										lowerCAmelCase_         =      ids_tensor([self.batch_size, self.seq_length]							,							self.type_vocab_size	)

							lowerCAmelCase_         =      None
							lowerCAmelCase_         =      None
							lowerCAmelCase_         =      None
							if self.use_labels:
										lowerCAmelCase_         =      ids_tensor([self.batch_size]							,							self.type_sequence_label_size	)
										lowerCAmelCase_         =      ids_tensor([self.batch_size, self.seq_length]							,							self.num_labels	)

							lowerCAmelCase_         =      DebertaVaConfig(
							    vocab_size=self.vocab_size							,							hidden_size=self.hidden_size							,							num_hidden_layers=self.num_hidden_layers							,							num_attention_heads=self.num_attention_heads							,							intermediate_size=self.intermediate_size							,							hidden_act=self.hidden_act							,							hidden_dropout_prob=self.hidden_dropout_prob							,							attention_probs_dropout_prob=self.attention_probs_dropout_prob							,							max_position_embeddings=self.max_position_embeddings							,							type_vocab_size=self.type_vocab_size							,							relative_attention=self.relative_attention							,							position_biased_input=self.position_biased_input							,							initializer_range=self.initializer_range							,							return_dict=_UpperCamelCase							,							)

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




				def 	__a		(   self							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase	)							-> Dict:
							lowerCAmelCase_         =      TFDebertaVaModel(config=_UpperCamelCase	)
							lowerCAmelCase_         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

							lowerCAmelCase_         =      [input_ids, input_mask]
							lowerCAmelCase_         =      model(_UpperCamelCase	)

							lowerCAmelCase_         =      model(_UpperCamelCase	)

							self.parent.assertEqual(result.last_hidden_state.shape							,							(self.batch_size, self.seq_length, self.hidden_size)	)




				def 	__a		(   self							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase	)							-> Any:
							lowerCAmelCase_         =      TFDebertaVaForMaskedLM(config=_UpperCamelCase	)
							lowerCAmelCase_         =      {
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							    "token_type_ids": token_type_ids,
							}
							lowerCAmelCase_         =      model(_UpperCamelCase	)
							self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.seq_length, self.vocab_size)	)




				def 	__a		(   self							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase	)							-> str:
							lowerCAmelCase_         =      self.num_labels
							lowerCAmelCase_         =      TFDebertaVaForSequenceClassification(config=_UpperCamelCase	)
							lowerCAmelCase_         =      {
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							    "token_type_ids": token_type_ids,
							}

							lowerCAmelCase_         =      model(_UpperCamelCase	)
							self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.num_labels)	)




				def 	__a		(   self							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase	)							-> int:
							lowerCAmelCase_         =      self.num_labels
							lowerCAmelCase_         =      TFDebertaVaForTokenClassification(config=_UpperCamelCase	)
							lowerCAmelCase_         =      {
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							    "token_type_ids": token_type_ids,
							}
							lowerCAmelCase_         =      model(_UpperCamelCase	)
							self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.seq_length, self.num_labels)	)




				def 	__a		(   self							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase							,							_UpperCamelCase	)							-> Dict:
							lowerCAmelCase_         =      TFDebertaVaForQuestionAnswering(config=_UpperCamelCase	)
							lowerCAmelCase_         =      {
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							    "token_type_ids": token_type_ids,
							}

							lowerCAmelCase_         =      model(_UpperCamelCase	)
							self.parent.assertEqual(result.start_logits.shape							,							(self.batch_size, self.seq_length)	)
							self.parent.assertEqual(result.end_logits.shape							,							(self.batch_size, self.seq_length)	)




				def 	__a		(   self	)							-> Tuple:
							lowerCAmelCase_         =      self.prepare_config_and_inputs()
							(
							    (
							    lowerCAmelCase_
							)      ,    (
							    lowerCAmelCase_
							)      ,    (
							    lowerCAmelCase_
							)      ,    (
							    lowerCAmelCase_
							)      ,    (
							    lowerCAmelCase_
							)      ,    (
							    lowerCAmelCase_
							)      ,    (
							    lowerCAmelCase_
							)      ,    
							)         =      config_and_inputs
							lowerCAmelCase_         =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
							return config, inputs_dict





@require_tf
class       _lowerCAmelCase   (      __a   , __a   , unittest.TestCase			):
				_lowercase     						=(
				    (
				        TFDebertaVaModel,
				        TFDebertaVaForMaskedLM,
				        TFDebertaVaForQuestionAnswering,
				        TFDebertaVaForSequenceClassification,
				        TFDebertaVaForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				_lowercase     						=(
				    {
				        '''feature-extraction''': TFDebertaVaModel,
				        '''fill-mask''': TFDebertaVaForMaskedLM,
				        '''question-answering''': TFDebertaVaForQuestionAnswering,
				        '''text-classification''': TFDebertaVaForSequenceClassification,
				        '''token-classification''': TFDebertaVaForTokenClassification,
				        '''zero-shot''': TFDebertaVaForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)

				_lowercase     						=False
				_lowercase     						=False




				def 	__a		(   self	)							-> Optional[int]:
							lowerCAmelCase_         =      TFDebertaVaModelTester(self	)
							lowerCAmelCase_         =      ConfigTester(self							,							config_class=_UpperCamelCase							,							hidden_size=37	)




				def 	__a		(   self	)							-> str:
							self.config_tester.run_common_tests()




				def 	__a		(   self	)							-> int:
							lowerCAmelCase_         =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_UpperCamelCase	)




				def 	__a		(   self	)							-> List[Any]:
							lowerCAmelCase_         =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_UpperCamelCase	)




				def 	__a		(   self	)							-> List[str]:
							lowerCAmelCase_         =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*_UpperCamelCase	)




				def 	__a		(   self	)							-> List[Any]:
							lowerCAmelCase_         =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*_UpperCamelCase	)




				def 	__a		(   self	)							-> int:
							lowerCAmelCase_         =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*_UpperCamelCase	)




				@slow
				def 	__a		(   self	)							-> Union[str, Any]:
							lowerCAmelCase_         =      TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"	)
							self.assertIsNotNone(_UpperCamelCase	)





@require_tf
class       _lowerCAmelCase   (      unittest.TestCase			):




				@unittest.skip(reason="Model not available yet"	)
				def 	__a		(   self	)							-> List[str]:
							pass




				@slow
				def 	__a		(   self	)							-> Dict:
							lowerCAmelCase_         =      TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"	)
							lowerCAmelCase_         =      tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]	)
							lowerCAmelCase_         =      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
							lowerCAmelCase_         =      model(_UpperCamelCase							,							attention_mask=_UpperCamelCase	)[0]

							lowerCAmelCase_         =      tf.constant(
							    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]	)
							tf.debugging.assert_near(output[:, 1:4, 1:4]							,							_UpperCamelCase							,							atol=1e-4	)



