

"""simple docstring"""




import itertools
import random
import unittest

import numpy as np

from transformers import is_speech_available
from transformers.testing_utils import require_torch, require_torchaudio

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
						from transformers import SpeechaTextFeatureExtractor

A_				:      Any           =			random.Random()

def 						A							(  snake_case__		,					snake_case__=1.0		,					snake_case__=None		,					snake_case__=None     ):




			'''simple docstring'''


			if rng is None:
						SCREAMING_SNAKE_CASE__										=   global_rng

			SCREAMING_SNAKE_CASE__										=   []
			for batch_idx in range(shape[0]     ):
						values.append([]     )
						for _ in range(shape[1]     ):
									values[-1].append(rng.random() * scale     )

			return values





@require_torch
@require_torchaudio
class  lowerCamelCase    (unittest.TestCase      ):

			def __init__(       self					:    Any     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    str=7     ,					__UpperCAmelCase					:    List[Any]=4_0_0     ,					__UpperCAmelCase					:    Tuple=2_0_0_0     ,					__UpperCAmelCase					:    Tuple=2_4     ,					__UpperCAmelCase					:    List[str]=2_4     ,					__UpperCAmelCase					:    Any=0.0     ,					__UpperCAmelCase					:    int=1_6_0_0_0     ,					__UpperCAmelCase					:    Tuple=True     ,					__UpperCAmelCase					:    Optional[Any]=True     ,					) ->     Dict:
						SCREAMING_SNAKE_CASE__										=   parent
						SCREAMING_SNAKE_CASE__										=   batch_size
						SCREAMING_SNAKE_CASE__										=   min_seq_length
						SCREAMING_SNAKE_CASE__										=   max_seq_length
						SCREAMING_SNAKE_CASE__										=   (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
						SCREAMING_SNAKE_CASE__										=   feature_size
						SCREAMING_SNAKE_CASE__										=   num_mel_bins
						SCREAMING_SNAKE_CASE__										=   padding_value
						SCREAMING_SNAKE_CASE__										=   sampling_rate
						SCREAMING_SNAKE_CASE__										=   return_attention_mask
						SCREAMING_SNAKE_CASE__										=   do_normalize

			def        SCREAMING_SNAKE_CASE					(       self					:    str							) ->     Optional[int]:
						return {
						    "feature_size": self.feature_size,
						    "num_mel_bins": self.num_mel_bins,
						    "padding_value": self.padding_value,
						    "sampling_rate": self.sampling_rate,
						    "return_attention_mask": self.return_attention_mask,
						    "do_normalize": self.do_normalize,
						}





			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]     ,					__UpperCAmelCase					:    Tuple=False     ,					__UpperCAmelCase					:    Any=False							) ->     Union[str, Any]:
						def _flatten(__UpperCAmelCase					:    List[str]							):
									return list(itertools.chain(*__UpperCAmelCase							)							)

						if equal_length:
									SCREAMING_SNAKE_CASE__										=   [floats_list((self.max_seq_length, self.feature_size)							) for _ in range(self.batch_size							)]
						else:
									# make sure that inputs increase in size
									SCREAMING_SNAKE_CASE__										=   [
									    floats_list((x, self.feature_size)							)
									    for x in range(self.min_seq_length     ,					self.max_seq_length     ,					self.seq_length_diff							)
									]
						if numpify:
									SCREAMING_SNAKE_CASE__										=   [np.asarray(__UpperCAmelCase							) for x in speech_inputs]
						return speech_inputs





