



from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
							    TFFunnelBaseModel,
							    TFFunnelForMaskedLM,
							    TFFunnelForMultipleChoice,
							    TFFunnelForPreTraining,
							    TFFunnelForQuestionAnswering,
							    TFFunnelForSequenceClassification,
							    TFFunnelForTokenClassification,
							    TFFunnelModel,
							)







class       __lowerCAmelCase   :



			def __init__(						self       :  List[Any]			,		A       :  Any			,		A       :  List[Any]=13			,		A       :  Optional[int]=7			,		A       :  Optional[int]=True			,		A       :  Tuple=True			,		A       :  Optional[Any]=True			,		A       :  str=True			,		A       :  Optional[int]=99			,		A       :  List[str]=[1, 1, 2]			,		A       :  List[Any]=1			,		A       :  int=32			,		A       :  Optional[Any]=4			,		A       :  Optional[Any]=8			,		A       :  List[Any]=37			,		A       :  Optional[int]="gelu_new"			,		A       :  Optional[int]=0.1			,		A       :  Tuple=0.1			,		A       :  Tuple=0.0			,		A       :  Tuple=5_12			,		A       :  List[Any]=3			,		A       :  int=0.0_2			,		A       :  Dict=3			,		A       :  Dict=4			,		A       :  str=None			,		A       :  Optional[int]=False			,		)       ->   Tuple:



						"""simple docstring"""






						_UpperCAmelCase			=       parent
						_UpperCAmelCase			=       batch_size
						_UpperCAmelCase			=       seq_length
						_UpperCAmelCase			=       is_training
						_UpperCAmelCase			=       use_input_mask
						_UpperCAmelCase			=       use_token_type_ids
						_UpperCAmelCase			=       use_labels
						_UpperCAmelCase			=       vocab_size
						_UpperCAmelCase			=       block_sizes
						_UpperCAmelCase			=       num_decoder_layers
						_UpperCAmelCase			=       d_model
						_UpperCAmelCase			=       n_head
						_UpperCAmelCase			=       d_head
						_UpperCAmelCase			=       d_inner
						_UpperCAmelCase			=       hidden_act
						_UpperCAmelCase			=       hidden_dropout
						_UpperCAmelCase			=       attention_dropout
						_UpperCAmelCase			=       activation_dropout
						_UpperCAmelCase			=       max_position_embeddings
						_UpperCAmelCase			=       type_vocab_size
						_UpperCAmelCase			=       2
						_UpperCAmelCase			=       num_labels
						_UpperCAmelCase			=       num_choices
						_UpperCAmelCase			=       scope
						_UpperCAmelCase			=       initializer_std

						# Used in the tests to check the size of the first attention layer
						_UpperCAmelCase			=       n_head
						# Used in the tests to check the size of the first hidden state
						_UpperCAmelCase			=       self.d_model
						# Used in the tests to check the number of output hidden states/attentions
						_UpperCAmelCase			=       sum(self.block_sizes) + (0 if base else self.num_decoder_layers)
						# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
						# the last hidden state of the first block (which is the first hidden state of the decoder).
						if not base:
									_UpperCAmelCase			=       self.num_hidden_layers + 2



			def    _lowerCamelCase	(						self       :  str)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       ids_tensor([self.batch_size, self.seq_length]			,		self.vocab_size)

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

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

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

						_UpperCAmelCase			=       FunnelConfig(
						    vocab_size=self.vocab_size			,		block_sizes=self.block_sizes			,		num_decoder_layers=self.num_decoder_layers			,		d_model=self.d_model			,		n_head=self.n_head			,		d_head=self.d_head			,		d_inner=self.d_inner			,		hidden_act=self.hidden_act			,		hidden_dropout=self.hidden_dropout			,		attention_dropout=self.attention_dropout			,		activation_dropout=self.activation_dropout			,		max_position_embeddings=self.max_position_embeddings			,		type_vocab_size=self.type_vocab_size			,		initializer_std=self.initializer_std			,		)

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



			def    _lowerCamelCase	(						self       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  Any			,		A       :  List[Any]			,		A       :  Tuple			,		A       :  int			,		A       :  Dict			,		A       :  Any			,		)       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelModel(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)

						_UpperCAmelCase			=       [input_ids, input_mask]
						_UpperCAmelCase			=       model(A)

						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, self.seq_length, self.d_model))

						_UpperCAmelCase			=       False
						_UpperCAmelCase			=       TFFunnelModel(config=A)
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, self.seq_length, self.d_model))

						_UpperCAmelCase			=       False
						_UpperCAmelCase			=       TFFunnelModel(config=A)
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, self.seq_length, self.d_model))



			def    _lowerCamelCase	(						self       :  List[str]			,		A       :  str			,		A       :  int			,		A       :  int			,		A       :  Union[str, Any]			,		A       :  Optional[Any]			,		A       :  Dict			,		A       :  Dict			,		)       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelBaseModel(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)

						_UpperCAmelCase			=       [input_ids, input_mask]
						_UpperCAmelCase			=       model(A)

						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, 2, self.d_model))

						_UpperCAmelCase			=       False
						_UpperCAmelCase			=       TFFunnelBaseModel(config=A)
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, 3, self.d_model))

						_UpperCAmelCase			=       False
						_UpperCAmelCase			=       TFFunnelBaseModel(config=A)
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.last_hidden_state.shape			,		(self.batch_size, 2, self.d_model))



			def    _lowerCamelCase	(						self       :  List[str]			,		A       :  List[str]			,		A       :  Optional[int]			,		A       :  Optional[Any]			,		A       :  Any			,		A       :  Dict			,		A       :  List[Any]			,		A       :  Any			,		)       ->   str:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelForPreTraining(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.seq_length))



			def    _lowerCamelCase	(						self       :  Union[str, Any]			,		A       :  Any			,		A       :  Any			,		A       :  str			,		A       :  Optional[Any]			,		A       :  Dict			,		A       :  Tuple			,		A       :  Dict			,		)       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelForMaskedLM(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.seq_length, self.vocab_size))



			def    _lowerCamelCase	(						self       :  Optional[Any]			,		A       :  Optional[Any]			,		A       :  List[Any]			,		A       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  List[str]			,		A       :  Tuple			,		A       :  int			,		)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.num_labels
						_UpperCAmelCase			=       TFFunnelForSequenceClassification(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.num_labels))



			def    _lowerCamelCase	(						self       :  int			,		A       :  Optional[int]			,		A       :  Any			,		A       :  str			,		A       :  str			,		A       :  Any			,		A       :  Union[str, Any]			,		A       :  Dict			,		)       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       self.num_choices
						_UpperCAmelCase			=       TFFunnelForMultipleChoice(config=A)
						_UpperCAmelCase			=       tf.tile(tf.expand_dims(A			,		1)			,		(1, self.num_choices, 1))
						_UpperCAmelCase			=       tf.tile(tf.expand_dims(A			,		1)			,		(1, self.num_choices, 1))
						_UpperCAmelCase			=       tf.tile(tf.expand_dims(A			,		1)			,		(1, self.num_choices, 1))
						_UpperCAmelCase			=       {
						    'input_ids': multiple_choice_inputs_ids,
						    'attention_mask': multiple_choice_input_mask,
						    'token_type_ids': multiple_choice_token_type_ids,
						}
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.num_choices))



			def    _lowerCamelCase	(						self       :  List[str]			,		A       :  Any			,		A       :  List[str]			,		A       :  Any			,		A       :  Any			,		A       :  List[str]			,		A       :  Optional[int]			,		A       :  Optional[int]			,		)       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       self.num_labels
						_UpperCAmelCase			=       TFFunnelForTokenClassification(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.seq_length, self.num_labels))



			def    _lowerCamelCase	(						self       :  Tuple			,		A       :  List[str]			,		A       :  Union[str, Any]			,		A       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  Optional[Any]			,		A       :  int			,		A       :  Union[str, Any]			,		)       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelForQuestionAnswering(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
						_UpperCAmelCase			=       model(A)
						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    _lowerCamelCase	(						self       :  int)       ->   List[str]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.prepare_config_and_inputs()
						(
						    (
						    _UpperCAmelCase
						)	,					(
						    _UpperCAmelCase
						)	,					(
						    _UpperCAmelCase
						)	,					(
						    _UpperCAmelCase
						)	,					(
						    _UpperCAmelCase
						)	,					(
						    _UpperCAmelCase
						)	,					(
						    _UpperCAmelCase
						)	,					
						)			=       config_and_inputs
						_UpperCAmelCase			=       {'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						):
			UpperCamelCase        =					(
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			UpperCamelCase        =					(
			    {
			        '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
			        '''fill-mask''': TFFunnelForMaskedLM,
			        '''question-answering''': TFFunnelForQuestionAnswering,
			        '''text-classification''': TFFunnelForSequenceClassification,
			        '''token-classification''': TFFunnelForTokenClassification,
			        '''zero-shot''': TFFunnelForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			UpperCamelCase        =					False
			UpperCamelCase        =					False



			def    _lowerCamelCase	(						self       :  Optional[int])       ->   str:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelModelTester(self)
						_UpperCAmelCase			=       ConfigTester(self			,		config_class=A)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   str:



						"""simple docstring"""






						self.config_tester.run_common_tests()



			def    _lowerCamelCase	(						self       :  int)       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*A)



			def    _lowerCamelCase	(						self       :  int)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*A)



			def    _lowerCamelCase	(						self       :  Dict)       ->   Dict:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*A)



			def    _lowerCamelCase	(						self       :  List[str])       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*A)



			def    _lowerCamelCase	(						self       :  Any)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*A)







