





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

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


					"""simple docstring"""

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

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

		def 	lowercase__     (   self					:   Optional[int]			)					->    Tuple:


					"""simple docstring"""

					__snake_case					:      Tuple							      =     ids_tensor([self.batch_size, self.seq_length]  ,      self.vocab_size			)

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

					__snake_case					:      Optional[int]							      =     None
					if self.use_token_type_ids:
								__snake_case					:      Optional[Any]							      =     ids_tensor([self.batch_size, self.seq_length]  ,      self.type_vocab_size			)

					__snake_case					:      Union[str, Any]							      =     None
					__snake_case					:      Optional[int]							      =     None
					__snake_case					:      Tuple							      =     None
					if self.use_labels:
								__snake_case					:      int							      =     ids_tensor([self.batch_size]  ,      self.type_sequence_label_size			)
								__snake_case					:      Optional[int]							      =     ids_tensor([self.batch_size, self.seq_length]  ,      self.num_labels			)
								__snake_case					:      int							      =     ids_tensor([self.batch_size]  ,      self.num_choices			)

					__snake_case					:      List[Any]							      =     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					:   Any  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   Any  ,      __magic_name__					:   Any  ,      __magic_name__					:   str  ,      __magic_name__					:   Dict  ,      __magic_name__					:   str  ,      __magic_name__					:   List[Any]  ,      )					->    Optional[Any]:


					"""simple docstring"""

					__snake_case					:      Dict							      =     TFFunnelModel(config=__magic_name__			)
					__snake_case					:      List[Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					__snake_case					:      Optional[Any]							      =     model(__magic_name__			)

					__snake_case					:      Tuple							      =     [input_ids, input_mask]
					__snake_case					:      Tuple							      =     model(__magic_name__			)

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

					__snake_case					:      str							      =     False
					__snake_case					:      Dict							      =     TFFunnelModel(config=__magic_name__			)
					__snake_case					:      str							      =     model(__magic_name__			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,      (self.batch_size, self.seq_length, self.d_model)			)

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

		def 	lowercase__     (   self					:   Any  ,      __magic_name__					:   Dict  ,      __magic_name__					:   Dict  ,      __magic_name__					:   Union[str, Any]  ,      __magic_name__					:   Any  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   Dict  ,      )					->    List[Any]:


					"""simple docstring"""

					__snake_case					:      str							      =     TFFunnelBaseModel(config=__magic_name__			)
					__snake_case					:      Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					__snake_case					:      Any							      =     model(__magic_name__			)

					__snake_case					:      List[Any]							      =     [input_ids, input_mask]
					__snake_case					:      Dict							      =     model(__magic_name__			)

					__snake_case					:      Optional[int]							      =     model(__magic_name__			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,      (self.batch_size, 2, self.d_model)			)

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

					__snake_case					:      Tuple							      =     False
					__snake_case					:      Optional[int]							      =     TFFunnelBaseModel(config=__magic_name__			)
					__snake_case					:      Dict							      =     model(__magic_name__			)
					self.parent.assertEqual(result.last_hidden_state.shape  ,      (self.batch_size, 2, self.d_model)			)

		def 	lowercase__     (   self					:   int  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   Any  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   Optional[int]  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   str  ,      __magic_name__					:   List[Any]  ,      )					->    Optional[Any]:


					"""simple docstring"""

					__snake_case					:      str							      =     TFFunnelForPreTraining(config=__magic_name__			)
					__snake_case					:      int							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					__snake_case					:      Tuple							      =     model(__magic_name__			)
					self.parent.assertEqual(result.logits.shape  ,      (self.batch_size, self.seq_length)			)

		def 	lowercase__     (   self					:   int  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   Any  ,      __magic_name__					:   int  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   Union[str, Any]  ,      __magic_name__					:   List[Any]  ,      )					->    Dict:


					"""simple docstring"""

					__snake_case					:      Optional[Any]							      =     TFFunnelForMaskedLM(config=__magic_name__			)
					__snake_case					:      Any							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					__snake_case					:      str							      =     model(__magic_name__			)
					self.parent.assertEqual(result.logits.shape  ,      (self.batch_size, self.seq_length, self.vocab_size)			)

		def 	lowercase__     (   self					:   List[str]  ,      __magic_name__					:   int  ,      __magic_name__					:   Optional[int]  ,      __magic_name__					:   Union[str, Any]  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   Optional[Any]  ,      __magic_name__					:   Tuple  ,      )					->    Dict:


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     self.num_labels
					__snake_case					:      str							      =     TFFunnelForSequenceClassification(config=__magic_name__			)
					__snake_case					:      Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					__snake_case					:      Union[str, Any]							      =     model(__magic_name__			)
					self.parent.assertEqual(result.logits.shape  ,      (self.batch_size, self.num_labels)			)

		def 	lowercase__     (   self					:   Optional[int]  ,      __magic_name__					:   Optional[int]  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   str  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   Optional[int]  ,      __magic_name__					:   Any  ,      __magic_name__					:   int  ,      )					->    List[Any]:


					"""simple docstring"""

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

		def 	lowercase__     (   self					:   Optional[int]  ,      __magic_name__					:   str  ,      __magic_name__					:   Optional[int]  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   str  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   Union[str, Any]  ,      __magic_name__					:   str  ,      )					->    Any:


					"""simple docstring"""

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

		def 	lowercase__     (   self					:   Union[str, Any]  ,      __magic_name__					:   List[Any]  ,      __magic_name__					:   int  ,      __magic_name__					:   Dict  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   Tuple  ,      __magic_name__					:   Optional[Any]  ,      )					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      int							      =     TFFunnelForQuestionAnswering(config=__magic_name__			)
					__snake_case					:      Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
					__snake_case					:      Any							      =     model(__magic_name__			)
					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					:   List[str]			)					->    int:


					"""simple docstring"""

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