@require_torch
@require_torchaudio
class  lowerCamelCase    (A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		Optional[Any]       		=				SpeechaTextFeatureExtractor if is_speech_available() else None

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Union[str, Any]:
						SCREAMING_SNAKE_CASE__										=   SpeechaTextFeatureExtractionTester(self							)

			def        SCREAMING_SNAKE_CASE					(       self					:    int     ,					__UpperCAmelCase					:    Optional[int]							) ->     str:
						self.assertTrue(np.all(np.mean(__UpperCAmelCase     ,					axis=0							) < 1e-3							)							)
						self.assertTrue(np.all(np.abs(np.var(__UpperCAmelCase     ,					axis=0							) - 1							) < 1e-3							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     Any:
						# Tests that all call wrap to encode_plus and batch_encode_plus
						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						# create three inputs of length 800, 1000, and 1200
						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0							)]
						SCREAMING_SNAKE_CASE__										=   [np.asarray(__UpperCAmelCase							) for speech_input in speech_inputs]

						# Test feature size
						SCREAMING_SNAKE_CASE__										=   feature_extractor(__UpperCAmelCase     ,					padding=__UpperCAmelCase     ,					return_tensors="""np"""							).input_features
						self.assertTrue(input_features.ndim == 3							)
						self.assertTrue(input_features.shape[-1] == feature_extractor.feature_size							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   feature_extractor(speech_inputs[0]     ,					return_tensors="""np"""							).input_features
						SCREAMING_SNAKE_CASE__										=   feature_extractor(np_speech_inputs[0]     ,					return_tensors="""np"""							).input_features
						self.assertTrue(np.allclose(__UpperCAmelCase     ,					__UpperCAmelCase     ,					atol=1e-3							)							)

						# Test batched
						SCREAMING_SNAKE_CASE__										=   feature_extractor(__UpperCAmelCase     ,					return_tensors="""np"""							).input_features
						SCREAMING_SNAKE_CASE__										=   feature_extractor(__UpperCAmelCase     ,					return_tensors="""np"""							).input_features
						for enc_seq_a, enc_seq_a in zip(__UpperCAmelCase     ,					__UpperCAmelCase							):
									self.assertTrue(np.allclose(__UpperCAmelCase     ,					__UpperCAmelCase     ,					atol=1e-3							)							)

						# Test 2-D numpy arrays are batched.
						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in (8_0_0, 8_0_0, 8_0_0)]
						SCREAMING_SNAKE_CASE__										=   np.asarray(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   feature_extractor(__UpperCAmelCase     ,					return_tensors="""np"""							).input_features
						SCREAMING_SNAKE_CASE__										=   feature_extractor(__UpperCAmelCase     ,					return_tensors="""np"""							).input_features
						for enc_seq_a, enc_seq_a in zip(__UpperCAmelCase     ,					__UpperCAmelCase							):
									self.assertTrue(np.allclose(__UpperCAmelCase     ,					__UpperCAmelCase     ,					atol=1e-3							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0							)]

						SCREAMING_SNAKE_CASE__										=   ["""longest""", """max_length""", """do_not_pad"""]
						SCREAMING_SNAKE_CASE__										=   [None, 1_6, None]
						for max_length, padding in zip(__UpperCAmelCase     ,					__UpperCAmelCase							):
									SCREAMING_SNAKE_CASE__										=   feature_extractor(
									    __UpperCAmelCase     ,					padding=__UpperCAmelCase     ,					max_length=__UpperCAmelCase     ,					return_attention_mask=__UpperCAmelCase							)
									SCREAMING_SNAKE_CASE__										=   inputs.input_features
									SCREAMING_SNAKE_CASE__										=   inputs.attention_mask
									SCREAMING_SNAKE_CASE__										=   [np.sum(__UpperCAmelCase							) for x in attention_mask]

									self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]]							)
									self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]]							)
									self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]]							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0							)]

						SCREAMING_SNAKE_CASE__										=   ["""longest""", """max_length""", """do_not_pad"""]
						SCREAMING_SNAKE_CASE__										=   [None, 1_6, None]
						for max_length, padding in zip(__UpperCAmelCase     ,					__UpperCAmelCase							):
									SCREAMING_SNAKE_CASE__										=   feature_extractor(
									    __UpperCAmelCase     ,					max_length=__UpperCAmelCase     ,					padding=__UpperCAmelCase     ,					return_tensors="""np"""     ,					return_attention_mask=__UpperCAmelCase							)
									SCREAMING_SNAKE_CASE__										=   inputs.input_features
									SCREAMING_SNAKE_CASE__										=   inputs.attention_mask
									SCREAMING_SNAKE_CASE__										=   [np.sum(__UpperCAmelCase							) for x in attention_mask]

									self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]]							)
									self.assertTrue(input_features[0][fbank_feat_lengths[0] :].sum() < 1e-6							)
									self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]]							)
									self.assertTrue(input_features[0][fbank_feat_lengths[1] :].sum() < 1e-6							)
									self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]]							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0							)]
						SCREAMING_SNAKE_CASE__										=   feature_extractor(
						    __UpperCAmelCase     ,					padding="""max_length"""     ,					max_length=4     ,					truncation=__UpperCAmelCase     ,					return_tensors="""np"""     ,					return_attention_mask=__UpperCAmelCase     ,					)
						SCREAMING_SNAKE_CASE__										=   inputs.input_features
						SCREAMING_SNAKE_CASE__										=   inputs.attention_mask
						SCREAMING_SNAKE_CASE__										=   np.sum(attention_mask == 1     ,					axis=1							)

						self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]]							)
						self._check_zero_mean_unit_variance(input_features[1]							)
						self._check_zero_mean_unit_variance(input_features[2]							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     int:
						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0							)]
						SCREAMING_SNAKE_CASE__										=   feature_extractor(
						    __UpperCAmelCase     ,					padding="""longest"""     ,					max_length=4     ,					truncation=__UpperCAmelCase     ,					return_tensors="""np"""     ,					return_attention_mask=__UpperCAmelCase     ,					)
						SCREAMING_SNAKE_CASE__										=   inputs.input_features
						SCREAMING_SNAKE_CASE__										=   inputs.attention_mask
						SCREAMING_SNAKE_CASE__										=   np.sum(attention_mask == 1     ,					axis=1							)

						self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]]							)
						self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]]							)
						self._check_zero_mean_unit_variance(input_features[2]							)

						# make sure that if max_length < longest -> then pad to max_length
						self.assertEqual(input_features.shape     ,					(3, 4, 2_4)							)

						SCREAMING_SNAKE_CASE__										=   [floats_list((1, x)							)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0							)]
						SCREAMING_SNAKE_CASE__										=   feature_extractor(
						    __UpperCAmelCase     ,					padding="""longest"""     ,					max_length=1_6     ,					truncation=__UpperCAmelCase     ,					return_tensors="""np"""     ,					return_attention_mask=__UpperCAmelCase     ,					)
						SCREAMING_SNAKE_CASE__										=   inputs.input_features
						SCREAMING_SNAKE_CASE__										=   inputs.attention_mask
						SCREAMING_SNAKE_CASE__										=   np.sum(attention_mask == 1     ,					axis=1							)

						self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]]							)
						self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]]							)
						self._check_zero_mean_unit_variance(input_features[2]							)

						# make sure that if max_length < longest -> then pad to max_length
						self.assertEqual(input_features.shape     ,					(3, 6, 2_4)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Union[str, Any]							) ->     Optional[Any]:
						import torch

						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						SCREAMING_SNAKE_CASE__										=   np.random.rand(1_0_0     ,					3_2							).astype(np.floataa							)
						SCREAMING_SNAKE_CASE__										=   np_speech_inputs.tolist()

						for inputs in [py_speech_inputs, np_speech_inputs]:
									SCREAMING_SNAKE_CASE__										=   feature_extractor.pad([{"""input_features""": inputs}]     ,					return_tensors="""np"""							)
									self.assertTrue(np_processed.input_features.dtype == np.floataa							)
									SCREAMING_SNAKE_CASE__										=   feature_extractor.pad([{"""input_features""": inputs}]     ,					return_tensors="""pt"""							)
									self.assertTrue(pt_processed.input_features.dtype == torch.floataa							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Any     ,					__UpperCAmelCase					:    Dict							) ->     List[str]:
						from datasets import load_dataset

						SCREAMING_SNAKE_CASE__										=   load_dataset("""hf-internal-testing/librispeech_asr_dummy"""     ,					"""clean"""     ,					split="""validation"""							)
						# automatic decoding with librispeech
						SCREAMING_SNAKE_CASE__										=   ds.sort("""id"""							).select(range(__UpperCAmelCase							)							)[:num_samples]["""audio"""]

						return [x["array"] for x in speech_samples]





			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     int:
						# fmt: off
						SCREAMING_SNAKE_CASE__										=   np.array([
						    -1.5_745, -1.7_713, -1.7_020, -1.6_069, -1.2_250, -1.1_105, -0.9_072, -0.8_241,
						    -1.2_310, -0.8_098, -0.3_320, -0.4_101, -0.7_985, -0.4_996, -0.8_213, -0.9_128,
						    -1.0_420, -1.1_286, -1.0_440, -0.7_999, -0.8_405, -1.2_275, -1.5_443, -1.4_625,
						]							)
						# fmt: on

						SCREAMING_SNAKE_CASE__										=   self._load_datasamples(1							)
						SCREAMING_SNAKE_CASE__										=   self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						SCREAMING_SNAKE_CASE__										=   feature_extractor(__UpperCAmelCase     ,					return_tensors="""pt"""							).input_features
						self.assertEquals(input_features.shape     ,					(1, 5_8_4, 2_4)							)
						self.assertTrue(np.allclose(input_features[0, 0, :3_0]     ,					__UpperCAmelCase     ,					atol=1e-4							)							)