@require_tf
class       __lowerCAmelCase   (      A    ,						unittest.TestCase						):
			UpperCamelCase        =					(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			UpperCamelCase        =					False
			UpperCamelCase        =					False



			def    _lowerCamelCase	(						self       :  List[str])       ->   Tuple:



						"""simple docstring"""






						_UpperCAmelCase			=       TFFunnelModelTester(self			,		base=A)
						_UpperCAmelCase			=       ConfigTester(self			,		config_class=A)



			def    _lowerCamelCase	(						self       :  str)       ->   Tuple:



						"""simple docstring"""






						self.config_tester.run_common_tests()



			def    _lowerCamelCase	(						self       :  List[str])       ->   Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*A)



			def    _lowerCamelCase	(						self       :  Dict)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*A)



			def    _lowerCamelCase	(						self       :  List[Any])       ->   Tuple:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*A)





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase__       =	{
    "configuration_deberta": ["DEBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP", "DebertaConfig", "DebertaOnnxConfig"],
    "tokenization_deberta": ["DebertaTokenizer"],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	["DebertaTokenizerFast"]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	[
							    "DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "DebertaForMaskedLM",
							    "DebertaForQuestionAnswering",
							    "DebertaForSequenceClassification",
							    "DebertaForTokenClassification",
							    "DebertaModel",
							    "DebertaPreTrainedModel",
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__       =	[
							    "TF_DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "TFDebertaForMaskedLM",
							    "TFDebertaForQuestionAnswering",
							    "TFDebertaForSequenceClassification",
							    "TFDebertaForTokenClassification",
							    "TFDebertaModel",
							    "TFDebertaPreTrainedModel",
							]


if TYPE_CHECKING:
							from .configuration_deberta import DEBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP, DebertaConfig, DebertaOnnxConfig
							from .tokenization_deberta import DebertaTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_deberta_fast import DebertaTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_deberta import (
														    DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DebertaForMaskedLM,
														    DebertaForQuestionAnswering,
														    DebertaForSequenceClassification,
														    DebertaForTokenClassification,
														    DebertaModel,
														    DebertaPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_deberta import (
														    TF_DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFDebertaForMaskedLM,
														    TFDebertaForQuestionAnswering,
														    TFDebertaForSequenceClassification,
														    TFDebertaForTokenClassification,
														    TFDebertaModel,
														    TFDebertaPreTrainedModel,
														)


else:
							import sys

							UpperCAmelCase__       =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
