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



						'''simple docstring'''


						def __init__( self     :      Tuple  ,A_     :      Union[str, Any]  ,A_     :      Optional[int]=13  ,A_     :      Dict=7  ,A_     :      str=True  ,A_     :      str=True  ,A_     :      Optional[int]=True  ,A_     :      Any=True  ,A_     :      Dict=99  ,A_     :      str=[1, 1, 2]  ,A_     :      List[Any]=1  ,A_     :      List[Any]=32  ,A_     :      Optional[int]=4  ,A_     :      str=8  ,A_     :      Any=37  ,A_     :      Union[str, Any]="gelu_new"  ,A_     :      List[Any]=0.1  ,A_     :      Optional[int]=0.1  ,A_     :      Dict=0.0  ,A_     :      List[Any]=512  ,A_     :      Optional[int]=3  ,A_     :      Dict=0.02  ,A_     :      List[str]=3  ,A_     :      List[str]=4  ,A_     :      Any=None  ,A_     :      Optional[int]=False  ,)     ->   Any:
							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 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   str:
							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 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Tuple  ,A_     :      int  ,A_     :      str  ,A_     :      int  ,A_     :      str  ,A_     :      List[str]  ,A_     :      Union[str, Any]  ,)     ->   Tuple:
							A						   =   TFFunnelModel(config=lowercase_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							A						   =   model(lowercase_      )

							A						   =   [input_ids, input_mask]
							A						   =   model(lowercase_      )

							A						   =   model(lowercase_      )
							self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, self.seq_length, self.d_model)      )

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str  ,A_     :      Any  ,A_     :      Dict  ,A_     :      int  ,A_     :      Any  ,A_     :      Tuple  ,A_     :      List[str]  ,A_     :      str  ,)     ->   Tuple:
							A						   =   TFFunnelBaseModel(config=lowercase_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							A						   =   model(lowercase_      )

							A						   =   [input_ids, input_mask]
							A						   =   model(lowercase_      )

							A						   =   model(lowercase_      )
							self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, 2, self.d_model)      )

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict  ,A_     :      Dict  ,A_     :      str  ,A_     :      str  ,A_     :      Tuple  ,A_     :      Optional[int]  ,A_     :      str  ,A_     :      Optional[Any]  ,)     ->   Any:
							A						   =   TFFunnelForPreTraining(config=lowercase_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							A						   =   model(lowercase_      )
							self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length)      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int  ,A_     :      int  ,A_     :      List[Any]  ,A_     :      Optional[Any]  ,A_     :      Dict  ,A_     :      Optional[Any]  ,A_     :      List[Any]  ,A_     :      Union[str, Any]  ,)     ->   int:
							A						   =   TFFunnelForMaskedLM(config=lowercase_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							A						   =   model(lowercase_      )
							self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.vocab_size)      )


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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]  ,A_     :      List[str]  ,A_     :      List[str]  ,A_     :      Any  ,A_     :      int  ,A_     :      Any  ,A_     :      Tuple  ,A_     :      List[str]  ,)     ->   Optional[int]:
							A						   =   self.num_choices
							A						   =   TFFunnelForMultipleChoice(config=lowercase_      )
							A						   =   tf.tile(tf.expand_dims(lowercase_  ,1      )  ,(1, self.num_choices, 1)      )
							A						   =   tf.tile(tf.expand_dims(lowercase_  ,1      )  ,(1, self.num_choices, 1)      )
							A						   =   tf.tile(tf.expand_dims(lowercase_  ,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(lowercase_      )
							self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.num_choices)      )


						def 						_SCREAMING_SNAKE_CASE      ( 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]  ,)     ->   Optional[Any]:
							A						   =   self.num_labels
							A						   =   TFFunnelForTokenClassification(config=lowercase_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							A						   =   model(lowercase_      )
							self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.num_labels)      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str  ,A_     :      int  ,A_     :      Optional[Any]  ,A_     :      str  ,A_     :      Optional[Any]  ,A_     :      Union[str, Any]  ,A_     :      List[str]  ,A_     :      Optional[Any]  ,)     ->   Optional[int]:
							A						   =   TFFunnelForQuestionAnswering(config=lowercase_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
							A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   int:
							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 				lowerCAmelCase_				(      _lowercase		,					_lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    Optional[Any]      =    (
						    (
						        TFFunnelModel,
						        TFFunnelForMaskedLM,
						        TFFunnelForPreTraining,
						        TFFunnelForQuestionAnswering,
						        TFFunnelForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						_lowerCamelCase:    str      =    (
						    {
						        '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
						        '''fill-mask''': TFFunnelForMaskedLM,
						        '''question-answering''': TFFunnelForQuestionAnswering,
						        '''text-classification''': TFFunnelForSequenceClassification,
						        '''token-classification''': TFFunnelForTokenClassification,
						        '''zero-shot''': TFFunnelForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						_lowerCamelCase:    Union[str, Any]      =    False
						_lowerCamelCase:    List[Any]      =    False


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   Dict:
							A						   =   TFFunnelModelTester(self      )
							A						   =   ConfigTester(self  ,config_class=lowercase_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   Dict:
							self.config_tester.run_common_tests()


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Union[str, Any]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowercase_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Dict:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*lowercase_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   List[str]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowercase_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Optional[int]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowercase_      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   str:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowercase_      )







@require_tf
class 				lowerCAmelCase_				(      _lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    List[str]      =    (
						    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
						)
						_lowerCamelCase:    int      =    False
						_lowerCamelCase:    List[str]      =    False


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Any:
							A						   =   TFFunnelModelTester(self  ,base=lowercase_      )
							A						   =   ConfigTester(self  ,config_class=lowercase_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   List[Any]:
							self.config_tester.run_common_tests()


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   Dict:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_base_model(*lowercase_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   Tuple:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowercase_      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   Optional[Any]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*lowercase_      )

"""simple docstring"""


# this script reports modified .py files under the desired list of top-level sub-dirs passed as a list of arguments, e.g.:
#   python ./utils/get_modified_files.py utils src tests examples
#
# it uses git to find the forking point and which files were modified - i.e. files not under git won't be considered
# since the output of this script is fed into Makefile commands it doesn't print a newline after the results

import re
import subprocess
import sys


_lowercase							   =				subprocess.check_output('''git merge-base main HEAD'''.split()).decode('''utf-8''')
_lowercase							   =				subprocess.check_output(F"""git diff --name-only {fork_point_sha}""".split()).decode('''utf-8''').split()

_lowercase							   =				'''|'''.join(sys.argv[1:])
_lowercase							   =				re.compile(rF"""^({joined_dirs}).*?\.py$""")

_lowercase							   =				[x for x in modified_files if regex.match(x)]
print(''' '''.join(relevant_modified_files), end='''''')