



import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# Build the list of all feature extractors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...feature_extraction_utils import FeatureExtractionMixin
from ...utils import CONFIG_NAME, FEATURE_EXTRACTOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)


a      :  Tuple			     =			logging.get_logger(__name__)

a      :  Optional[Any]			     =			OrderedDict(
    [
        ('audio-spectrogram-transformer', 'ASTFeatureExtractor'),
        ('beit', 'BeitFeatureExtractor'),
        ('chinese_clip', 'ChineseCLIPFeatureExtractor'),
        ('clap', 'ClapFeatureExtractor'),
        ('clip', 'CLIPFeatureExtractor'),
        ('clipseg', 'ViTFeatureExtractor'),
        ('conditional_detr', 'ConditionalDetrFeatureExtractor'),
        ('convnext', 'ConvNextFeatureExtractor'),
        ('cvt', 'ConvNextFeatureExtractor'),
        ('data2vec-audio', 'Wav2Vec2FeatureExtractor'),
        ('data2vec-vision', 'BeitFeatureExtractor'),
        ('deformable_detr', 'DeformableDetrFeatureExtractor'),
        ('deit', 'DeiTFeatureExtractor'),
        ('detr', 'DetrFeatureExtractor'),
        ('dinat', 'ViTFeatureExtractor'),
        ('donut-swin', 'DonutFeatureExtractor'),
        ('dpt', 'DPTFeatureExtractor'),
        ('encodec', 'EncodecFeatureExtractor'),
        ('flava', 'FlavaFeatureExtractor'),
        ('glpn', 'GLPNFeatureExtractor'),
        ('groupvit', 'CLIPFeatureExtractor'),
        ('hubert', 'Wav2Vec2FeatureExtractor'),
        ('imagegpt', 'ImageGPTFeatureExtractor'),
        ('layoutlmv2', 'LayoutLMv2FeatureExtractor'),
        ('layoutlmv3', 'LayoutLMv3FeatureExtractor'),
        ('levit', 'LevitFeatureExtractor'),
        ('maskformer', 'MaskFormerFeatureExtractor'),
        ('mctct', 'MCTCTFeatureExtractor'),
        ('mobilenet_v1', 'MobileNetV1FeatureExtractor'),
        ('mobilenet_v2', 'MobileNetV2FeatureExtractor'),
        ('mobilevit', 'MobileViTFeatureExtractor'),
        ('nat', 'ViTFeatureExtractor'),
        ('owlvit', 'OwlViTFeatureExtractor'),
        ('perceiver', 'PerceiverFeatureExtractor'),
        ('poolformer', 'PoolFormerFeatureExtractor'),
        ('regnet', 'ConvNextFeatureExtractor'),
        ('resnet', 'ConvNextFeatureExtractor'),
        ('segformer', 'SegformerFeatureExtractor'),
        ('sew', 'Wav2Vec2FeatureExtractor'),
        ('sew-d', 'Wav2Vec2FeatureExtractor'),
        ('speech_to_text', 'Speech2TextFeatureExtractor'),
        ('speecht5', 'SpeechT5FeatureExtractor'),
        ('swiftformer', 'ViTFeatureExtractor'),
        ('swin', 'ViTFeatureExtractor'),
        ('swinv2', 'ViTFeatureExtractor'),
        ('table-transformer', 'DetrFeatureExtractor'),
        ('timesformer', 'VideoMAEFeatureExtractor'),
        ('tvlt', 'TvltFeatureExtractor'),
        ('unispeech', 'Wav2Vec2FeatureExtractor'),
        ('unispeech-sat', 'Wav2Vec2FeatureExtractor'),
        ('van', 'ConvNextFeatureExtractor'),
        ('videomae', 'VideoMAEFeatureExtractor'),
        ('vilt', 'ViltFeatureExtractor'),
        ('vit', 'ViTFeatureExtractor'),
        ('vit_mae', 'ViTFeatureExtractor'),
        ('vit_msn', 'ViTFeatureExtractor'),
        ('wav2vec2', 'Wav2Vec2FeatureExtractor'),
        ('wav2vec2-conformer', 'Wav2Vec2FeatureExtractor'),
        ('wavlm', 'Wav2Vec2FeatureExtractor'),
        ('whisper', 'WhisperFeatureExtractor'),
        ('xclip', 'CLIPFeatureExtractor'),
        ('yolos', 'YolosFeatureExtractor'),
    ]
)

