


"""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   _UpperCamelCase  :
							'''simple docstring'''







							def __init__(     self    ,   __a    ,   __a=13    ,   __a=7    ,   __a=True    ,   __a=True    ,   __a=True    ,   __a=True    ,   __a=99    ,   __a=[1, 1, 2]    ,   __a=1    ,   __a=32    ,   __a=4    ,   __a=8    ,   __a=37    ,   __a="gelu_new"    ,   __a=0.1    ,   __a=0.1    ,   __a=0.0    ,   __a=5_12    ,   __a=3    ,   __a=0.0_2    ,   __a=3    ,   __a=4    ,   __a=None    ,   __a=False    ,   ):
										__lowerCAmelCase				    =			parent
										__lowerCAmelCase				    =			batch_size
										__lowerCAmelCase				    =			seq_length
										__lowerCAmelCase				    =			is_training
										__lowerCAmelCase				    =			use_input_mask
										__lowerCAmelCase				    =			use_token_type_ids
										__lowerCAmelCase				    =			use_labels
										__lowerCAmelCase				    =			vocab_size
										__lowerCAmelCase				    =			block_sizes
										__lowerCAmelCase				    =			num_decoder_layers
										__lowerCAmelCase				    =			d_model
										__lowerCAmelCase				    =			n_head
										__lowerCAmelCase				    =			d_head
										__lowerCAmelCase				    =			d_inner
										__lowerCAmelCase				    =			hidden_act
										__lowerCAmelCase				    =			hidden_dropout
										__lowerCAmelCase				    =			attention_dropout
										__lowerCAmelCase				    =			activation_dropout
										__lowerCAmelCase				    =			max_position_embeddings
										__lowerCAmelCase				    =			type_vocab_size
										__lowerCAmelCase				    =			2
										__lowerCAmelCase				    =			num_labels
										__lowerCAmelCase				    =			num_choices
										__lowerCAmelCase				    =			scope
										__lowerCAmelCase				    =			initializer_std

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

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

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

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

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

										__lowerCAmelCase				    =			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 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			TFFunnelModel(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)

										__lowerCAmelCase				    =			[input_ids, input_mask]
										__lowerCAmelCase				    =			model(__a	)

										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.d_model)	)

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

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

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			TFFunnelBaseModel(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)

										__lowerCAmelCase				    =			[input_ids, input_mask]
										__lowerCAmelCase				    =			model(__a	)

										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 2, self.d_model)	)

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

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

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			TFFunnelForPreTraining(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length)	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			TFFunnelForMaskedLM(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.vocab_size)	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			self.num_labels
										__lowerCAmelCase				    =			TFFunnelForSequenceClassification(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			self.num_choices
										__lowerCAmelCase				    =			TFFunnelForMultipleChoice(config=__a	)
										__lowerCAmelCase				    =			tf.tile(tf.expand_dims(__a    ,   1	)    ,   (1, self.num_choices, 1)	)
										__lowerCAmelCase				    =			tf.tile(tf.expand_dims(__a    ,   1	)    ,   (1, self.num_choices, 1)	)
										__lowerCAmelCase				    =			tf.tile(tf.expand_dims(__a    ,   1	)    ,   (1, self.num_choices, 1)	)
										__lowerCAmelCase				    =			{
										    "input_ids": multiple_choice_inputs_ids,
										    "attention_mask": multiple_choice_input_mask,
										    "token_type_ids": multiple_choice_token_type_ids,
										}
										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_choices)	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			self.num_labels
										__lowerCAmelCase				    =			TFFunnelForTokenClassification(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.num_labels)	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   __a    ,   ):
										__lowerCAmelCase				    =			TFFunnelForQuestionAnswering(config=__a	)
										__lowerCAmelCase				    =			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										__lowerCAmelCase				    =			model(__a	)
										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 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.prepare_config_and_inputs()
										(
										    (
										    __lowerCAmelCase
										)    ,	(
										    __lowerCAmelCase
										)    ,	(
										    __lowerCAmelCase
										)    ,	(
										    __lowerCAmelCase
										)    ,	(
										    __lowerCAmelCase
										)    ,	(
										    __lowerCAmelCase
										)    ,	(
										    __lowerCAmelCase
										)    ,	
										)				    =			config_and_inputs
										__lowerCAmelCase				    =			{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
										return config, inputs_dict
@require_tf
class   _UpperCamelCase  (   lowerCAmelCase__       ,lowerCAmelCase__       ,unittest.TestCase		):
							'''simple docstring'''







							__UpperCAmelCase						:    str				      =(
							    (
							        TFFunnelModel,
							        TFFunnelForMaskedLM,
							        TFFunnelForPreTraining,
							        TFFunnelForQuestionAnswering,
							        TFFunnelForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							__UpperCAmelCase						:    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 {}
							)
							__UpperCAmelCase						:    Optional[Any]				      =False
							__UpperCAmelCase						:    List[str]				      =False

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			TFFunnelModelTester(self	)
										__lowerCAmelCase				    =			ConfigTester(self    ,   config_class=__a	)

							def 			snake_case				(     self	):
										self.config_tester.run_common_tests()

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*__a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*__a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*__a	)



							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*__a	)
@require_tf
class   _UpperCamelCase  (   lowerCAmelCase__       ,unittest.TestCase		):
							'''simple docstring'''







							__UpperCAmelCase						:    List[str]				      =(
							    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
							)
							__UpperCAmelCase						:    Tuple				      =False
							__UpperCAmelCase						:    Any				      =False

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			TFFunnelModelTester(self    ,   base=__a	)
										__lowerCAmelCase				    =			ConfigTester(self    ,   config_class=__a	)

							def 			snake_case				(     self	):
										self.config_tester.run_common_tests()

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_base_model(*__a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*__a	)



							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*__a	)









from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_:Optional[Any]             =						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_:Dict             =						{
    """camembert-base""": """https://huggingface.co/camembert-base/resolve/main/config.json""",
    """umberto-commoncrawl-cased-v1""": (
        """https://huggingface.co/Musixmatch/umberto-commoncrawl-cased-v1/resolve/main/config.json"""
    ),
    """umberto-wikipedia-uncased-v1""": (
        """https://huggingface.co/Musixmatch/umberto-wikipedia-uncased-v1/resolve/main/config.json"""
    ),
}






