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





							"""simple docstring"""




							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  , ):







														'''simple docstring'''






														_lowercase					=						parent
														_lowercase					=						batch_size
														_lowercase					=						seq_length
														_lowercase					=						is_training
														_lowercase					=						use_input_mask
														_lowercase					=						use_token_type_ids
														_lowercase					=						use_labels
														_lowercase					=						vocab_size
														_lowercase					=						block_sizes
														_lowercase					=						num_decoder_layers
														_lowercase					=						d_model
														_lowercase					=						n_head
														_lowercase					=						d_head
														_lowercase					=						d_inner
														_lowercase					=						hidden_act
														_lowercase					=						hidden_dropout
														_lowercase					=						attention_dropout
														_lowercase					=						activation_dropout
														_lowercase					=						max_position_embeddings
														_lowercase					=						type_vocab_size
														_lowercase					=						2
														_lowercase					=						num_labels
														_lowercase					=						num_choices
														_lowercase					=						scope
														_lowercase					=						initializer_std

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



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						ids_tensor([self.batch_size, self.seq_length]  , self.vocab_size	)

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

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

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

														_lowercase					=						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      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






														_lowercase					=						TFFunnelModel(config=lowercase_	)
														_lowercase					=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
														_lowercase					=						model(lowercase_	)

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

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

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

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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






														_lowercase					=						TFFunnelBaseModel(config=lowercase_	)
														_lowercase					=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
														_lowercase					=						model(lowercase_	)

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

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

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

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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






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



							def      _UpperCAmelCase							(     self  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , UpperCAmelCase  , ):







														'''simple docstring'''






														_lowercase					=						TFFunnelForQuestionAnswering(config=lowercase_	)
														_lowercase					=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
														_lowercase					=						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      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.prepare_config_and_inputs()
														(
														    (
														    _lowercase
														)					,							(
														    _lowercase
														)					,							(
														    _lowercase
														)					,							(
														    _lowercase
														)					,							(
														    _lowercase
														)					,							(
														    _lowercase
														)					,							(
														    _lowercase
														)					,							
														)					=						config_and_inputs
														_lowercase					=						{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
														return config, inputs_dict






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





							"""simple docstring"""




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



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						TFFunnelModelTester(self	)
														_lowercase					=						ConfigTester(self  , config_class=lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														self.config_tester.run_common_tests()



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_pretraining(*lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_lm(*lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_token_classification(*lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_question_answering(*lowercase_	)






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





							"""simple docstring"""




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



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						TFFunnelModelTester(self  , base=lowercase_	)
														_lowercase					=						ConfigTester(self  , config_class=lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														self.config_tester.run_common_tests()



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_base_model(*lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_sequence_classification(*lowercase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_multiple_choice(*lowercase_	)








'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


a    :							Tuple										=    {
    'configuration_encodec': [
        'ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'EncodecConfig',
    ],
    'feature_extraction_encodec': ['EncodecFeatureExtractor'],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a    :							str										=    [
							    'ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'EncodecModel',
							    'EncodecPreTrainedModel',
							]

if TYPE_CHECKING:
							from .configuration_encodec import (
							    ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    EncodecConfig,
							)
							from .feature_extraction_encodec import EncodecFeatureExtractor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_encodec import (
														    ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST,
														    EncodecModel,
														    EncodecPreTrainedModel,
														)

else:
							import sys

							a    :							List[Any]										=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

