






"""simple docstring"""






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       snake_case_       :



	"""simple docstring"""

	def __init__(      self  ,					__a  ,					__a=13  ,					__a=7  ,					__a=True  ,					__a=True  ,					__a=True  ,					__a=True  ,					__a=99  ,					__a=[1, 1, 2]  ,					__a=1  ,					__a=32  ,					__a=4  ,					__a=8  ,					__a=37  ,					__a="gelu_new"  ,					__a=0.1  ,					__a=0.1  ,					__a=0.0  ,					__a=512  ,					__a=3  ,					__a=0.02  ,					__a=3  ,					__a=4  ,					__a=None  ,					__a=False  ,					):


					"""simple docstring"""

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

					# Used in the tests to check the size of the first attention layer
					A__							 =       n_head
					# Used in the tests to check the size of the first hidden state
					A__							 =       self.d_model
					# Used in the tests to check the number of output hidden states/attentions
					A__							 =       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:
									A__							 =       self.num_hidden_layers + 2


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

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

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

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

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

					A__							 =       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  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

					A__							 =       TFFunnelModel(config=__a						)
					A__							 =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
					A__							 =       model(__a						)

					A__							 =       [input_ids, input_mask]
					A__							 =       model(__a						)

					A__							 =       model(__a						)
					self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.d_model)						)

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

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

					A__							 =       TFFunnelBaseModel(config=__a						)
					A__							 =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
					A__							 =       model(__a						)

					A__							 =       [input_ids, input_mask]
					A__							 =       model(__a						)

					A__							 =       model(__a						)
					self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, 2, self.d_model)						)

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

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

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


	def       _UpperCAmelCase						(      self  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					__a  ,					):


					"""simple docstring"""

					A__							 =       TFFunnelForQuestionAnswering(config=__a						)
					A__							 =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
					A__							 =       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						):


					"""simple docstring"""

					A__							 =       self.prepare_config_and_inputs()
					(
					    (
					    A__
					) ,			(
					    A__
					) ,			(
					    A__
					) ,			(
					    A__
					) ,			(
					    A__
					) ,			(
					    A__
					) ,			(
					    A__
					) ,			
					)							 =       config_and_inputs
					A__							 =       {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
					return config, inputs_dict





@require_tf
class       snake_case_       (    _lowerCamelCase    ,							_lowerCamelCase    ,							unittest.TestCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Optional[Any]   			=					(
	    (
	        TFFunnelModel,
	        TFFunnelForMaskedLM,
	        TFFunnelForPreTraining,
	        TFFunnelForQuestionAnswering,
	        TFFunnelForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	SCREAMING_SNAKE_CASE_:							List[Any]   			=					(
	    {
	        """feature-extraction""": (TFFunnelBaseModel, TFFunnelModel),
	        """fill-mask""": TFFunnelForMaskedLM,
	        """question-answering""": TFFunnelForQuestionAnswering,
	        """text-classification""": TFFunnelForSequenceClassification,
	        """token-classification""": TFFunnelForTokenClassification,
	        """zero-shot""": TFFunnelForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					False
	SCREAMING_SNAKE_CASE_:							Optional[int]   			=					False


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       TFFunnelModelTester(self						)
					A__							 =       ConfigTester(self  ,					config_class=__a						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					self.config_tester.run_common_tests()


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__a						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*__a						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*__a						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__a						)






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__a						)





@require_tf
class       snake_case_       (    _lowerCamelCase    ,							unittest.TestCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Optional[int]   			=					(
	    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
	)
	SCREAMING_SNAKE_CASE_:							Optional[Any]   			=					False
	SCREAMING_SNAKE_CASE_:							Optional[Any]   			=					False


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       TFFunnelModelTester(self  ,					base=__a						)
					A__							 =       ConfigTester(self  ,					config_class=__a						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					self.config_tester.run_common_tests()


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_base_model(*__a						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*__a						)






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*__a						)










"""simple docstring"""






from ...processing_utils import ProcessorMixin





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					["""image_processor""", """feature_extractor"""]
	SCREAMING_SNAKE_CASE_:							Optional[int]   			=					"""TvltImageProcessor"""
	SCREAMING_SNAKE_CASE_:							Optional[int]   			=					"""TvltFeatureExtractor"""


	def __init__(      self  ,					__a  ,					__a						):


					"""simple docstring"""

					super().__init__(image_processor=__a  ,					feature_extractor=__a						)

					A__							 =       image_processor
					A__							 =       feature_extractor


	def __call__(      self  ,					__a=None  ,					__a=None  ,					__a=None  ,					__a=None  ,					__a=False  ,					__a=False  ,					*__a  ,					**__a  ,					):


					"""simple docstring"""

					if images is None and audio is None:
									raise ValueError('You need to specify either an `images` or `audio` input to process.'						)

					A__							 =       None
					if images is not None:
									A__							 =       self.image_processor(__a  ,					mask_pixel=__a  ,					*__a  ,					**__a						)
					if images_mixed is not None:
									A__							 =       self.image_processor(__a  ,					is_mixed=__a  ,					*__a  ,					**__a						)
					if audio is not None:
									A__							 =       self.feature_extractor(
									    __a  ,					*__a  ,					sampling_rate=__a  ,					mask_audio=__a  ,					**__a						)

					A__							 =       {}
					if audio is not None:
									output_dict.update(__a						)
					if images is not None:
									output_dict.update(__a						)
					if images_mixed_dict is not None:
									output_dict.update(__a						)
					return output_dict






	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processor.model_input_names
					A__							 =       self.feature_extractor.model_input_names
					return list(dict.fromkeys(image_processor_input_names + feature_extractor_input_names						)						)