a      :  Optional[int]			     =			_LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)







def  lowerCAmelCase_	(lowerCAmelCase__:		str  ):





			"""simple docstring"""


			for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
						if class_name in extractors:
									UpperCAmelCase_:		int							      =     model_type_to_module_name(lowerCAmelCase__  )

									UpperCAmelCase_:		Optional[int]							      =     importlib.import_module(F'.{module_name}'		,						"""transformers.models"""  )
									try:
												return getattr(lowerCAmelCase__		,						lowerCAmelCase__  )
									except AttributeError:
												continue

			for _, extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.items():
						if getattr(lowerCAmelCase__		,						"""__name__"""		,						lowerCAmelCase__  ) == class_name:
									return extractor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
			UpperCAmelCase_:		List[str]							      =     importlib.import_module("""transformers"""  )
			if hasattr(lowerCAmelCase__		,						lowerCAmelCase__  ):
						return getattr(lowerCAmelCase__		,						lowerCAmelCase__  )

			return None







def  lowerCAmelCase_	(lowerCAmelCase__:		Union[str, os.PathLike]		,						lowerCAmelCase__:		Optional[Union[str, os.PathLike]] = None		,						lowerCAmelCase__:		bool = False		,						lowerCAmelCase__:		bool = False		,						lowerCAmelCase__:		Optional[Dict[str, str]] = None		,						lowerCAmelCase__:		Optional[Union[bool, str]] = None		,						lowerCAmelCase__:		Optional[str] = None		,						lowerCAmelCase__:		bool = False		,						**lowerCAmelCase__:		Optional[int]		,						):





			"""simple docstring"""


			UpperCAmelCase_:		List[str]							      =     get_file_from_repo(
			    lowerCAmelCase__		,						lowerCAmelCase__		,						cache_dir=lowerCAmelCase__		,						force_download=lowerCAmelCase__		,						resume_download=lowerCAmelCase__		,						proxies=lowerCAmelCase__		,						use_auth_token=lowerCAmelCase__		,						revision=lowerCAmelCase__		,						local_files_only=lowerCAmelCase__		,						)
			if resolved_config_file is None:
						logger.info(
						    """Could not locate the feature extractor configuration file, will try to use the model config instead."""  )
						return {}

			with open(lowerCAmelCase__		,						encoding="""utf-8"""  ) as reader:
						return json.load(lowerCAmelCase__  )







