


"""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						,	UpperCamelCase__						,	UpperCamelCase__=13						,	UpperCamelCase__=7						,	UpperCamelCase__=True						,	UpperCamelCase__=True						,	UpperCamelCase__=True						,	UpperCamelCase__=True						,	UpperCamelCase__=99						,	UpperCamelCase__=[1, 1, 2]						,	UpperCamelCase__=1						,	UpperCamelCase__=32						,	UpperCamelCase__=4						,	UpperCamelCase__=8						,	UpperCamelCase__=37						,	UpperCamelCase__="gelu_new"						,	UpperCamelCase__=0.1						,	UpperCamelCase__=0.1						,	UpperCamelCase__=0.0						,	UpperCamelCase__=512						,	UpperCamelCase__=3						,	UpperCamelCase__=0.02						,	UpperCamelCase__=3						,	UpperCamelCase__=4						,	UpperCamelCase__=None						,	UpperCamelCase__=False						,	)	->		Optional[Any]:

       '''simple docstring'''




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

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







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      Dict      					=    ids_tensor([self.batch_size, self.seq_length]						,	self.vocab_size						)

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

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

       snake_case    :      List[Any]      					=    None
       snake_case    :      Any      					=    None
       snake_case    :      int      					=    None
       if self.use_labels:
           snake_case    :      int      					=    ids_tensor([self.batch_size]						,	self.type_sequence_label_size						)
           snake_case    :      int      					=    ids_tensor([self.batch_size, self.seq_length]						,	self.num_labels						)
           snake_case    :      Optional[int]      					=    ids_tensor([self.batch_size]						,	self.num_choices						)

       snake_case    :      Union[str, 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  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	)	->		List[Any]:

       '''simple docstring'''




       snake_case    :      Any      					=    TFFunnelModel(config=UpperCamelCase__						)
       snake_case    :      Any      					=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       snake_case    :      Optional[Any]      					=    model(UpperCamelCase__						)

       snake_case    :      Tuple      					=    [input_ids, input_mask]
       snake_case    :      Dict      					=    model(UpperCamelCase__						)

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

       snake_case    :      Any      					=    False
       snake_case    :      Any      					=    TFFunnelModel(config=UpperCamelCase__						)
       snake_case    :      str      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.last_hidden_state.shape						,	(self.batch_size, self.seq_length, self.d_model)						)

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







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	)	->		Dict:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    TFFunnelBaseModel(config=UpperCamelCase__						)
       snake_case    :      int      					=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       snake_case    :      Tuple      					=    model(UpperCamelCase__						)

       snake_case    :      List[str]      					=    [input_ids, input_mask]
       snake_case    :      Optional[int]      					=    model(UpperCamelCase__						)

       snake_case    :      Optional[Any]      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.last_hidden_state.shape						,	(self.batch_size, 2, self.d_model)						)

       snake_case    :      Any      					=    False
       snake_case    :      int      					=    TFFunnelBaseModel(config=UpperCamelCase__						)
       snake_case    :      List[Any]      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.last_hidden_state.shape						,	(self.batch_size, 3, self.d_model)						)

       snake_case    :      List[Any]      					=    False
       snake_case    :      List[str]      					=    TFFunnelBaseModel(config=UpperCamelCase__						)
       snake_case    :      List[Any]      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.last_hidden_state.shape						,	(self.batch_size, 2, self.d_model)						)







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	)	->		List[str]:

       '''simple docstring'''




       snake_case    :      Tuple      					=    TFFunnelForPreTraining(config=UpperCamelCase__						)
       snake_case    :      Dict      					=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       snake_case    :      Any      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length)						)







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

       '''simple docstring'''




       snake_case    :      Dict      					=    TFFunnelForMaskedLM(config=UpperCamelCase__						)
       snake_case    :      Tuple      					=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       snake_case    :      Optional[int]      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length, self.vocab_size)						)







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	)	->		Any:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    self.num_labels
       snake_case    :      int      					=    TFFunnelForSequenceClassification(config=UpperCamelCase__						)
       snake_case    :      Optional[Any]      					=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       snake_case    :      Dict      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_labels)						)







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	)	->		Dict:

       '''simple docstring'''




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







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						,	)	->		int:

       '''simple docstring'''




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







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

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    TFFunnelForQuestionAnswering(config=UpperCamelCase__						)
       snake_case    :      Tuple      					=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       snake_case    :      List[str]      					=    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  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      Dict      					=    self.prepare_config_and_inputs()
       (
           (
           snake_case
       )					,(
           snake_case
       )					,(
           snake_case
       )					,(
           snake_case
       )					,(
           snake_case
       )					,(
           snake_case
       )					,(
           snake_case
       )					,
       )    :      Union[str, Any]      					=    config_and_inputs
       snake_case    :      int      					=    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
       return config, inputs_dict







@require_tf
class _lowerCAmelCase				(      snake_case_    ,							snake_case_    ,							unittest.TestCase	):
   __UpperCAmelCase :       List[str]							  =  (
       (
           TFFunnelModel,
           TFFunnelForMaskedLM,
           TFFunnelForPreTraining,
           TFFunnelForQuestionAnswering,
           TFFunnelForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   __UpperCAmelCase :       Union[str, 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 :       int							  =  False
   __UpperCAmelCase :       Optional[Any]							  =  False







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    TFFunnelModelTester(self						)
       snake_case    :      Optional[Any]      					=    ConfigTester(self						,	config_class=UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       self.config_tester.run_common_tests()







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      Dict      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCamelCase__						)







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

       '''simple docstring'''




       snake_case    :      int      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		Dict:

       '''simple docstring'''




       snake_case    :      Dict      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		Dict:

       '''simple docstring'''




       snake_case    :      Optional[int]      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__						)







@require_tf
class _lowerCAmelCase				(      snake_case_    ,							unittest.TestCase	):
   __UpperCAmelCase :       List[str]							  =  (
       (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
   )
   __UpperCAmelCase :       Union[str, Any]							  =  False
   __UpperCAmelCase :       Any							  =  False







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    TFFunnelModelTester(self						,	base=UpperCamelCase__						)
       snake_case    :      List[Any]      					=    ConfigTester(self						,	config_class=UpperCamelCase__						)







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

       '''simple docstring'''




       self.config_tester.run_common_tests()







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

       '''simple docstring'''




       snake_case    :      List[Any]      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_base_model(*UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__						)







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

       '''simple docstring'''




       snake_case    :      List[str]      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__						)









"""simple docstring"""



def   __lowerCAmelCase						(						lowercase  :  list )	->						int:


    """simple docstring"""





    if not grid or not grid[0]:
        raise TypeError("The grid does not contain the appropriate information" )

    for cell_n in range(1						,							len(grid[0] ) ):
        grid[0][cell_n] += grid[0][cell_n - 1]
    snake_case    :      int      					=    grid[0]

    for row_n in range(1						,							len(lowercase ) ):
        snake_case    :      Optional[Any]      					=    grid[row_n]
        snake_case    :      List[str]      					=    fill_row(lowercase						,							lowercase )
        snake_case    :      Optional[int]      					=    grid[row_n]

    return grid[-1][-1]







def   __lowerCAmelCase						(						lowercase  :  list						,							lowercase  :  list )	->						list:


    """simple docstring"""





    current_row[0] += row_above[0]
    for cell_n in range(1						,							len(lowercase ) ):
        current_row[cell_n] += min(current_row[cell_n - 1]						,							row_above[cell_n] )

    return current_row


if __name__ == "__main__":
  import doctest

  doctest.testmod()