class SCREAMING_SNAKE_CASE__     (		SCREAMING_SNAKE_CASE__    ):




    '''simple docstring'''






    __lowerCamelCase			: Optional[int]					=      "camembert"






    def __init__(       self,		lowerCamelCase__=3_0522,		lowerCamelCase__=768,		lowerCamelCase__=12,		lowerCamelCase__=12,		lowerCamelCase__=3072,		lowerCamelCase__="gelu",		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__=512,		lowerCamelCase__=2,		lowerCamelCase__=0.02,		lowerCamelCase__=1e-12,		lowerCamelCase__=1,		lowerCamelCase__=0,		lowerCamelCase__=2,		lowerCamelCase__="absolute",		lowerCamelCase__=True,		lowerCamelCase__=None,		**lowerCamelCase__,		):
        super().__init__(pad_token_id=lowerCamelCase__,		bos_token_id=lowerCamelCase__,		eos_token_id=lowerCamelCase__,		**lowerCamelCase__		)

        A :       List[Any]          =   vocab_size
        A :       Dict          =   hidden_size
        A :       str          =   num_hidden_layers
        A :       List[Any]          =   num_attention_heads
        A :       List[str]          =   hidden_act
        A :       Tuple          =   intermediate_size
        A :       Tuple          =   hidden_dropout_prob
        A :       List[Any]          =   attention_probs_dropout_prob
        A :       Optional[int]          =   max_position_embeddings
        A :       Tuple          =   type_vocab_size
        A :       List[Any]          =   initializer_range
        A :       str          =   layer_norm_eps
        A :       Tuple          =   position_embedding_type
        A :       str          =   use_cache
        A :       Any          =   classifier_dropout






class SCREAMING_SNAKE_CASE__     (		SCREAMING_SNAKE_CASE__    ):




    '''simple docstring'''






    @property
    def 			_lowerCAmelCase					(       self		):
        if self.task == "multiple-choice":
            A :       int          =   {0: """batch""", 1: """choice""", 2: """sequence"""}
        else:
            A :       Tuple          =   {0: """batch""", 1: """sequence"""}
        return OrderedDict(
            [
                ("""input_ids""", dynamic_axis),
                ("""attention_mask""", dynamic_axis),
            ]		)


