



import time
from dataclasses import dataclass
from multiprocessing import Pool
from unittest import TestCase
from unittest.mock import patch

import multiprocess
import numpy as np
import pytest

from datasets.utils.py_utils import (
    NestedDataStructure,
    asdict,
    iflatmap_unordered,
    map_nested,
    temp_seed,
    temporary_assignment,
    zip_dict,
)

from .utils import require_tf, require_torch


def A    (							__UpperCamelCase       )    ->   List[str]:  # picklable for multiprocessing
			return x.sum()


def A    (							__UpperCamelCase       )    ->   Optional[Any]:  # picklable for multiprocessing
			return i + 1


@dataclass
class   __lowerCAmelCase  :
					"""simple docstring"""






					A__					:		int
					A__					:		str







class   __lowerCAmelCase  (		UpperCAmelCase_   ):
					"""simple docstring"""






					def      _a				(  self       :							List[str]       ):






								"""simple docstring"""


								A__	  =     {}
								A__	  =     []
								A__	  =     1
								A__	  =     [1, 2]
								A__	  =     {'a': 1, 'b': 2}
								A__	  =     {'a': [1, 2], 'b': [3, 4]}
								A__	  =     {'a': {'1': 1}, 'b': 2}
								A__	  =     {'a': 1, 'b': 2, 'c': 3, 'd': 4}
								A__	  =     {}
								A__	  =     []
								A__	  =     2
								A__	  =     [2, 3]
								A__	  =     {'a': 2, 'b': 3}
								A__	  =     {'a': [2, 3], 'b': [4, 5]}
								A__	  =     {'a': {'1': 2}, 'b': 3}
								A__	  =     {'a': 2, 'b': 3, 'c': 4, 'd': 5}
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case       )					,       _snake_case       )

								A__	  =     2
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       num_proc=_snake_case       )					,       _snake_case       )

								A__	  =     {'a': np.eye(2       ), 'b': np.zeros(3       ), 'c': np.ones(2       )}
								A__	  =     {'a': 2, 'b': 0, 'c': 2}
								A__	  =     {
								    'a': np.eye(2       ).astype(_snake_case       ),
								    'b': np.zeros(3       ).astype(_snake_case       ),
								    'c': np.ones(2       ).astype(_snake_case       ),
								}
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       map_numpy=_snake_case       )					,       _snake_case       )
								self.assertEqual(
								    {k: v.tolist() for k, v in map_nested(_snake_case					,       _snake_case					,       map_numpy=_snake_case       ).items()}					,       {k: v.tolist() for k, v in expected_map_nested_sna_int.items()}					,       )
								self.assertEqual(map_nested(_snake_case					,       _snake_case					,       map_numpy=_snake_case					,       num_proc=_snake_case       )					,       _snake_case       )
								self.assertEqual(
								    {k: v.tolist() for k, v in map_nested(_snake_case					,       _snake_case					,       map_numpy=_snake_case					,       num_proc=_snake_case       ).items()}					,       {k: v.tolist() for k, v in expected_map_nested_sna_int.items()}					,       )
								with self.assertRaises(_snake_case       ):  # can't pickle a local lambda
											map_nested(lambda _snake_case       : x + 1					,       _snake_case					,       num_proc=_snake_case       )



					def      _a				(  self       :							Optional[int]       ):






								"""simple docstring"""


								A__	  =     {'a': 1, 'b': 2}
								A__	  =     {'a': 3, 'b': 4}
								A__	  =     {'a': 5, 'b': 6}
								A__	  =     sorted([('a', (1, 3, 5)), ('b', (2, 4, 6))]       )
								self.assertEqual(sorted(zip_dict(_snake_case					,       _snake_case					,       _snake_case       )       )					,       _snake_case       )



					def      _a				(  self       :							Tuple       ):






								"""simple docstring"""


								class   __lowerCAmelCase  :
													"""simple docstring"""






													A__					:		int      							=     "bar"







								A__	  =     Foo()
								self.assertEqual(foo.my_attr					,       'bar'       )
								with temporary_assignment(_snake_case					,       'my_attr'					,       'BAR'       ):
											self.assertEqual(foo.my_attr					,       'BAR'       )
								self.assertEqual(foo.my_attr					,       'bar'       )







