






"""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        _SCREAMING_SNAKE_CASE						:





							"""simple docstring"""





							def __init__(   self:     Tuple				,		__A:     int				,		__A:     Any=13				,		__A:     Optional[int]=7				,		__A:     List[str]=True				,		__A:     str=True				,		__A:     List[Any]=True				,		__A:     Union[str, Any]=True				,		__A:     Optional[int]=99				,		__A:     List[str]=[1, 1, 2]				,		__A:     str=1				,		__A:     List[str]=32				,		__A:     List[str]=4				,		__A:     Dict=8				,		__A:     str=37				,		__A:     Union[str, Any]="gelu_new"				,		__A:     Tuple=0.1				,		__A:     str=0.1				,		__A:     Any=0.0				,		__A:     Union[str, Any]=512				,		__A:     List[str]=3				,		__A:     Tuple=0.0_2				,		__A:     int=3				,		__A:     int=4				,		__A:     Dict=None				,		__A:     Tuple=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  lowercase		(   self:     List[str]    ):

												'''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  lowercase		(   self:     List[Any]				,		__A:     Tuple				,		__A:     Dict				,		__A:     Union[str, Any]				,		__A:     str				,		__A:     Tuple				,		__A:     Union[str, Any]				,		__A:     str				,		):

												'''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  lowercase		(   self:     str				,		__A:     Dict				,		__A:     List[str]				,		__A:     List[str]				,		__A:     int				,		__A:     str				,		__A:     int				,		__A:     Any				,		):

												'''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  lowercase		(   self:     Any				,		__A:     Any				,		__A:     Tuple				,		__A:     int				,		__A:     Optional[int]				,		__A:     int				,		__A:     List[Any]				,		__A:     List[str]				,		):

												'''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  lowercase		(   self:     Tuple				,		__A:     List[Any]				,		__A:     Union[str, Any]				,		__A:     int				,		__A:     str				,		__A:     Tuple				,		__A:     Optional[Any]				,		__A:     int				,		):

												'''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  lowercase		(   self:     str				,		__A:     Union[str, Any]				,		__A:     Optional[int]				,		__A:     Tuple				,		__A:     int				,		__A:     Union[str, Any]				,		__A:     str				,		__A:     Optional[Any]				,		):

												'''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  lowercase		(   self:     List[Any]				,		__A:     Union[str, Any]				,		__A:     Any				,		__A:     Dict				,		__A:     Tuple				,		__A:     int				,		__A:     Optional[Any]				,		__A:     int				,		):

												'''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  lowercase		(   self:     List[Any]				,		__A:     Optional[Any]				,		__A:     Union[str, Any]				,		__A:     Tuple				,		__A:     int				,		__A:     int				,		__A:     List[str]				,		__A:     int				,		):

												'''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  lowercase		(   self:     Any				,		__A:     Union[str, Any]				,		__A:     Dict				,		__A:     Tuple				,		__A:     List[str]				,		__A:     int				,		__A:     Optional[Any]				,		__A:     Optional[int]				,		):

												'''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  lowercase		(   self:     Union[str, Any]    ):

												'''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        _SCREAMING_SNAKE_CASE						(  __snake_case       , __snake_case       , unittest.TestCase							):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE    =(
							    (
							        TFFunnelModel,
							        TFFunnelForMaskedLM,
							        TFFunnelForPreTraining,
							        TFFunnelForQuestionAnswering,
							        TFFunnelForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							_SCREAMING_SNAKE_CASE    =(
							    {
							        '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    =False
							_SCREAMING_SNAKE_CASE    =False




							def  lowercase		(   self:     str    ):

												'''simple docstring'''

												a__          =  TFFunnelModelTester(self    )
												a__          =  ConfigTester(self				,		config_class=__A    )




							def  lowercase		(   self:     int    ):

												'''simple docstring'''

												self.config_tester.run_common_tests()




							def  lowercase		(   self:     Dict    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__A    )




							def  lowercase		(   self:     str    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_pretraining(*__A    )




							def  lowercase		(   self:     int    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_masked_lm(*__A    )




							def  lowercase		(   self:     int    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_token_classification(*__A    )





							def  lowercase		(   self:     Tuple    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_question_answering(*__A    )







@require_tf
class        _SCREAMING_SNAKE_CASE						(  __snake_case       , unittest.TestCase							):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE    =(
							    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
							)
							_SCREAMING_SNAKE_CASE    =False
							_SCREAMING_SNAKE_CASE    =False




							def  lowercase		(   self:     List[Any]    ):

												'''simple docstring'''

												a__          =  TFFunnelModelTester(self				,		base=__A    )
												a__          =  ConfigTester(self				,		config_class=__A    )




							def  lowercase		(   self:     int    ):

												'''simple docstring'''

												self.config_tester.run_common_tests()




							def  lowercase		(   self:     Any    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_base_model(*__A    )




							def  lowercase		(   self:     Optional[int]    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_sequence_classification(*__A    )





							def  lowercase		(   self:     Optional[Any]    ):

												'''simple docstring'''

												a__          =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_multiple_choice(*__A    )










"""simple docstring"""







__a       :	List[Any]             = frozenset(
    [
        'prompt',
        'height',
        'width',
        'guidance_scale',
        'negative_prompt',
        'prompt_embeds',
        'negative_prompt_embeds',
        'cross_attention_kwargs',
    ]
)

__a       :	Union[str, Any]             = frozenset(['prompt', 'negative_prompt'])

__a       :	Any             = frozenset([])

__a       :	Union[str, Any]             = frozenset(['image'])

__a       :	Dict             = frozenset(
    [
        'image',
        'height',
        'width',
        'guidance_scale',
    ]
)

__a       :	Dict             = frozenset(['image'])

__a       :	Dict             = frozenset(
    [
        'prompt',
        'image',
        'height',
        'width',
        'guidance_scale',
        'negative_prompt',
        'prompt_embeds',
        'negative_prompt_embeds',
    ]
)

__a       :	Optional[Any]             = frozenset(['prompt', 'image', 'negative_prompt'])

__a       :	List[Any]             = frozenset(
    [
        # Text guided image variation with an image mask
        'prompt',
        'image',
        'mask_image',
        'height',
        'width',
        'guidance_scale',
        'negative_prompt',
        'prompt_embeds',
        'negative_prompt_embeds',
    ]
)

__a       :	Union[str, Any]             = frozenset(['prompt', 'image', 'mask_image', 'negative_prompt'])

__a       :	Optional[Any]             = frozenset(
    [
        # image variation with an image mask
        'image',
        'mask_image',
        'height',
        'width',
        'guidance_scale',
    ]
)

__a       :	int             = frozenset(['image', 'mask_image'])

__a       :	Tuple             = frozenset(
    [
        'example_image',
        'image',
        'mask_image',
        'height',
        'width',
        'guidance_scale',
    ]
)

__a       :	Optional[Any]             = frozenset(['example_image', 'image', 'mask_image'])

__a       :	Optional[Any]             = frozenset(['class_labels'])

__a       :	Tuple             = frozenset(['class_labels'])

__a       :	int             = frozenset(['batch_size'])

__a       :	int             = frozenset([])

__a       :	Union[str, Any]             = frozenset(['batch_size'])

__a       :	Tuple             = frozenset([])

__a       :	Dict             = frozenset(
    [
        'prompt',
        'audio_length_in_s',
        'guidance_scale',
        'negative_prompt',
        'prompt_embeds',
        'negative_prompt_embeds',
        'cross_attention_kwargs',
    ]
)

__a       :	Dict             = frozenset(['prompt', 'negative_prompt'])
__a       :	Optional[int]             = frozenset(['input_tokens'])

__a       :	str             = frozenset(['input_tokens'])