"""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					:    str     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    Union[str, Any]=1_3     ,					__UpperCAmelCase					:    Union[str, Any]=7     ,					__UpperCAmelCase					:    List[str]=True     ,					__UpperCAmelCase					:    Tuple=True     ,					__UpperCAmelCase					:    Any=True     ,					__UpperCAmelCase					:    Dict=True     ,					__UpperCAmelCase					:    Union[str, Any]=9_9     ,					__UpperCAmelCase					:    str=[1, 1, 2]     ,					__UpperCAmelCase					:    str=1     ,					__UpperCAmelCase					:    Dict=3_2     ,					__UpperCAmelCase					:    Optional[int]=4     ,					__UpperCAmelCase					:    str=8     ,					__UpperCAmelCase					:    List[Any]=3_7     ,					__UpperCAmelCase					:    Union[str, Any]="gelu_new"     ,					__UpperCAmelCase					:    List[Any]=0.1     ,					__UpperCAmelCase					:    str=0.1     ,					__UpperCAmelCase					:    Any=0.0     ,					__UpperCAmelCase					:    str=5_1_2     ,					__UpperCAmelCase					:    Optional[Any]=3     ,					__UpperCAmelCase					:    List[str]=0.02     ,					__UpperCAmelCase					:    Tuple=3     ,					__UpperCAmelCase					:    str=4     ,					__UpperCAmelCase					:    Optional[Any]=None     ,					__UpperCAmelCase					:    int=False     ,					) ->     List[Any]:
						SCREAMING_SNAKE_CASE__										=   parent
						SCREAMING_SNAKE_CASE__										=   batch_size
						SCREAMING_SNAKE_CASE__										=   seq_length
						SCREAMING_SNAKE_CASE__										=   is_training
						SCREAMING_SNAKE_CASE__										=   use_input_mask
						SCREAMING_SNAKE_CASE__										=   use_token_type_ids
						SCREAMING_SNAKE_CASE__										=   use_labels
						SCREAMING_SNAKE_CASE__										=   vocab_size
						SCREAMING_SNAKE_CASE__										=   block_sizes
						SCREAMING_SNAKE_CASE__										=   num_decoder_layers
						SCREAMING_SNAKE_CASE__										=   d_model
						SCREAMING_SNAKE_CASE__										=   n_head
						SCREAMING_SNAKE_CASE__										=   d_head
						SCREAMING_SNAKE_CASE__										=   d_inner
						SCREAMING_SNAKE_CASE__										=   hidden_act
						SCREAMING_SNAKE_CASE__										=   hidden_dropout
						SCREAMING_SNAKE_CASE__										=   attention_dropout
						SCREAMING_SNAKE_CASE__										=   activation_dropout
						SCREAMING_SNAKE_CASE__										=   max_position_embeddings
						SCREAMING_SNAKE_CASE__										=   type_vocab_size
						SCREAMING_SNAKE_CASE__										=   2
						SCREAMING_SNAKE_CASE__										=   num_labels
						SCREAMING_SNAKE_CASE__										=   num_choices
						SCREAMING_SNAKE_CASE__										=   scope
						SCREAMING_SNAKE_CASE__										=   initializer_std

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

			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[Any]							) ->     Union[str, Any]:
						SCREAMING_SNAKE_CASE__										=   ids_tensor([self.batch_size, self.seq_length]     ,					self.vocab_size							)

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

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

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

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

						SCREAMING_SNAKE_CASE__										=   [input_ids, input_mask]
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)

						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)
						self.parent.assertEqual(result.last_hidden_state.shape     ,					(self.batch_size, self.seq_length, self.d_model)							)

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

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

			def        SCREAMING_SNAKE_CASE					(       self					:    int     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    int     ,					) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   TFFunnelBaseModel(config=__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)

						SCREAMING_SNAKE_CASE__										=   [input_ids, input_mask]
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)

						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)
						self.parent.assertEqual(result.last_hidden_state.shape     ,					(self.batch_size, 2, self.d_model)							)

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

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

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

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

			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[Any]     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    int     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Tuple     ,					) ->     List[str]:
						SCREAMING_SNAKE_CASE__										=   self.num_labels
						SCREAMING_SNAKE_CASE__										=   TFFunnelForSequenceClassification(config=__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.num_labels)							)

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

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

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





@require_tf
class  lowerCamelCase    (A__      ,A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		int       		=				(
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCamelCase__ :		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 {}
			)
			lowerCamelCase__ :		str       		=				False
			lowerCamelCase__ :		Any       		=				False

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   TFFunnelModelTester(self							)
						SCREAMING_SNAKE_CASE__										=   ConfigTester(self     ,					config_class=__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     str:
						self.config_tester.run_common_tests()

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     str:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    int							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase							)





			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase							)





@require_tf
class  lowerCamelCase    (A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		List[Any]       		=				(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			lowerCamelCase__ :		Dict       		=				False
			lowerCamelCase__ :		Tuple       		=				False

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     Union[str, Any]:
						SCREAMING_SNAKE_CASE__										=   TFFunnelModelTester(self     ,					base=__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   ConfigTester(self     ,					config_class=__UpperCAmelCase							)

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

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     str:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase							)





			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     int:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*__UpperCAmelCase							)