@require_tf
class  _A (					__lowercase						,					__lowercase						,					unittest.TestCase		):
		lowercase__:   int				     =   (
		    (
		        TFFunnelModel,
		        TFFunnelForMaskedLM,
		        TFFunnelForPreTraining,
		        TFFunnelForQuestionAnswering,
		        TFFunnelForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		lowercase__:   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 {}
		)
		lowercase__:   List[Any]				     =   False
		lowercase__:   str				     =   False

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    Any:


					"""simple docstring"""

					__snake_case					:      Dict							      =     TFFunnelModelTester(self			)
					__snake_case					:      Tuple							      =     ConfigTester(self  ,      config_class=__magic_name__			)

		def 	lowercase__     (   self					:   List[str]			)					->    List[str]:


					"""simple docstring"""

					self.config_tester.run_common_tests()

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


					"""simple docstring"""

					__snake_case					:      int							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__magic_name__			)

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    List[str]:


					"""simple docstring"""

					__snake_case					:      Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*__magic_name__			)

		def 	lowercase__     (   self					:   Any			)					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*__magic_name__			)

		def 	lowercase__     (   self					:   List[Any]			)					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__magic_name__			)

		def 	lowercase__     (   self					:   Optional[int]			)					->    List[Any]:


					"""simple docstring"""

					__snake_case					:      Any							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__magic_name__			)





@require_tf
class  _A (					__lowercase						,					unittest.TestCase		):
		lowercase__:   Dict				     =   (
		    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
		)
		lowercase__:   List[str]				     =   False
		lowercase__:   List[str]				     =   False

		def 	lowercase__     (   self					:   Tuple			)					->    Dict:


					"""simple docstring"""

					__snake_case					:      Any							      =     TFFunnelModelTester(self  ,      base=__magic_name__			)
					__snake_case					:      List[Any]							      =     ConfigTester(self  ,      config_class=__magic_name__			)

		def 	lowercase__     (   self					:   str			)					->    List[str]:


					"""simple docstring"""

					self.config_tester.run_common_tests()

		def 	lowercase__     (   self					:   int			)					->    Tuple:


					"""simple docstring"""

					__snake_case					:      Dict							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_base_model(*__magic_name__			)

		def 	lowercase__     (   self					:   Optional[int]			)					->    Tuple:


					"""simple docstring"""

					__snake_case					:      int							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*__magic_name__			)

		def 	lowercase__     (   self					:   Optional[int]			)					->    Optional[Any]:


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*__magic_name__			)








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


__magic_name__  :  Optional[int]					=       {
    """configuration_biogpt""": ["""BIOGPT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """BioGptConfig"""],
    """tokenization_biogpt""": ["""BioGptTokenizer"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  int					=       [
          """BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """BioGptForCausalLM""",
          """BioGptForTokenClassification""",
          """BioGptForSequenceClassification""",
          """BioGptModel""",
          """BioGptPreTrainedModel""",
      ]


if TYPE_CHECKING:
      from .configuration_biogpt import BIOGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, BioGptConfig
      from .tokenization_biogpt import BioGptTokenizer

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_biogpt import (
                BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
                BioGptForCausalLM,
                BioGptForSequenceClassification,
                BioGptForTokenClassification,
                BioGptModel,
                BioGptPreTrainedModel,
            )


else:
      import sys

      __magic_name__  :  int					=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

