






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

			def __init__(					self ,				snake_case_ ,				snake_case_=13 ,				snake_case_=7 ,				snake_case_=True ,				snake_case_=True ,				snake_case_=True ,				snake_case_=True ,				snake_case_=99 ,				snake_case_=[1, 1, 2] ,				snake_case_=1 ,				snake_case_=32 ,				snake_case_=4 ,				snake_case_=8 ,				snake_case_=37 ,				snake_case_="gelu_new" ,				snake_case_=0.1 ,				snake_case_=0.1 ,				snake_case_=0.0 ,				snake_case_=512 ,				snake_case_=3 ,				snake_case_=0.02 ,				snake_case_=3 ,				snake_case_=4 ,				snake_case_=None ,				snake_case_=False ,				)		->       Optional[int]:
							UpperCamelCase__         =    parent
							UpperCamelCase__         =    batch_size
							UpperCamelCase__         =    seq_length
							UpperCamelCase__         =    is_training
							UpperCamelCase__         =    use_input_mask
							UpperCamelCase__         =    use_token_type_ids
							UpperCamelCase__         =    use_labels
							UpperCamelCase__         =    vocab_size
							UpperCamelCase__         =    block_sizes
							UpperCamelCase__         =    num_decoder_layers
							UpperCamelCase__         =    d_model
							UpperCamelCase__         =    n_head
							UpperCamelCase__         =    d_head
							UpperCamelCase__         =    d_inner
							UpperCamelCase__         =    hidden_act
							UpperCamelCase__         =    hidden_dropout
							UpperCamelCase__         =    attention_dropout
							UpperCamelCase__         =    activation_dropout
							UpperCamelCase__         =    max_position_embeddings
							UpperCamelCase__         =    type_vocab_size
							UpperCamelCase__         =    2
							UpperCamelCase__         =    num_labels
							UpperCamelCase__         =    num_choices
							UpperCamelCase__         =    scope
							UpperCamelCase__         =    initializer_std

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

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
							UpperCamelCase__         =    ids_tensor([self.batch_size, self.seq_length] ,				self.vocab_size      )

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

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

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

							UpperCamelCase__         =    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 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Optional[int]:
							UpperCamelCase__         =    TFFunnelModel(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )

							UpperCamelCase__         =    [input_ids, input_mask]
							UpperCamelCase__         =    model(snake_case_      )

							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, self.seq_length, self.d_model)      )

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

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

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Any:
							UpperCamelCase__         =    TFFunnelBaseModel(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )

							UpperCamelCase__         =    [input_ids, input_mask]
							UpperCamelCase__         =    model(snake_case_      )

							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, 2, self.d_model)      )

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

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

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Union[str, Any]:
							UpperCamelCase__         =    TFFunnelForPreTraining(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length)      )

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Union[str, Any]:
							UpperCamelCase__         =    TFFunnelForMaskedLM(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.vocab_size)      )

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Optional[Any]:
							UpperCamelCase__         =    self.num_labels
							UpperCamelCase__         =    TFFunnelForSequenceClassification(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_labels)      )

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Optional[int]:
							UpperCamelCase__         =    self.num_choices
							UpperCamelCase__         =    TFFunnelForMultipleChoice(config=snake_case_      )
							UpperCamelCase__         =    tf.tile(tf.expand_dims(snake_case_ ,				1      ) ,				(1, self.num_choices, 1)      )
							UpperCamelCase__         =    tf.tile(tf.expand_dims(snake_case_ ,				1      ) ,				(1, self.num_choices, 1)      )
							UpperCamelCase__         =    tf.tile(tf.expand_dims(snake_case_ ,				1      ) ,				(1, self.num_choices, 1)      )
							UpperCamelCase__         =    {
							    'input_ids': multiple_choice_inputs_ids,
							    'attention_mask': multiple_choice_input_mask,
							    'token_type_ids': multiple_choice_token_type_ids,
							}
							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_choices)      )

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       List[Any]:
							UpperCamelCase__         =    self.num_labels
							UpperCamelCase__         =    TFFunnelForTokenClassification(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.num_labels)      )

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				)		->       Union[str, Any]:
							UpperCamelCase__         =    TFFunnelForQuestionAnswering(config=snake_case_      )
							UpperCamelCase__         =    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							UpperCamelCase__         =    model(snake_case_      )
							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 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[str]:
							UpperCamelCase__         =    self.prepare_config_and_inputs()
							(
							    (
							    UpperCamelCase__						
							)       ,						(
							    UpperCamelCase__						
							)       ,						(
							    UpperCamelCase__						
							)       ,						(
							    UpperCamelCase__						
							)       ,						(
							    UpperCamelCase__						
							)       ,						(
							    UpperCamelCase__						
							)       ,						(
							    UpperCamelCase__						
							)       ,												
							)         =    config_and_inputs
							UpperCamelCase__         =    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_tf
