"""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							:							Tuple      ,    _A							:							Union[str, Any]      ,    _A							:							Optional[int]=1_3      ,    _A							:							Dict=7      ,    _A							:							str=True      ,    _A							:							str=True      ,    _A							:							Optional[int]=True      ,    _A							:							Any=True      ,    _A							:							Dict=9_9      ,    _A							:							str=[1, 1, 2]      ,    _A							:							List[Any]=1      ,    _A							:							List[Any]=3_2      ,    _A							:							Optional[int]=4      ,    _A							:							str=8      ,    _A							:							Any=3_7      ,    _A							:							Union[str, Any]="gelu_new"      ,    _A							:							List[Any]=0.1      ,    _A							:							Optional[int]=0.1      ,    _A							:							Dict=0.0      ,    _A							:							List[Any]=5_1_2      ,    _A							:							Optional[int]=3      ,    _A							:							Dict=0.02      ,    _A							:							List[str]=3      ,    _A							:							List[str]=4      ,    _A							:							Any=None      ,    _A							:							Optional[int]=False      ,    ):



											"""simple docstring"""







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

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





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						int			  =    ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size)

											_SCREAMING_SNAKE_CASE		:						str			  =    None
											if self.use_input_mask:
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    random_attention_mask([self.batch_size, self.seq_length])

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

											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    None
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    None
											_SCREAMING_SNAKE_CASE		:						int			  =    None
											if self.use_labels:
																		_SCREAMING_SNAKE_CASE		:						Any			  =    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		:						Union[str, Any]			  =    ids_tensor([self.batch_size]      ,    self.num_choices)

											_SCREAMING_SNAKE_CASE		:						Tuple			  =    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							:							Tuple      ,    _A							:							int      ,    _A							:							str      ,    _A							:							int      ,    _A							:							str      ,    _A							:							List[str]      ,    _A							:							Union[str, Any]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    TFFunnelModel(config=lowercase_)
											_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(lowercase_)

											_SCREAMING_SNAKE_CASE		:						Dict			  =    [input_ids, input_mask]
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(lowercase_)

											_SCREAMING_SNAKE_CASE		:						List[str]			  =    model(lowercase_)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.d_model))

											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    False
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    TFFunnelModel(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						str			  =    model(lowercase_)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.d_model))

											_SCREAMING_SNAKE_CASE		:						str			  =    False
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    TFFunnelModel(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						Dict			  =    model(lowercase_)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.d_model))





				def 		_lowerCAmelCase		(      self							:							str      ,    _A							:							Any      ,    _A							:							Dict      ,    _A							:							int      ,    _A							:							Any      ,    _A							:							Tuple      ,    _A							:							List[str]      ,    _A							:							str      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    TFFunnelBaseModel(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(lowercase_)

											_SCREAMING_SNAKE_CASE		:						str			  =    [input_ids, input_mask]
											_SCREAMING_SNAKE_CASE		:						int			  =    model(lowercase_)

											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    model(lowercase_)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, 2, self.d_model))

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

											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    False
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    TFFunnelBaseModel(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(lowercase_)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, 2, self.d_model))





				def 		_lowerCAmelCase		(      self							:							Dict      ,    _A							:							Dict      ,    _A							:							str      ,    _A							:							str      ,    _A							:							Tuple      ,    _A							:							Optional[int]      ,    _A							:							str      ,    _A							:							Optional[Any]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    TFFunnelForPreTraining(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    model(lowercase_)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length))





				def 		_lowerCAmelCase		(      self							:							int      ,    _A							:							int      ,    _A							:							List[Any]      ,    _A							:							Optional[Any]      ,    _A							:							Dict      ,    _A							:							Optional[Any]      ,    _A							:							List[Any]      ,    _A							:							Union[str, Any]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Dict			  =    TFFunnelForMaskedLM(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						int			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(lowercase_)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size))





				def 		_lowerCAmelCase		(      self							:							Any      ,    _A							:							List[str]      ,    _A							:							Optional[int]      ,    _A							:							str      ,    _A							:							int      ,    _A							:							str      ,    _A							:							Dict      ,    _A							:							Union[str, Any]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    self.num_labels
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    TFFunnelForSequenceClassification(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						str			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    model(lowercase_)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels))





				def 		_lowerCAmelCase		(      self							:							Optional[int]      ,    _A							:							List[str]      ,    _A							:							List[str]      ,    _A							:							Any      ,    _A							:							int      ,    _A							:							Any      ,    _A							:							Tuple      ,    _A							:							List[str]      ,    ):



											"""simple docstring"""







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





				def 		_lowerCAmelCase		(      self							:							Dict      ,    _A							:							List[Any]      ,    _A							:							str      ,    _A							:							Union[str, Any]      ,    _A							:							Union[str, Any]      ,    _A							:							List[str]      ,    _A							:							Union[str, Any]      ,    _A							:							Optional[int]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.num_labels
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    TFFunnelForTokenClassification(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
											_SCREAMING_SNAKE_CASE		:						Any			  =    model(lowercase_)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.num_labels))





				def 		_lowerCAmelCase		(      self							:							str      ,    _A							:							int      ,    _A							:							Optional[Any]      ,    _A							:							str      ,    _A							:							Optional[Any]      ,    _A							:							Union[str, Any]      ,    _A							:							List[str]      ,    _A							:							Optional[Any]      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    TFFunnelForQuestionAnswering(config=lowercase_)
											_SCREAMING_SNAKE_CASE		:						Dict			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
											_SCREAMING_SNAKE_CASE		:						Dict			  =    model(lowercase_)
											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):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    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	
											)  ,					
											)		:						Tuple			  =    config_and_inputs
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
											return config, inputs_dict




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







				"""simple docstring"""






				a			=						(
				    (
				        TFFunnelModel,
				        TFFunnelForMaskedLM,
				        TFFunnelForPreTraining,
				        TFFunnelForQuestionAnswering,
				        TFFunnelForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				a			=						(
				    {
				        "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
				        "fill-mask": TFFunnelForMaskedLM,
				        "question-answering": TFFunnelForQuestionAnswering,
				        "text-classification": TFFunnelForSequenceClassification,
				        "token-classification": TFFunnelForTokenClassification,
				        "zero-shot": TFFunnelForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				a			=						False
				a			=						False





				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						int			  =    TFFunnelModelTester(self)
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    ConfigTester(self      ,    config_class=lowercase_)





				def 		_lowerCAmelCase		(      self							:							Any):



											"""simple docstring"""







											self.config_tester.run_common_tests()





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*lowercase_)





				def 		_lowerCAmelCase		(      self							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						int			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_pretraining(*lowercase_)





				def 		_lowerCAmelCase		(      self							:							List[str]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*lowercase_)





				def 		_lowerCAmelCase		(      self							:							List[str]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*lowercase_)





				def 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*lowercase_)




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







				"""simple docstring"""






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





				def 		_lowerCAmelCase		(      self							:							Optional[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Tuple			  =    TFFunnelModelTester(self      ,    base=lowercase_)
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    ConfigTester(self      ,    config_class=lowercase_)





				def 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







											self.config_tester.run_common_tests()





				def 		_lowerCAmelCase		(      self							:							Dict):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_base_model(*lowercase_)





				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Tuple			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*lowercase_)





				def 		_lowerCAmelCase		(      self							:							Any):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*lowercase_)



"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase_     =	{
    '''configuration_clipseg''': [
        '''CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPSegConfig''',
        '''CLIPSegTextConfig''',
        '''CLIPSegVisionConfig''',
    ],
    '''processing_clipseg''': ['''CLIPSegProcessor'''],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowerCAmelCase_     =	[
			    '''CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''CLIPSegModel''',
			    '''CLIPSegPreTrainedModel''',
			    '''CLIPSegTextModel''',
			    '''CLIPSegVisionModel''',
			    '''CLIPSegForImageSegmentation''',
			]

if TYPE_CHECKING:
			from .configuration_clipseg import (
			    CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
			    CLIPSegConfig,
			    CLIPSegTextConfig,
			    CLIPSegVisionConfig,
			)
			from .processing_clipseg import CLIPSegProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_clipseg import (
						    CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CLIPSegForImageSegmentation,
						    CLIPSegModel,
						    CLIPSegPreTrainedModel,
						    CLIPSegTextModel,
						    CLIPSegVisionModel,
						)

else:
			import sys

			lowerCAmelCase_     =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