@pytest.mark.parametrize(
    'iterable_length, num_proc, expected_num_proc'			,						[
        (1, None, 1),
        (1, 1, 1),
        (2, None, 1),
        (2, 1, 1),
        (2, 2, 1),
        (2, 3, 1),
        (3, 2, 1),
        (16, 16, 16),
        (16, 17, 16),
        (17, 16, 16),
    ]			,						)
def A    (							__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )    ->   List[str]:
			with patch('datasets.utils.py_utils._single_map_nested'       ) as mock_single_map_nested, patch(
			    'datasets.parallel.parallel.Pool'       ) as mock_multiprocessing_pool:
						A__	  =     {f'''{i}''': i for i in range(__UpperCamelCase       )}
						A__	  =     map_nested(lambda __UpperCamelCase       : x + 10			,						__UpperCamelCase			,						num_proc=__UpperCamelCase			,						parallel_min_length=16       )
						if expected_num_proc == 1:
									assert mock_single_map_nested.called
									assert not mock_multiprocessing_pool.called
						else:
									assert not mock_single_map_nested.called
									assert mock_multiprocessing_pool.called
									assert mock_multiprocessing_pool.call_args[0][0] == expected_num_proc


class   __lowerCAmelCase  (		UpperCAmelCase_   ):
					"""simple docstring"""






					@require_tf
					def      _a				(  self       :							Optional[int]       ):






								"""simple docstring"""


								import tensorflow as tf
								from tensorflow.keras import layers

								A__	  =     layers.Dense(2       )

								def gen_random_output():
											A__	  =     tf.random.uniform((1, 3)       )
											return model(_snake_case       ).numpy()

								with temp_seed(42					,       set_tensorflow=_snake_case       ):
											A__	  =     gen_random_output()
								with temp_seed(42					,       set_tensorflow=_snake_case       ):
											A__	  =     gen_random_output()
								A__	  =     gen_random_output()

								np.testing.assert_equal(_snake_case					,       _snake_case       )
								self.assertGreater(np.abs(outa - outa       ).sum()					,       0       )



					@require_torch
					def      _a				(  self       :							Optional[Any]       ):






								"""simple docstring"""


								import torch

								def gen_random_output():
											A__	  =     torch.nn.Linear(3					,       2       )
											A__	  =     torch.rand(1					,       3       )
											return model(_snake_case       ).detach().numpy()

								with temp_seed(42					,       set_pytorch=_snake_case       ):
											A__	  =     gen_random_output()
								with temp_seed(42					,       set_pytorch=_snake_case       ):
											A__	  =     gen_random_output()
								A__	  =     gen_random_output()

								np.testing.assert_equal(_snake_case					,       _snake_case       )
								self.assertGreater(np.abs(outa - outa       ).sum()					,       0       )



					def      _a				(  self       :							List[Any]       ):






								"""simple docstring"""


								def gen_random_output():
											return np.random.rand(1					,       3       )

								with temp_seed(42       ):
											A__	  =     gen_random_output()
								with temp_seed(42       ):
											A__	  =     gen_random_output()
								A__	  =     gen_random_output()

								np.testing.assert_equal(_snake_case					,       _snake_case       )
								self.assertGreater(np.abs(outa - outa       ).sum()					,       0       )







@pytest.mark.parametrize('input_data'			,						[{}]       )
def A    (							__UpperCamelCase       )    ->   List[str]:
			A__	  =     NestedDataStructure(__UpperCamelCase       ).data
			assert output_data == input_data


