
"""simple docstring"""







import unittest

from transformers import GPTNeoXJapaneseConfig, is_torch_available
from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import GPTNeoXJapaneseTokenizer
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import GPTNeoXJapaneseForCausalLM, GPTNeoXJapaneseModel




class       lowerCAmelCase__       :


				"""simple docstring"""





				def __init__(     self					:	Optional[Any]    ,   lowercase__					:	Optional[Any]    ,   lowercase__					:	str=1_3    ,   lowercase__					:	Optional[int]=7    ,   lowercase__					:	Dict=True    ,   lowercase__					:	List[str]=True    ,   lowercase__					:	Any=True    ,   lowercase__					:	Optional[int]=True    ,   lowercase__					:	Tuple=9_9    ,   lowercase__					:	List[str]=3_2    ,   lowercase__					:	Optional[Any]=5    ,   lowercase__					:	List[Any]=4    ,   lowercase__					:	Tuple=4    ,   lowercase__					:	Dict="gelu"    ,   lowercase__					:	str=0.0    ,   lowercase__					:	int=0.1    ,   lowercase__					:	str=True    ,   lowercase__					:	List[str]=5_1_2    ,   lowercase__					:	Any=1_6    ,   lowercase__					:	Optional[Any]=2    ,   lowercase__					:	List[Any]=0.0_2    ,   lowercase__					:	Tuple=3    ,   lowercase__					:	Union[str, Any]=4    ,   lowercase__					:	Optional[int]=None    ,   ):
						__lowercase				:		Tuple												=				parent
						__lowercase				:		str												=				batch_size
						__lowercase				:		Optional[Any]												=				seq_length
						__lowercase				:		Optional[int]												=				is_training
						__lowercase				:		List[Any]												=				use_input_mask
						__lowercase				:		int												=				use_token_type_ids
						__lowercase				:		Dict												=				use_labels
						__lowercase				:		str												=				vocab_size
						__lowercase				:		List[str]												=				hidden_size
						__lowercase				:		Union[str, Any]												=				num_hidden_layers
						__lowercase				:		List[Any]												=				num_attention_heads
						__lowercase				:		Union[str, Any]												=				intermediate_multiple_size
						__lowercase				:		Optional[int]												=				hidden_act
						__lowercase				:		List[Any]												=				hidden_dropout
						__lowercase				:		Tuple												=				attention_dropout
						__lowercase				:		Optional[Any]												=				weight_tying
						__lowercase				:		Union[str, Any]												=				max_position_embeddings
						__lowercase				:		List[str]												=				type_vocab_size
						__lowercase				:		str												=				type_sequence_label_size
						__lowercase				:		str												=				initializer_range
						__lowercase				:		Tuple												=				num_labels
						__lowercase				:		List[str]												=				num_choices
						__lowercase				:		List[Any]												=				scope



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Tuple												=				ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size						)

						__lowercase				:		Union[str, Any]												=				None
						if self.use_input_mask:
								__lowercase				:		Any												=				random_attention_mask([self.batch_size, self.seq_length]						)

						__lowercase				:		Optional[int]												=				None
						if self.use_labels:
								__lowercase				:		Optional[Any]												=				ids_tensor([self.batch_size, self.seq_length]    ,   self.num_labels						)

						__lowercase				:		List[Any]												=				self.get_config()

						return config, input_ids, input_mask, token_labels



				def       snake_case    (     self					:	Tuple						):
						return GPTNeoXJapaneseConfig(
						    vocab_size=self.vocab_size    ,   hidden_size=self.hidden_size    ,   num_hidden_layers=self.num_hidden_layers    ,   num_attention_heads=self.num_attention_heads    ,   intermediate_multiple_size=self.intermediate_multiple_size    ,   hidden_act=self.hidden_act    ,   hidden_dropout=self.hidden_dropout    ,   attention_dropout=self.attention_dropout    ,   weight_tying=self.weight_tying    ,   max_position_embeddings=self.max_position_embeddings    ,   type_vocab_size=self.type_vocab_size    ,   is_decoder=lowercase__    ,   initializer_range=self.initializer_range    ,   )



				def       snake_case    (     self					:	Dict						):
						__lowercase						,__lowercase						,__lowercase						,__lowercase				:		Union[str, Any]												=				self.prepare_config_and_inputs()

						__lowercase				:		Any												=				True

						return config, input_ids, input_mask, token_labels



				def       snake_case    (     self					:	Tuple    ,   lowercase__					:	Union[str, Any]    ,   lowercase__					:	List[str]    ,   lowercase__					:	Tuple						):
						__lowercase				:		Any												=				GPTNeoXJapaneseModel(config=lowercase__						)
						model.to(lowercase__						)
						model.eval()
						__lowercase				:		List[str]												=				model(lowercase__    ,   attention_mask=lowercase__						)
						__lowercase				:		Tuple												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.hidden_size)						)



				def       snake_case    (     self					:	List[Any]    ,   lowercase__					:	List[str]    ,   lowercase__					:	Any    ,   lowercase__					:	int						):
						__lowercase				:		List[Any]												=				True
						__lowercase				:		Dict												=				GPTNeoXJapaneseModel(lowercase__						)
						model.to(lowercase__						)
						model.eval()
						__lowercase				:		Optional[Any]												=				model(lowercase__    ,   attention_mask=lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.hidden_size)						)



				def       snake_case    (     self					:	int    ,   lowercase__					:	Tuple    ,   lowercase__					:	Optional[int]    ,   lowercase__					:	Dict    ,   lowercase__					:	str						):
						__lowercase				:		List[Any]												=				GPTNeoXJapaneseForCausalLM(config=lowercase__						)
						model.to(lowercase__						)
						model.eval()
						__lowercase				:		Any												=				model(lowercase__    ,   attention_mask=lowercase__    ,   labels=lowercase__						)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.vocab_size)						)



				def       snake_case    (     self					:	str    ,   lowercase__					:	str    ,   lowercase__					:	Optional[int]    ,   lowercase__					:	Optional[Any]						):
						__lowercase				:		str												=				True
						__lowercase				:		Any												=				GPTNeoXJapaneseForCausalLM(config=lowercase__						)
						model.to(lowercase__						)
						model.eval()

						# first forward pass
						__lowercase				:		Any												=				model(lowercase__    ,   attention_mask=lowercase__    ,   use_cache=lowercase__						)
						__lowercase				:		List[str]												=				outputs.past_key_values

						# create hypothetical multiple next token and extent to next_input_ids
						__lowercase				:		Tuple												=				ids_tensor((self.batch_size, 3)    ,   config.vocab_size						)
						__lowercase				:		List[Any]												=				ids_tensor((self.batch_size, 3)    ,   vocab_size=2						)

						# append to next input_ids and
						__lowercase				:		Any												=				torch.cat([input_ids, next_tokens]    ,   dim=-1						)
						__lowercase				:		int												=				torch.cat([input_mask, next_mask]    ,   dim=-1						)

						__lowercase				:		Union[str, Any]												=				model(lowercase__    ,   attention_mask=lowercase__    ,   output_hidden_states=lowercase__						)
						__lowercase				:		List[str]												=				output_from_no_past["hidden_states"][0]
						__lowercase				:		Optional[Any]												=				model(
						    lowercase__    ,   attention_mask=lowercase__    ,   past_key_values=lowercase__    ,   output_hidden_states=lowercase__    ,   )["hidden_states"][0]

						# select random slice
						__lowercase				:		List[str]												=				ids_tensor((1,)    ,   output_from_past.shape[-1]						).item()
						__lowercase				:		Union[str, Any]												=				output_from_no_past[:, -3:, random_slice_idx].detach()
						__lowercase				:		Union[str, Any]												=				output_from_past[:, :, random_slice_idx].detach()

						self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]						)

						# test that outputs are equal for slice
						self.parent.assertTrue(torch.allclose(lowercase__    ,   lowercase__    ,   atol=1e-3						)						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		Union[str, Any]												=				self.prepare_config_and_inputs()
						__lowercase						,__lowercase						,__lowercase						,__lowercase				:		Tuple												=				config_and_inputs
						__lowercase				:		Dict												=				{"input_ids": input_ids, "attention_mask": input_mask}
						return config, inputs_dict





@require_torch
class       lowerCAmelCase__       (			lowerCAmelCase_  ,			lowerCAmelCase_  ,			unittest.TestCase    ):


				"""simple docstring"""





				__UpperCAmelCase :     str       =      (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
				__UpperCAmelCase :     Optional[int]       =      (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
				__UpperCAmelCase :     str       =      (
				    {'feature-extraction': GPTNeoXJapaneseModel, 'text-generation': GPTNeoXJapaneseForCausalLM}
				    if is_torch_available()
				    else {}
				)
				__UpperCAmelCase :     Optional[int]       =      False
				__UpperCAmelCase :     str       =      False
				__UpperCAmelCase :     Optional[int]       =      False
				__UpperCAmelCase :     str       =      False



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Any												=				GPTNeoXJapaneseModelTester(self						)
						__lowercase				:		List[str]												=				ConfigTester(self    ,   config_class=lowercase__    ,   hidden_size=3_7						)



				def       snake_case    (     self					:	List[str]						):
						self.config_tester.run_common_tests()



				def       snake_case    (     self					:	List[Any]						):
						__lowercase						,__lowercase						,__lowercase						,__lowercase				:		Any												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(lowercase__    ,   lowercase__    ,   lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						__lowercase						,__lowercase						,__lowercase						,__lowercase				:		Dict												=				self.model_tester.prepare_config_and_inputs_for_decoder()
						self.model_tester.create_and_check_model_as_decoder(lowercase__    ,   lowercase__    ,   lowercase__						)



				def       snake_case    (     self					:	Dict						):
						__lowercase						,__lowercase						,__lowercase						,__lowercase				:		int												=				self.model_tester.prepare_config_and_inputs_for_decoder()

						__lowercase				:		str												=				None

						self.model_tester.create_and_check_model_as_decoder(lowercase__    ,   lowercase__    ,   lowercase__						)



				def       snake_case    (     self					:	Tuple						):
						__lowercase						,__lowercase						,__lowercase						,__lowercase				:		Any												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_decoder_model_past_large_inputs(lowercase__    ,   lowercase__    ,   lowercase__						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		int												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_causal_lm(*lowercase__						)



				@slow
				def       snake_case    (     self					:	Tuple						):
						__lowercase				:		Optional[Any]												=				"abeja/gpt-neox-japanese-2.7b"

						__lowercase				:		List[str]												=				["データサイエンティストとは、", "100年後に必要とされる会社は、", "フルリモートの環境で働くために必要なことは、", "国境の長いトンネルを抜けると", "美味しい日本食といえば、"]

						__lowercase				:		Tuple												=				[
						    "データサイエンティストとは、データを分析し、ビジネスに役立つ知見を導き出す専門家のことです。",
						    "100年後に必要とされる会社は、「人」が中心の会社です。",
						    "フルリモートの環境で働くために必要なことは、「自分の時間をコントロールする」ことです。",
						    "国境の長いトンネルを抜けると、そこは雪国だった。",
						    "美味しい日本食といえば、やっぱりお寿司ですよね。",
						]

						__lowercase				:		Optional[int]												=				GPTNeoXJapaneseTokenizer.from_pretrained(lowercase__						)
						__lowercase				:		Optional[int]												=				GPTNeoXJapaneseForCausalLM.from_pretrained(lowercase__						)

						__lowercase				:		Dict												=				[]
						for prompt in prompts:
								__lowercase				:		List[str]												=				tokenizer(lowercase__    ,   return_tensors="pt"						).input_ids
								__lowercase				:		Any												=				model.generate(lowercase__    ,   max_length=5_0						)
								__lowercase				:		Any												=				tokenizer.batch_decode(lowercase__    ,   skip_special_tokens=lowercase__						)
								predicted_outputs += generated_string
						self.assertListEqual(lowercase__    ,   lowercase__						)






"""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__       :


				"""simple docstring"""





				def __init__(     self					:	Optional[Any]    ,   lowercase__					:	List[Any]    ,   lowercase__					:	int=1_3    ,   lowercase__					:	Optional[int]=7    ,   lowercase__					:	Any=True    ,   lowercase__					:	int=True    ,   lowercase__					:	List[Any]=True    ,   lowercase__					:	Union[str, Any]=True    ,   lowercase__					:	Any=9_9    ,   lowercase__					:	Tuple=[1, 1, 2]    ,   lowercase__					:	str=1    ,   lowercase__					:	Union[str, Any]=3_2    ,   lowercase__					:	int=4    ,   lowercase__					:	Dict=8    ,   lowercase__					:	Tuple=3_7    ,   lowercase__					:	int="gelu_new"    ,   lowercase__					:	Tuple=0.1    ,   lowercase__					:	int=0.1    ,   lowercase__					:	Dict=0.0    ,   lowercase__					:	int=5_1_2    ,   lowercase__					:	str=3    ,   lowercase__					:	List[Any]=0.0_2    ,   lowercase__					:	Any=3    ,   lowercase__					:	Union[str, Any]=4    ,   lowercase__					:	Tuple=None    ,   lowercase__					:	List[Any]=False    ,   ):
						__lowercase				:		Any												=				parent
						__lowercase				:		Tuple												=				batch_size
						__lowercase				:		Union[str, Any]												=				seq_length
						__lowercase				:		List[Any]												=				is_training
						__lowercase				:		Tuple												=				use_input_mask
						__lowercase				:		Optional[int]												=				use_token_type_ids
						__lowercase				:		List[Any]												=				use_labels
						__lowercase				:		Any												=				vocab_size
						__lowercase				:		Union[str, Any]												=				block_sizes
						__lowercase				:		Optional[Any]												=				num_decoder_layers
						__lowercase				:		str												=				d_model
						__lowercase				:		Tuple												=				n_head
						__lowercase				:		Any												=				d_head
						__lowercase				:		Dict												=				d_inner
						__lowercase				:		Optional[Any]												=				hidden_act
						__lowercase				:		int												=				hidden_dropout
						__lowercase				:		int												=				attention_dropout
						__lowercase				:		Tuple												=				activation_dropout
						__lowercase				:		int												=				max_position_embeddings
						__lowercase				:		Optional[Any]												=				type_vocab_size
						__lowercase				:		Union[str, Any]												=				2
						__lowercase				:		Optional[int]												=				num_labels
						__lowercase				:		List[str]												=				num_choices
						__lowercase				:		List[Any]												=				scope
						__lowercase				:		List[str]												=				initializer_std

						# Used in the tests to check the size of the first attention layer
						__lowercase				:		str												=				n_head
						# Used in the tests to check the size of the first hidden state
						__lowercase				:		List[str]												=				self.d_model
						# Used in the tests to check the number of output hidden states/attentions
						__lowercase				:		Optional[Any]												=				sum(self.block_sizes						) + (0 if base else self.num_decoder_layers)
						# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
						# the last hidden state of the first block (which is the first hidden state of the decoder).
						if not base:
								__lowercase				:		Dict												=				self.num_hidden_layers + 2



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Any												=				ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size						)

						__lowercase				:		Optional[int]												=				None
						if self.use_input_mask:
								__lowercase				:		Optional[int]												=				random_attention_mask([self.batch_size, self.seq_length]						)

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

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

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

						__lowercase				:		Optional[Any]												=				[input_ids, input_mask]
						__lowercase				:		int												=				model(lowercase__						)

						__lowercase				:		Tuple												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.d_model)						)

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

						__lowercase				:		str												=				False
						__lowercase				:		int												=				TFFunnelModel(config=lowercase__						)
						__lowercase				:		Dict												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.d_model)						)



				def       snake_case    (     self					:	Union[str, Any]    ,   lowercase__					:	List[Any]    ,   lowercase__					:	Union[str, Any]    ,   lowercase__					:	Optional[int]    ,   lowercase__					:	int    ,   lowercase__					:	str    ,   lowercase__					:	Dict    ,   lowercase__					:	Union[str, Any]    ,   ):
						__lowercase				:		List[str]												=				TFFunnelBaseModel(config=lowercase__						)
						__lowercase				:		int												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		List[Any]												=				model(lowercase__						)

						__lowercase				:		List[Any]												=				[input_ids, input_mask]
						__lowercase				:		Optional[int]												=				model(lowercase__						)

						__lowercase				:		Optional[Any]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 2, self.d_model)						)

						__lowercase				:		Any												=				False
						__lowercase				:		Any												=				TFFunnelBaseModel(config=lowercase__						)
						__lowercase				:		Union[str, Any]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 3, self.d_model)						)

						__lowercase				:		List[Any]												=				False
						__lowercase				:		Optional[int]												=				TFFunnelBaseModel(config=lowercase__						)
						__lowercase				:		Optional[int]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 2, self.d_model)						)



				def       snake_case    (     self					:	Optional[int]    ,   lowercase__					:	str    ,   lowercase__					:	Tuple    ,   lowercase__					:	Any    ,   lowercase__					:	List[Any]    ,   lowercase__					:	Dict    ,   lowercase__					:	List[str]    ,   lowercase__					:	Optional[Any]    ,   ):
						__lowercase				:		Tuple												=				TFFunnelForPreTraining(config=lowercase__						)
						__lowercase				:		Optional[int]												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		Union[str, Any]												=				model(lowercase__						)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length)						)



				def       snake_case    (     self					:	int    ,   lowercase__					:	List[Any]    ,   lowercase__					:	List[Any]    ,   lowercase__					:	Any    ,   lowercase__					:	int    ,   lowercase__					:	Any    ,   lowercase__					:	str    ,   lowercase__					:	Optional[Any]    ,   ):
						__lowercase				:		Optional[int]												=				TFFunnelForMaskedLM(config=lowercase__						)
						__lowercase				:		List[str]												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		Optional[int]												=				model(lowercase__						)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.vocab_size)						)



				def       snake_case    (     self					:	Union[str, Any]    ,   lowercase__					:	str    ,   lowercase__					:	Any    ,   lowercase__					:	Any    ,   lowercase__					:	Union[str, Any]    ,   lowercase__					:	Dict    ,   lowercase__					:	int    ,   lowercase__					:	int    ,   ):
						__lowercase				:		str												=				self.num_labels
						__lowercase				:		List[Any]												=				TFFunnelForSequenceClassification(config=lowercase__						)
						__lowercase				:		Union[str, Any]												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		int												=				model(lowercase__						)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)						)



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



				def       snake_case    (     self					:	Any    ,   lowercase__					:	Tuple    ,   lowercase__					:	str    ,   lowercase__					:	List[str]    ,   lowercase__					:	Optional[int]    ,   lowercase__					:	Dict    ,   lowercase__					:	Any    ,   lowercase__					:	Optional[int]    ,   ):
						__lowercase				:		Tuple												=				self.num_labels
						__lowercase				:		int												=				TFFunnelForTokenClassification(config=lowercase__						)
						__lowercase				:		Optional[Any]												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		int												=				model(lowercase__						)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.num_labels)						)



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





@require_tf
class       lowerCAmelCase__       (			lowerCAmelCase_  ,			lowerCAmelCase_  ,			unittest.TestCase    ):


				"""simple docstring"""





				__UpperCAmelCase :     List[Any]       =      (
				    (
				        TFFunnelModel,
				        TFFunnelForMaskedLM,
				        TFFunnelForPreTraining,
				        TFFunnelForQuestionAnswering,
				        TFFunnelForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				__UpperCAmelCase :     Optional[int]       =      (
				    {
				        "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
				        "fill-mask": TFFunnelForMaskedLM,
				        "question-answering": TFFunnelForQuestionAnswering,
				        "text-classification": TFFunnelForSequenceClassification,
				        "token-classification": TFFunnelForTokenClassification,
				        "zero-shot": TFFunnelForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				__UpperCAmelCase :     Dict       =      False
				__UpperCAmelCase :     Union[str, Any]       =      False



				def       snake_case    (     self					:	Dict						):
						__lowercase				:		List[Any]												=				TFFunnelModelTester(self						)
						__lowercase				:		Tuple												=				ConfigTester(self    ,   config_class=lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						self.config_tester.run_common_tests()



				def       snake_case    (     self					:	Any						):
						__lowercase				:		Optional[int]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Optional[int]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*lowercase__						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		List[str]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*lowercase__						)



				def       snake_case    (     self					:	Any						):
						__lowercase				:		Any												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*lowercase__						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		Union[str, Any]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*lowercase__						)





@require_tf
class       lowerCAmelCase__       (			lowerCAmelCase_  ,			unittest.TestCase    ):


				"""simple docstring"""





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



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Optional[int]												=				TFFunnelModelTester(self    ,   base=lowercase__						)
						__lowercase				:		List[Any]												=				ConfigTester(self    ,   config_class=lowercase__						)



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



				def       snake_case    (     self					:	List[str]						):
						__lowercase				:		Any												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*lowercase__						)



				def       snake_case    (     self					:	Union[str, Any]						):
						__lowercase				:		Tuple												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Optional[Any]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*lowercase__						)
