

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 _UpperCamelCase				:
			'''simple docstring'''







			def __init__(      self				:			List[str]   ,   a				:			Optional[Any]   ,   a				:			List[str]=13   ,   a				:			Union[str, Any]=7   ,   a				:			List[str]=True   ,   a				:			str=True   ,   a				:			Union[str, Any]=True   ,   a				:			Optional[Any]=True   ,   a				:			str=99   ,   a				:			str=[1, 1, 2]   ,   a				:			Any=1   ,   a				:			str=32   ,   a				:			List[Any]=4   ,   a				:			Tuple=8   ,   a				:			Tuple=37   ,   a				:			Dict="gelu_new"   ,   a				:			List[Any]=0.1   ,   a				:			Tuple=0.1   ,   a				:			Any=0.0   ,   a				:			Dict=512   ,   a				:			Any=3   ,   a				:			Dict=0.02   ,   a				:			str=3   ,   a				:			Union[str, Any]=4   ,   a				:			Union[str, Any]=None   ,   a				:			Any=False   ,   )				->							Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Any					  =							parent
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							batch_size
				SCREAMING_SNAKE_CASE :   Tuple					  =							seq_length
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							is_training
				SCREAMING_SNAKE_CASE :   List[Any]					  =							use_input_mask
				SCREAMING_SNAKE_CASE :   Dict					  =							use_token_type_ids
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							use_labels
				SCREAMING_SNAKE_CASE :   int					  =							vocab_size
				SCREAMING_SNAKE_CASE :   List[str]					  =							block_sizes
				SCREAMING_SNAKE_CASE :   List[Any]					  =							num_decoder_layers
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							d_model
				SCREAMING_SNAKE_CASE :   Any					  =							n_head
				SCREAMING_SNAKE_CASE :   Tuple					  =							d_head
				SCREAMING_SNAKE_CASE :   Dict					  =							d_inner
				SCREAMING_SNAKE_CASE :   List[Any]					  =							hidden_act
				SCREAMING_SNAKE_CASE :   str					  =							hidden_dropout
				SCREAMING_SNAKE_CASE :   List[Any]					  =							attention_dropout
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							activation_dropout
				SCREAMING_SNAKE_CASE :   int					  =							max_position_embeddings
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							type_vocab_size
				SCREAMING_SNAKE_CASE :   int					  =							2
				SCREAMING_SNAKE_CASE :   List[Any]					  =							num_labels
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							num_choices
				SCREAMING_SNAKE_CASE :   Dict					  =							scope
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							initializer_std

				# Used in the tests to check the size of the first attention layer
				SCREAMING_SNAKE_CASE :   Tuple					  =							n_head
				# Used in the tests to check the size of the first hidden state
				SCREAMING_SNAKE_CASE :   Any					  =							self.d_model
				# Used in the tests to check the number of output hidden states/attentions
				SCREAMING_SNAKE_CASE :   int					  =							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:
					SCREAMING_SNAKE_CASE :   List[Any]					  =							self.num_hidden_layers + 2
			def 				__UpperCamelCase			(      self				:			Union[str, Any]						)				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   str					  =							ids_tensor([self.batch_size, self.seq_length]   ,   self.vocab_size						)

				SCREAMING_SNAKE_CASE :   List[str]					  =							None
				if self.use_input_mask:
					SCREAMING_SNAKE_CASE :   List[str]					  =							random_attention_mask([self.batch_size, self.seq_length]						)

				SCREAMING_SNAKE_CASE :   str					  =							None
				if self.use_token_type_ids:
					SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							ids_tensor([self.batch_size, self.seq_length]   ,   self.type_vocab_size						)

				SCREAMING_SNAKE_CASE :   int					  =							None
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							None
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							None
				if self.use_labels:
					SCREAMING_SNAKE_CASE :   List[str]					  =							ids_tensor([self.batch_size]   ,   self.type_sequence_label_size						)
					SCREAMING_SNAKE_CASE :   List[str]					  =							ids_tensor([self.batch_size, self.seq_length]   ,   self.num_labels						)
					SCREAMING_SNAKE_CASE :   int					  =							ids_tensor([self.batch_size]   ,   self.num_choices						)

				SCREAMING_SNAKE_CASE :   int					  =							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 				__UpperCamelCase			(      self				:			List[Any]   ,   a				:			Optional[Any]   ,   a				:			str   ,   a				:			Tuple   ,   a				:			List[Any]   ,   a				:			int   ,   a				:			Any   ,   a				:			str   ,   )				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Dict					  =							TFFunnelModel(config=a						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   int					  =							model(a						)

				SCREAMING_SNAKE_CASE :   List[str]					  =							[input_ids, input_mask]
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							model(a						)

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							model(a						)
				self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, self.seq_length, self.d_model)						)

				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							False
				SCREAMING_SNAKE_CASE :   int					  =							TFFunnelModel(config=a						)
				SCREAMING_SNAKE_CASE :   Tuple					  =							model(a						)
				self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, self.seq_length, self.d_model)						)

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							False
				SCREAMING_SNAKE_CASE :   List[str]					  =							TFFunnelModel(config=a						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							model(a						)
				self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, self.seq_length, self.d_model)						)
			def 				__UpperCamelCase			(      self				:			Union[str, Any]   ,   a				:			str   ,   a				:			Optional[Any]   ,   a				:			List[str]   ,   a				:			List[Any]   ,   a				:			int   ,   a				:			List[Any]   ,   a				:			Optional[Any]   ,   )				->							int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Dict					  =							TFFunnelBaseModel(config=a						)
				SCREAMING_SNAKE_CASE :   Dict					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   List[Any]					  =							model(a						)

				SCREAMING_SNAKE_CASE :   int					  =							[input_ids, input_mask]
				SCREAMING_SNAKE_CASE :   str					  =							model(a						)

				SCREAMING_SNAKE_CASE :   Tuple					  =							model(a						)
				self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, 2, self.d_model)						)

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							False
				SCREAMING_SNAKE_CASE :   List[Any]					  =							TFFunnelBaseModel(config=a						)
				SCREAMING_SNAKE_CASE :   int					  =							model(a						)
				self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, 3, self.d_model)						)

				SCREAMING_SNAKE_CASE :   Any					  =							False
				SCREAMING_SNAKE_CASE :   List[Any]					  =							TFFunnelBaseModel(config=a						)
				SCREAMING_SNAKE_CASE :   List[str]					  =							model(a						)
				self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, 2, self.d_model)						)
			def 				__UpperCamelCase			(      self				:			str   ,   a				:			int   ,   a				:			str   ,   a				:			List[Any]   ,   a				:			Optional[Any]   ,   a				:			Tuple   ,   a				:			Any   ,   a				:			List[str]   ,   )				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   int					  =							TFFunnelForPreTraining(config=a						)
				SCREAMING_SNAKE_CASE :   List[Any]					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   Dict					  =							model(a						)
				self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.seq_length)						)
			def 				__UpperCamelCase			(      self				:			int   ,   a				:			Tuple   ,   a				:			str   ,   a				:			List[Any]   ,   a				:			str   ,   a				:			Union[str, Any]   ,   a				:			Any   ,   a				:			Dict   ,   )				->							Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   int					  =							TFFunnelForMaskedLM(config=a						)
				SCREAMING_SNAKE_CASE :   List[Any]					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   str					  =							model(a						)
				self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.seq_length, self.vocab_size)						)
			def 				__UpperCamelCase			(      self				:			List[str]   ,   a				:			Dict   ,   a				:			Union[str, Any]   ,   a				:			Any   ,   a				:			Any   ,   a				:			Tuple   ,   a				:			Tuple   ,   a				:			Optional[int]   ,   )				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							self.num_labels
				SCREAMING_SNAKE_CASE :   Dict					  =							TFFunnelForSequenceClassification(config=a						)
				SCREAMING_SNAKE_CASE :   int					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							model(a						)
				self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.num_labels)						)
			def 				__UpperCamelCase			(      self				:			Optional[Any]   ,   a				:			Optional[Any]   ,   a				:			Optional[int]   ,   a				:			Dict   ,   a				:			Union[str, Any]   ,   a				:			Optional[Any]   ,   a				:			Union[str, Any]   ,   a				:			List[Any]   ,   )				->							Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							self.num_choices
				SCREAMING_SNAKE_CASE :   List[str]					  =							TFFunnelForMultipleChoice(config=a						)
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							tf.tile(tf.expand_dims(a   ,   1						)   ,   (1, self.num_choices, 1)						)
				SCREAMING_SNAKE_CASE :   Any					  =							tf.tile(tf.expand_dims(a   ,   1						)   ,   (1, self.num_choices, 1)						)
				SCREAMING_SNAKE_CASE :   int					  =							tf.tile(tf.expand_dims(a   ,   1						)   ,   (1, self.num_choices, 1)						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							{
				    "input_ids": multiple_choice_inputs_ids,
				    "attention_mask": multiple_choice_input_mask,
				    "token_type_ids": multiple_choice_token_type_ids,
				}
				SCREAMING_SNAKE_CASE :   List[str]					  =							model(a						)
				self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.num_choices)						)
			def 				__UpperCamelCase			(      self				:			Tuple   ,   a				:			Optional[Any]   ,   a				:			Any   ,   a				:			List[str]   ,   a				:			str   ,   a				:			Tuple   ,   a				:			Dict   ,   a				:			Optional[int]   ,   )				->							List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Dict					  =							self.num_labels
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							TFFunnelForTokenClassification(config=a						)
				SCREAMING_SNAKE_CASE :   int					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							model(a						)
				self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.seq_length, self.num_labels)						)
			def 				__UpperCamelCase			(      self				:			Dict   ,   a				:			Optional[Any]   ,   a				:			Dict   ,   a				:			Optional[int]   ,   a				:			str   ,   a				:			Any   ,   a				:			Dict   ,   a				:			List[Any]   ,   )				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							TFFunnelForQuestionAnswering(config=a						)
				SCREAMING_SNAKE_CASE :   int					  =							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
				SCREAMING_SNAKE_CASE :   List[str]					  =							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 				__UpperCamelCase			(      self				:			Optional[int]						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[str]					  =							self.prepare_config_and_inputs()
				(
				    (
				    SCREAMING_SNAKE_CASE
				)  ,(
				    SCREAMING_SNAKE_CASE
				)  ,(
				    SCREAMING_SNAKE_CASE
				)  ,(
				    SCREAMING_SNAKE_CASE
				)  ,(
				    SCREAMING_SNAKE_CASE
				)  ,(
				    SCREAMING_SNAKE_CASE
				)  ,(
				    SCREAMING_SNAKE_CASE
				)  ,
				) :   Dict					  =							config_and_inputs
				SCREAMING_SNAKE_CASE :   List[Any]					  =							{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
				return config, inputs_dict






@require_tf
class _UpperCamelCase				(				__A				,						__A				,						unittest.TestCase ):
			'''simple docstring'''







			lowerCamelCase__							     =(
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCamelCase__							     =(
			    {
			        'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
			        'fill-mask': TFFunnelForMaskedLM,
			        'question-answering': TFFunnelForQuestionAnswering,
			        'text-classification': TFFunnelForSequenceClassification,
			        'token-classification': TFFunnelForTokenClassification,
			        'zero-shot': TFFunnelForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			lowerCamelCase__							     =False
			lowerCamelCase__							     =False
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							TFFunnelModelTester(self						)
				SCREAMING_SNAKE_CASE :   Any					  =							ConfigTester(self   ,   config_class=a						)
			def 				__UpperCamelCase			(      self				:			Tuple						)				->							List[str]:

				"""simple docstring"""

				self.config_tester.run_common_tests()
			def 				__UpperCamelCase			(      self				:			Union[str, Any]						)				->							Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[Any]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*a						)
			def 				__UpperCamelCase			(      self				:			Any						)				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Tuple					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_pretraining(*a						)
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Any					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*a						)
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Dict					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*a						)






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

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*a						)






@require_tf
class _UpperCamelCase				(				__A				,						unittest.TestCase ):
			'''simple docstring'''







			lowerCamelCase__							     =(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			lowerCamelCase__							     =False
			lowerCamelCase__							     =False
			def 				__UpperCamelCase			(      self				:			Any						)				->							Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							TFFunnelModelTester(self   ,   base=a						)
				SCREAMING_SNAKE_CASE :   int					  =							ConfigTester(self   ,   config_class=a						)
			def 				__UpperCamelCase			(      self				:			int						)				->							List[str]:

				"""simple docstring"""

				self.config_tester.run_common_tests()
			def 				__UpperCamelCase			(      self				:			List[str]						)				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_base_model(*a						)
			def 				__UpperCamelCase			(      self				:			List[str]						)				->							int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[Any]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*a						)






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

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   str					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*a						)


from __future__ import annotations

def 			lowerCamelCase__			(       _a):
	if len(_a) == 0:
		return []
	SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE :   Tuple					  =							min(_a), max(_a)
	SCREAMING_SNAKE_CASE :   Dict					  =							int(max_value - min_value) + 1
	SCREAMING_SNAKE_CASE :   list[list]					  =							[[] for _ in range(_a)]

	for i in my_list:
		buckets[int(i - min_value)].append(_a)

	return [v for bucket in buckets for v in sorted(_a)]


if __name__ == "__main__":
			from doctest import testmod

			testmod()
			assert bucket_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
			assert bucket_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]