@pytest.mark.parametrize(
    'data, expected_output'			,						[
        ({}, []),
        ([], []),
        ('foo', ['foo']),
        (['foo', 'bar'], ['foo', 'bar']),
        ([['foo', 'bar']], ['foo', 'bar']),
        ([[['foo'], ['bar']]], ['foo', 'bar']),
        ([[['foo'], 'bar']], ['foo', 'bar']),
        ({'a': 1, 'b': 2}, [1, 2]),
        ({'a': [1, 2], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[1, 2]], 'b': [[3, 4]]}, [1, 2, 3, 4]),
        ({'a': [[1, 2]], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [[[3], [4]]]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [[3, 4]]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [3, [4]]}, [1, 2, 3, 4]),
        ({'a': {'1': 1}, 'b': 2}, [1, 2]),
        ({'a': {'1': [1]}, 'b': 2}, [1, 2]),
        ({'a': {'1': [1]}, 'b': [2]}, [1, 2]),
    ]			,						)
def A    (							__UpperCamelCase			,						__UpperCamelCase       )    ->   str:
			A__	  =     NestedDataStructure(__UpperCamelCase       ).flatten()
			assert output == expected_output


def A    (							)    ->   Tuple:
			A__	  =     A(x=1			,						y='foobar'       )
			A__	  =     {'x': 1, 'y': 'foobar'}
			assert asdict(__UpperCamelCase       ) == expected_output

			A__	  =     {'a': {'b': A(x=10			,						y='foo'       )}, 'c': [A(x=20			,						y='bar'       )]}
			A__	  =     {'a': {'b': {'x': 10, 'y': 'foo'}}, 'c': [{'x': 20, 'y': 'bar'}]}
			assert asdict(__UpperCamelCase       ) == expected_output

			with pytest.raises(__UpperCamelCase       ):
						asdict([1, A(x=10			,						y='foo'       )]       )


def A    (							__UpperCamelCase       )    ->   str:
			return text.split()


def A    (							__UpperCamelCase       )    ->   Tuple:
			yield (time.time(), content)
			time.sleep(2       )
			yield (time.time(), content)