class 				_a				:

			def __init__(self					)       ->   List[str]:
						raise EnvironmentError(
						    """AutoFeatureExtractor is designed to be instantiated """
						    """using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method."""					)

			@classmethod
			@replace_list_option_in_docstrings(SCREAMING_SNAKE_CASE_					)
			def      __snake_case       (cls,   SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Tuple							      =     kwargs.pop("""config""",   SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		str							      =     kwargs.pop("""trust_remote_code""",   SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		str							      =     True

						UpperCAmelCase_      ,							UpperCAmelCase_:		Optional[int]							      =     FeatureExtractionMixin.get_feature_extractor_dict(SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Optional[int]							      =     config_dict.get("""feature_extractor_type""",   SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Any							      =     None
						if "AutoFeatureExtractor" in config_dict.get("""auto_map""",   {}					):
									UpperCAmelCase_:		List[Any]							      =     config_dict["""auto_map"""]["""AutoFeatureExtractor"""]

						# If we don't find the feature extractor class in the feature extractor config, let's try the model config.
						if feature_extractor_class is None and feature_extractor_auto_map is None:
									if not isinstance(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					):
												UpperCAmelCase_:		Union[str, Any]							      =     AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)
									# It could be in `config.feature_extractor_type``
									UpperCAmelCase_:		Tuple							      =     getattr(SCREAMING_SNAKE_CASE_,   """feature_extractor_type""",   SCREAMING_SNAKE_CASE_					)
									if hasattr(SCREAMING_SNAKE_CASE_,   """auto_map"""					) and "AutoFeatureExtractor" in config.auto_map:
												UpperCAmelCase_:		Union[str, Any]							      =     config.auto_map["""AutoFeatureExtractor"""]

						if feature_extractor_class is not None:
									UpperCAmelCase_:		Optional[int]							      =     feature_extractor_class_from_name(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     feature_extractor_auto_map is not None
						UpperCAmelCase_:		Tuple							      =     feature_extractor_class is not None or type(SCREAMING_SNAKE_CASE_					) in FEATURE_EXTRACTOR_MAPPING
						UpperCAmelCase_:		Union[str, Any]							      =     resolve_trust_remote_code(
						    SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

						if has_remote_code and trust_remote_code:
									UpperCAmelCase_:		List[Any]							      =     get_class_from_dynamic_module(
									    SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)
									UpperCAmelCase_:		List[Any]							      =     kwargs.pop("""code_revision""",   SCREAMING_SNAKE_CASE_					)
									if os.path.isdir(SCREAMING_SNAKE_CASE_					):
												feature_extractor_class.register_for_auto_class()
									return feature_extractor_class.from_dict(SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)
						elif feature_extractor_class is not None:
									return feature_extractor_class.from_dict(SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)
						# Last try: we use the FEATURE_EXTRACTOR_MAPPING.
						elif type(SCREAMING_SNAKE_CASE_					) in FEATURE_EXTRACTOR_MAPPING:
									UpperCAmelCase_:		Tuple							      =     FEATURE_EXTRACTOR_MAPPING[type(SCREAMING_SNAKE_CASE_					)]
									return feature_extractor_class.from_dict(SCREAMING_SNAKE_CASE_,   **SCREAMING_SNAKE_CASE_					)

						raise ValueError(
						    f'Unrecognized feature extractor in {pretrained_model_name_or_path}. Should have a '
						    f'`feature_extractor_type` key in its {FEATURE_EXTRACTOR_NAME} of {CONFIG_NAME}, or one of the following '
						    f'`model_type` keys in its {CONFIG_NAME}: {", ".join(c for c in FEATURE_EXTRACTOR_MAPPING_NAMES.keys()					)}'					)

			@staticmethod
			def      __snake_case       (SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Tuple:
						FEATURE_EXTRACTOR_MAPPING.register(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)











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

			def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_=13,   SCREAMING_SNAKE_CASE_=7,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=99,   SCREAMING_SNAKE_CASE_=[1, 1, 2],   SCREAMING_SNAKE_CASE_=1,   SCREAMING_SNAKE_CASE_=32,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_=8,   SCREAMING_SNAKE_CASE_=37,   SCREAMING_SNAKE_CASE_="gelu_new",   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.0,   SCREAMING_SNAKE_CASE_=512,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=0.0_2,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_=None,   SCREAMING_SNAKE_CASE_=False,   )       ->   Tuple:
						UpperCAmelCase_:		Any							      =     parent
						UpperCAmelCase_:		Optional[Any]							      =     batch_size
						UpperCAmelCase_:		Dict							      =     seq_length
						UpperCAmelCase_:		Union[str, Any]							      =     is_training
						UpperCAmelCase_:		Optional[Any]							      =     use_input_mask
						UpperCAmelCase_:		Optional[Any]							      =     use_token_type_ids
						UpperCAmelCase_:		int							      =     use_labels
						UpperCAmelCase_:		List[str]							      =     vocab_size
						UpperCAmelCase_:		Optional[int]							      =     block_sizes
						UpperCAmelCase_:		Tuple							      =     num_decoder_layers
						UpperCAmelCase_:		List[Any]							      =     d_model
						UpperCAmelCase_:		Dict							      =     n_head
						UpperCAmelCase_:		Optional[Any]							      =     d_head
						UpperCAmelCase_:		Optional[Any]							      =     d_inner
						UpperCAmelCase_:		str							      =     hidden_act
						UpperCAmelCase_:		str							      =     hidden_dropout
						UpperCAmelCase_:		Union[str, Any]							      =     attention_dropout
						UpperCAmelCase_:		Dict							      =     activation_dropout
						UpperCAmelCase_:		str							      =     max_position_embeddings
						UpperCAmelCase_:		Dict							      =     type_vocab_size
						UpperCAmelCase_:		str							      =     2
						UpperCAmelCase_:		Dict							      =     num_labels
						UpperCAmelCase_:		Optional[int]							      =     num_choices
						UpperCAmelCase_:		Optional[int]							      =     scope
						UpperCAmelCase_:		List[Any]							      =     initializer_std

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

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Dict							      =     ids_tensor([self.batch_size, self.seq_length],   self.vocab_size					)

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

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

						UpperCAmelCase_:		Any							      =     None
						UpperCAmelCase_:		str							      =     None
						UpperCAmelCase_:		Any							      =     None
						if self.use_labels:
									UpperCAmelCase_:		Dict							      =     ids_tensor([self.batch_size],   self.type_sequence_label_size					)
									UpperCAmelCase_:		Optional[Any]							      =     ids_tensor([self.batch_size, self.seq_length],   self.num_labels					)
									UpperCAmelCase_:		str							      =     ids_tensor([self.batch_size],   self.num_choices					)

						UpperCAmelCase_:		Dict							      =     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,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		str							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     [input_ids, input_mask]
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

						UpperCAmelCase_:		Union[str, Any]							      =     False
						UpperCAmelCase_:		int							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

						UpperCAmelCase_:		Optional[Any]							      =     False
						UpperCAmelCase_:		str							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Any:
						UpperCAmelCase_:		Dict							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Optional[int]							      =     [input_ids, input_mask]
						UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 2, self.d_model)					)

						UpperCAmelCase_:		List[str]							      =     False
						UpperCAmelCase_:		str							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Any							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 3, self.d_model)					)

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

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Dict:
						UpperCAmelCase_:		List[Any]							      =     TFFunnelForPreTraining(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   str:
						UpperCAmelCase_:		Union[str, Any]							      =     TFFunnelForMaskedLM(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[str]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.vocab_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		Tuple							      =     self.num_labels
						UpperCAmelCase_:		Optional[int]							      =     TFFunnelForSequenceClassification(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		Tuple							      =     self.num_choices
						UpperCAmelCase_:		List[str]							      =     TFFunnelForMultipleChoice(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		int							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		Any							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		int							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		Tuple							      =     {
						    """input_ids""": multiple_choice_inputs_ids,
						    """attention_mask""": multiple_choice_input_mask,
						    """token_type_ids""": multiple_choice_token_type_ids,
						}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_choices)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		List[Any]							      =     self.num_labels
						UpperCAmelCase_:		Dict							      =     TFFunnelForTokenClassification(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   str:
						UpperCAmelCase_:		Any							      =     TFFunnelForQuestionAnswering(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						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					)       ->   int:
						UpperCAmelCase_:		Optional[Any]							      =     self.prepare_config_and_inputs()
						(
						    (
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							
						):		Tuple							      =     config_and_inputs
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
						return config, inputs_dict







@require_tf
class 				_a				(   _lowerCAmelCase ,		_lowerCAmelCase ,		unittest.TestCase					):
			A      		=	(
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			A      		=	(
			    {
			        '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
			        '''fill-mask''': TFFunnelForMaskedLM,
			        '''question-answering''': TFFunnelForQuestionAnswering,
			        '''text-classification''': TFFunnelForSequenceClassification,
			        '''token-classification''': TFFunnelForTokenClassification,
			        '''zero-shot''': TFFunnelForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			A      		=	False
			A      		=	False

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Union[str, Any]							      =     TFFunnelModelTester(self					)
						UpperCAmelCase_:		List[str]							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Any:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		List[str]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[int]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Tuple							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   List[Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_					)







@require_tf
class 				_a				(   _lowerCAmelCase ,		unittest.TestCase					):
			A      		=	(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			A      		=	False
			A      		=	False

			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_:		List[Any]							      =     TFFunnelModelTester(self,   base=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_					)






