'''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 				a__:


			'''simple docstring'''






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




					"""simple docstring"""


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

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



			def 							a_       (   self):




					"""simple docstring"""


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

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

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

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

					lowerCAmelCase   					=  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 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  TFFunnelModel(config=__lowerCAmelCase)
					lowerCAmelCase   					=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					lowerCAmelCase   					=  model(__lowerCAmelCase)

					lowerCAmelCase   					=  [input_ids, input_mask]
					lowerCAmelCase   					=  model(__lowerCAmelCase)

					lowerCAmelCase   					=  model(__lowerCAmelCase)
					self.parent.assertEqual(result.last_hidden_state.shape       ,    (self.batch_size, self.seq_length, self.d_model))

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

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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  TFFunnelBaseModel(config=__lowerCAmelCase)
					lowerCAmelCase   					=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					lowerCAmelCase   					=  model(__lowerCAmelCase)

					lowerCAmelCase   					=  [input_ids, input_mask]
					lowerCAmelCase   					=  model(__lowerCAmelCase)

					lowerCAmelCase   					=  model(__lowerCAmelCase)
					self.parent.assertEqual(result.last_hidden_state.shape       ,    (self.batch_size, 2, self.d_model))

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

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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  TFFunnelForPreTraining(config=__lowerCAmelCase)
					lowerCAmelCase   					=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					lowerCAmelCase   					=  model(__lowerCAmelCase)
					self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.seq_length))



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  self.num_labels
					lowerCAmelCase   					=  TFFunnelForSequenceClassification(config=__lowerCAmelCase)
					lowerCAmelCase   					=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					lowerCAmelCase   					=  model(__lowerCAmelCase)
					self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.num_labels))



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  TFFunnelForQuestionAnswering(config=__lowerCAmelCase)
					lowerCAmelCase   					=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					lowerCAmelCase   					=  model(__lowerCAmelCase)
					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 							a_       (   self):




					"""simple docstring"""


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







@require_tf
class 				a__(					lowerCAmelCase__ ,						lowerCAmelCase__ ,						unittest.TestCase	):


			'''simple docstring'''






			UpperCAmelCase_			:     Union[str, Any]      =       (
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			UpperCAmelCase_			:     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 {}
			)
			UpperCAmelCase_			:     List[Any]      =       False
			UpperCAmelCase_			:     Union[str, Any]      =       False



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  TFFunnelModelTester(self)
					lowerCAmelCase   					=  ConfigTester(self       ,    config_class=__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					self.config_tester.run_common_tests()



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase)







			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase)







@require_tf
class 				a__(					lowerCAmelCase__ ,						unittest.TestCase	):


			'''simple docstring'''






			UpperCAmelCase_			:     str      =       (
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			UpperCAmelCase_			:     Union[str, Any]      =       False
			UpperCAmelCase_			:     int      =       False



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  TFFunnelModelTester(self       ,    base=__lowerCAmelCase)
					lowerCAmelCase   					=  ConfigTester(self       ,    config_class=__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					self.config_tester.run_common_tests()



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_base_model(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase)







			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*__lowerCAmelCase)





'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowercase          =  {
    '''configuration_instructblip''': [
        '''INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''InstructBlipConfig''',
        '''InstructBlipQFormerConfig''',
        '''InstructBlipVisionConfig''',
    ],
    '''processing_instructblip''': ['''InstructBlipProcessor'''],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__lowercase          =  [
						    '''INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''InstructBlipQFormerModel''',
						    '''InstructBlipPreTrainedModel''',
						    '''InstructBlipForConditionalGeneration''',
						    '''InstructBlipVisionModel''',
						]

if TYPE_CHECKING:
						from .configuration_instructblip import (
						    INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    InstructBlipConfig,
						    InstructBlipQFormerConfig,
						    InstructBlipVisionConfig,
						)
						from .processing_instructblip import InstructBlipProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_instructblip import (
												    INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
												    InstructBlipForConditionalGeneration,
												    InstructBlipPreTrainedModel,
												    InstructBlipQFormerModel,
												    InstructBlipVisionModel,
												)

else:
						import sys

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