def A    (							)    ->   Any:
			with Pool(2       ) as pool:
						A__	  =     list(iflatmap_unordered(__UpperCamelCase			,						_split_text			,						kwargs_iterable=[{'text': 'hello there'}] * 10       )       )
						assert out.count('hello'       ) == 10
						assert out.count('there'       ) == 10
						assert len(__UpperCamelCase       ) == 20

			# check multiprocess from pathos (uses dill for pickling)
			with multiprocess.Pool(2       ) as pool:
						A__	  =     list(iflatmap_unordered(__UpperCamelCase			,						_split_text			,						kwargs_iterable=[{'text': 'hello there'}] * 10       )       )
						assert out.count('hello'       ) == 10
						assert out.count('there'       ) == 10
						assert len(__UpperCamelCase       ) == 20

			# check that we get items as fast as possible
			with Pool(2       ) as pool:
						A__	  =     []
						for yield_time, content in iflatmap_unordered(
						    __UpperCamelCase			,						_aseconds_generator_of_aitems_with_timing			,						kwargs_iterable=[{'content': 'a'}, {'content': 'b'}]       ):
									assert yield_time < time.time() + 0.1, "we should each item directly after it was yielded"
									out.append(__UpperCamelCase       )
						assert out.count('a'       ) == 2
						assert out.count('b'       ) == 2
						assert len(__UpperCamelCase       ) == 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 		a							:


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

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


				def     A_					(						self       :   Union[str, Any]   ):
									snake_case_		     =							ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size   )

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

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

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

									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     A_					(						self       :   Optional[Any]			,							lowercase_       :   int			,							lowercase_       :   Tuple			,							lowercase_       :   List[str]			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Optional[int]			,							lowercase_       :   List[Any]			,							lowercase_       :   Optional[int]			,							):
									snake_case_		     =							TFFunnelModel(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )

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

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

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

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


				def     A_					(						self       :   List[Any]			,							lowercase_       :   Tuple			,							lowercase_       :   Dict			,							lowercase_       :   List[Any]			,							lowercase_       :   Dict			,							lowercase_       :   int			,							lowercase_       :   int			,							lowercase_       :   List[Any]			,							):
									snake_case_		     =							TFFunnelBaseModel(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )

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

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

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

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


				def     A_					(						self       :   Any			,							lowercase_       :   Optional[int]			,							lowercase_       :   str			,							lowercase_       :   int			,							lowercase_       :   Optional[int]			,							lowercase_       :   Optional[int]			,							lowercase_       :   Dict			,							lowercase_       :   Union[str, Any]			,							):
									snake_case_		     =							TFFunnelForPreTraining(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length)   )


				def     A_					(						self       :   Any			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Tuple			,							lowercase_       :   str			,							lowercase_       :   Tuple			,							lowercase_       :   List[str]			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Union[str, Any]			,							):
									snake_case_		     =							TFFunnelForMaskedLM(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.vocab_size)   )


				def     A_					(						self       :   Dict			,							lowercase_       :   Dict			,							lowercase_       :   str			,							lowercase_       :   Optional[Any]			,							lowercase_       :   Tuple			,							lowercase_       :   Optional[Any]			,							lowercase_       :   Tuple			,							lowercase_       :   Tuple			,							):
									snake_case_		     =							self.num_labels
									snake_case_		     =							TFFunnelForSequenceClassification(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.num_labels)   )


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


				def     A_					(						self       :   Any			,							lowercase_       :   str			,							lowercase_       :   Dict			,							lowercase_       :   int			,							lowercase_       :   Optional[int]			,							lowercase_       :   List[str]			,							lowercase_       :   Any			,							lowercase_       :   Optional[Any]			,							):
									snake_case_		     =							self.num_labels
									snake_case_		     =							TFFunnelForTokenClassification(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.num_labels)   )


				def     A_					(						self       :   Optional[Any]			,							lowercase_       :   Any			,							lowercase_       :   Dict			,							lowercase_       :   Any			,							lowercase_       :   int			,							lowercase_       :   Tuple			,							lowercase_       :   List[str]			,							lowercase_       :   Optional[Any]			,							):
									snake_case_		     =							TFFunnelForQuestionAnswering(config=lowercase_   )
									snake_case_		     =							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									snake_case_		     =							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     A_					(						self       :   Any   ):
									snake_case_		     =							self.prepare_config_and_inputs()
									(
									    (
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,
									)		     =							config_and_inputs
									snake_case_		     =							{'''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	):
				snake_case_           =						(
				    (
				        TFFunnelModel,
				        TFFunnelForMaskedLM,
				        TFFunnelForPreTraining,
				        TFFunnelForQuestionAnswering,
				        TFFunnelForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				snake_case_           =						(
				    {
				        "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
				        "fill-mask": TFFunnelForMaskedLM,
				        "question-answering": TFFunnelForQuestionAnswering,
				        "text-classification": TFFunnelForSequenceClassification,
				        "token-classification": TFFunnelForTokenClassification,
				        "zero-shot": TFFunnelForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				snake_case_           =						False
				snake_case_           =						False


				def     A_					(						self       :   int   ):
									snake_case_		     =							TFFunnelModelTester(self   )
									snake_case_		     =							ConfigTester(self			,							config_class=lowercase_   )


				def     A_					(						self       :   Union[str, Any]   ):
									self.config_tester.run_common_tests()


				def     A_					(						self       :   List[Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*lowercase_   )


				def     A_					(						self       :   List[str]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*lowercase_   )


				def     A_					(						self       :   str   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*lowercase_   )


				def     A_					(						self       :   List[str]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*lowercase_   )


				def     A_					(						self       :   List[Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*lowercase_   )







@require_tf
class 		a							(  _lowerCamelCase  ,	unittest.TestCase	):
				snake_case_           =						(
				    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
				)
				snake_case_           =						False
				snake_case_           =						False


				def     A_					(						self       :   Union[str, Any]   ):
									snake_case_		     =							TFFunnelModelTester(self			,							base=lowercase_   )
									snake_case_		     =							ConfigTester(self			,							config_class=lowercase_   )


				def     A_					(						self       :   Dict   ):
									self.config_tester.run_common_tests()


				def     A_					(						self       :   List[str]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_base_model(*lowercase_   )


				def     A_					(						self       :   Union[str, Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*lowercase_   )


				def     A_					(						self       :   str   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*lowercase_   )

