




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

    '''simple docstring'''






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





           '''simple docstring'''

           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				:     int)						->str:





           '''simple docstring'''

           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				:     List[Any] ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     Tuple ,			UpperCAmelCase__				:     Optional[Any] ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     Dict ,			UpperCAmelCase__				:     List[str] ,			)						->int:





           '''simple docstring'''

           A__							=   TFFunnelModel(config=UpperCAmelCase__)
           A__							=   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__							=   model(UpperCAmelCase__)

           A__							=   [input_ids, input_mask]
           A__							=   model(UpperCAmelCase__)

           A__							=   model(UpperCAmelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape ,			(self.batch_size, self.seq_length, self.d_model))

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

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


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





           '''simple docstring'''

           A__							=   TFFunnelBaseModel(config=UpperCAmelCase__)
           A__							=   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__							=   model(UpperCAmelCase__)

           A__							=   [input_ids, input_mask]
           A__							=   model(UpperCAmelCase__)

           A__							=   model(UpperCAmelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape ,			(self.batch_size, 2, self.d_model))

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

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     Dict ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     str ,			UpperCAmelCase__				:     Dict ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     Tuple ,			UpperCAmelCase__				:     Optional[Any] ,			)						->Dict:





           '''simple docstring'''

           A__							=   TFFunnelForPreTraining(config=UpperCAmelCase__)
           A__							=   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__							=   model(UpperCAmelCase__)
           self.parent.assertEqual(result.logits.shape ,			(self.batch_size, self.seq_length))


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





           '''simple docstring'''

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     List[str] ,			UpperCAmelCase__				:     Tuple ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     Tuple ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     str ,			)						->int:





           '''simple docstring'''

           A__							=   self.num_labels
           A__							=   TFFunnelForSequenceClassification(config=UpperCAmelCase__)
           A__							=   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__							=   model(UpperCAmelCase__)
           self.parent.assertEqual(result.logits.shape ,			(self.batch_size, self.num_labels))


    def 	SCREAMING_SNAKE_CASE							(      self				:     Union[str, Any] ,			UpperCAmelCase__				:     str ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     Dict ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     str ,			UpperCAmelCase__				:     str ,			UpperCAmelCase__				:     int ,			)						->str:





           '''simple docstring'''

           A__							=   self.num_choices
           A__							=   TFFunnelForMultipleChoice(config=UpperCAmelCase__)
           A__							=   tf.tile(tf.expand_dims(UpperCAmelCase__ ,			1) ,			(1, self.num_choices, 1))
           A__							=   tf.tile(tf.expand_dims(UpperCAmelCase__ ,			1) ,			(1, self.num_choices, 1))
           A__							=   tf.tile(tf.expand_dims(UpperCAmelCase__ ,			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(UpperCAmelCase__)
           self.parent.assertEqual(result.logits.shape ,			(self.batch_size, self.num_choices))


    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any] ,			UpperCAmelCase__				:     Optional[Any] ,			UpperCAmelCase__				:     int ,			UpperCAmelCase__				:     Dict ,			UpperCAmelCase__				:     int ,			UpperCAmelCase__				:     int ,			UpperCAmelCase__				:     Union[str, Any] ,			UpperCAmelCase__				:     List[Any] ,			)						->str:





           '''simple docstring'''

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     str ,			UpperCAmelCase__				:     Optional[Any] ,			UpperCAmelCase__				:     Any ,			UpperCAmelCase__				:     List[str] ,			UpperCAmelCase__				:     Optional[int] ,			UpperCAmelCase__				:     Dict ,			UpperCAmelCase__				:     Tuple ,			UpperCAmelCase__				:     Tuple ,			)						->List[Any]:





           '''simple docstring'''

           A__							=   TFFunnelForQuestionAnswering(config=UpperCAmelCase__)
           A__							=   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__							=   model(UpperCAmelCase__)
           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				:     Any)						->Tuple:





           '''simple docstring'''

           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     UpperCamelCase_   (			UpperCAmelCase__		, UpperCAmelCase__		, unittest.TestCase					):

    '''simple docstring'''






    UpperCAmelCase__							  =				(
        (
            TFFunnelModel,
            TFFunnelForMaskedLM,
            TFFunnelForPreTraining,
            TFFunnelForQuestionAnswering,
            TFFunnelForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    UpperCAmelCase__							  =				(
        {
            '''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__							  =				False
    UpperCAmelCase__							  =				False


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





           '''simple docstring'''

           A__							=   TFFunnelModelTester(self)
           A__							=   ConfigTester(self ,			config_class=UpperCAmelCase__)


    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any])						->Optional[Any]:





           '''simple docstring'''

           self.config_tester.run_common_tests()


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





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*UpperCAmelCase__)


    def 	SCREAMING_SNAKE_CASE							(      self				:     List[str])						->Dict:





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase__)


    def 	SCREAMING_SNAKE_CASE							(      self				:     Tuple)						->int:





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase__)


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





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase__)





    def 	SCREAMING_SNAKE_CASE							(      self				:     List[Any])						->List[Any]:





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase__)


@require_tf
class     UpperCamelCase_   (			UpperCAmelCase__		, unittest.TestCase					):

    '''simple docstring'''






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


    def 	SCREAMING_SNAKE_CASE							(      self				:     int)						->Optional[int]:





           '''simple docstring'''

           A__							=   TFFunnelModelTester(self ,			base=UpperCAmelCase__)
           A__							=   ConfigTester(self ,			config_class=UpperCAmelCase__)


    def 	SCREAMING_SNAKE_CASE							(      self				:     List[str])						->Tuple:





           '''simple docstring'''

           self.config_tester.run_common_tests()


    def 	SCREAMING_SNAKE_CASE							(      self				:     int)						->int:





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_base_model(*UpperCAmelCase__)


    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any])						->Dict:





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase__)





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





           '''simple docstring'''

           A__							=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase__)








from __future__ import annotations

from typing import Any







def SCREAMING_SNAKE_CASE    (	lowercase_						)       ->	None:



       """simple docstring"""

       create_state_space_tree(lowercase_			,    []			,    0						)







def SCREAMING_SNAKE_CASE    (	lowercase_			,    lowercase_			,    lowercase_						)       ->	None:



       """simple docstring"""

       if index == len(lowercase_						):
              print(lowercase_						)
              return

       create_state_space_tree(lowercase_			,    lowercase_			,    index + 1						)
       current_subsequence.append(sequence[index]						)
       create_state_space_tree(lowercase_			,    lowercase_			,    index + 1						)
       current_subsequence.pop()


if __name__ == "__main__":
  _lowerCamelCase     :		list[Any]								=       [3, 1, 2, 4]
  generate_all_subsequences(seq)

  seq.clear()
  seq.extend(["""A""", """B""", """C"""])
  generate_all_subsequences(seq)