class    __lowerCamelCase    (  _a							,	_a							,	unittest.TestCase  ):
			a      :				str 						=(
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			a      :				Tuple 						=(
			    {
			        """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      :				str 						=False
			a      :				Optional[Any] 						=False

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       int:
							UpperCamelCase__         =    TFFunnelModelTester(self      )
							UpperCamelCase__         =    ConfigTester(self ,				config_class=snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Dict:
							self.config_tester.run_common_tests()

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       int:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[Any]:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       int:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[Any]:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*snake_case_      )







			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[Any]:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*snake_case_      )







@require_tf
class    __lowerCamelCase    (  _a							,	unittest.TestCase  ):
			a      :				Optional[Any] 						=(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			a      :				Optional[int] 						=False
			a      :				Union[str, Any] 						=False

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Dict:
							UpperCamelCase__         =    TFFunnelModelTester(self ,				base=snake_case_      )
							UpperCamelCase__         =    ConfigTester(self ,				config_class=snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       int:
							self.config_tester.run_common_tests()

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[int]:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_base_model(*snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[int]:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*snake_case_      )







			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       str:
							UpperCamelCase__         =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*snake_case_      )












"""simple docstring"""





import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


A__					: Union[str, Any]=	logging.getLogger()
@unittest.skip("""Temporarily disable the doc tests."""  )
@require_torch
@require_tf
@slow
class    __lowerCamelCase    (  unittest.TestCase  ):

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ = None ,				snake_case_ = None ,				snake_case_ = None ,				snake_case_ = True ,				)		->       Tuple:
       UpperCamelCase__         =    [file for file in os.listdir(snake_case_      ) if os.path.isfile(os.path.join(snake_case_ ,				snake_case_      )      )]

       if identifier is not None:
           UpperCamelCase__         =    [file for file in files if identifier in file]

       if n_identifier is not None:
           if isinstance(snake_case_ ,				snake_case_      ):
               for n_ in n_identifier:
                   UpperCamelCase__         =    [file for file in files if n_ not in file]
           else:
               UpperCamelCase__         =    [file for file in files if n_identifier not in file]

       UpperCamelCase__         =    ignore_files or []
       ignore_files.append('__init__.py'      )
       UpperCamelCase__         =    [file for file in files if file not in ignore_files]

       for file in files:
           # Open all files
           print('Testing' ,				snake_case_      )

           if only_modules:
               UpperCamelCase__         =    file.split('.'      )[0]
               try:
                   UpperCamelCase__         =    getattr(snake_case_ ,				snake_case_      )
                   UpperCamelCase__         =    doctest.DocTestSuite(snake_case_      )
                   UpperCamelCase__         =    unittest.TextTestRunner().run(snake_case_      )
                   self.assertIs(len(result.failures      ) ,				0      )
               except AttributeError:
                   logger.info(F'{module_identifier} is not a module.'      )
           else:
               UpperCamelCase__         =    doctest.testfile(str('..' / directory / file      ) ,				optionflags=doctest.ELLIPSIS      )
               self.assertIs(result.failed ,				0      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    'modeling'
       UpperCamelCase__         =    [
           'modeling_ctrl.py',
           'modeling_tf_ctrl.py',
       ]
       self.analyze_directory(snake_case_ ,				identifier=snake_case_ ,				ignore_files=snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[int]:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    'tokenization'
       self.analyze_directory(snake_case_ ,				identifier=snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[Any]:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    'configuration'
       self.analyze_directory(snake_case_ ,				identifier=snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       str:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    ['configuration', 'modeling', 'tokenization']
       self.analyze_directory(snake_case_ ,				n_identifier=snake_case_      )







   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
       UpperCamelCase__         =    Path('docs/source'      )
       UpperCamelCase__         =    ['favicon.ico']
       self.analyze_directory(snake_case_ ,				ignore_files=snake_case_ ,				only_modules=snake_case_      )




