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

							"""simple docstring"""






							def __init__(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_=13     ,	SCREAMING_SNAKE_CASE_=7     ,	SCREAMING_SNAKE_CASE_=True     ,	SCREAMING_SNAKE_CASE_=True     ,	SCREAMING_SNAKE_CASE_=True     ,	SCREAMING_SNAKE_CASE_=True     ,	SCREAMING_SNAKE_CASE_=99     ,	SCREAMING_SNAKE_CASE_=[1, 1, 2]     ,	SCREAMING_SNAKE_CASE_=1     ,	SCREAMING_SNAKE_CASE_=32     ,	SCREAMING_SNAKE_CASE_=4     ,	SCREAMING_SNAKE_CASE_=8     ,	SCREAMING_SNAKE_CASE_=37     ,	SCREAMING_SNAKE_CASE_="gelu_new"     ,	SCREAMING_SNAKE_CASE_=0.1     ,	SCREAMING_SNAKE_CASE_=0.1     ,	SCREAMING_SNAKE_CASE_=0.0     ,	SCREAMING_SNAKE_CASE_=512     ,	SCREAMING_SNAKE_CASE_=3     ,	SCREAMING_SNAKE_CASE_=0.0_2     ,	SCREAMING_SNAKE_CASE_=3     ,	SCREAMING_SNAKE_CASE_=4     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=False     ,	)->   List[Any]:





													'''simple docstring'''






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

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



							def     A__		(  self			)->   str:





													'''simple docstring'''






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

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

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

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

													__UpperCamelCase       =			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     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   Optional[Any]:





													'''simple docstring'''






													__UpperCamelCase       =			TFFunnelModel(config=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)

													__UpperCamelCase       =			[input_ids, input_mask]
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)

													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)
													self.parent.assertEqual(result.last_hidden_state.shape     ,	(self.batch_size, self.seq_length, self.d_model)			)

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

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



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   List[str]:





													'''simple docstring'''






													__UpperCamelCase       =			TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)

													__UpperCamelCase       =			[input_ids, input_mask]
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)

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

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

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



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   str:





													'''simple docstring'''






													__UpperCamelCase       =			TFFunnelForPreTraining(config=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)
													self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.seq_length)			)



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   Optional[Any]:





													'''simple docstring'''






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



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   int:





													'''simple docstring'''






													__UpperCamelCase       =			self.num_labels
													__UpperCamelCase       =			TFFunnelForSequenceClassification(config=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)
													self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.num_labels)			)



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   Optional[Any]:





													'''simple docstring'''






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



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   Dict:





													'''simple docstring'''






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



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	)->   str:





													'''simple docstring'''






													__UpperCamelCase       =			TFFunnelForQuestionAnswering(config=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_			)
													self.parent.assertEqual(result.start_logits.shape     ,	(self.batch_size, self.seq_length)			)
													self.parent.assertEqual(result.end_logits.shape     ,	(self.batch_size, self.seq_length)			)



							def     A__		(  self			)->   Any:





													'''simple docstring'''






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






@require_tf
class        SCREAMING_SNAKE_CASE__    (							SCREAMING_SNAKE_CASE_   ,		SCREAMING_SNAKE_CASE_   ,		unittest.TestCase    ):

							"""simple docstring"""






							_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			)->   Dict:





													'''simple docstring'''






													__UpperCamelCase       =			TFFunnelModelTester(self			)
													__UpperCamelCase       =			ConfigTester(self     ,	config_class=SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   Any:





													'''simple docstring'''






													self.config_tester.run_common_tests()



							def     A__		(  self			)->   int:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   Union[str, Any]:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   List[str]:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   str:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_			)






@require_tf
class        SCREAMING_SNAKE_CASE__    (							SCREAMING_SNAKE_CASE_   ,		unittest.TestCase    ):

							"""simple docstring"""






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



							def     A__		(  self			)->   Optional[Any]:





													'''simple docstring'''






													__UpperCamelCase       =			TFFunnelModelTester(self     ,	base=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			ConfigTester(self     ,	config_class=SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   int:





													'''simple docstring'''






													self.config_tester.run_common_tests()



							def     A__		(  self			)->   List[str]:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_base_model(*SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   Optional[int]:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_			)



							def     A__		(  self			)->   Union[str, Any]:





													'''simple docstring'''






													__UpperCamelCase       =			self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_			)






# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import platform
import sys


lowercase__							:							List[str]									=			"3"

print("Python version:", sys.version)

print("OS platform:", platform.platform())
print("OS architecture:", platform.machine())

try:
				import torch

				print("Torch version:", torch.__version__)
				print("Cuda available:", torch.cuda.is_available())
				print("Cuda version:", torch.version.cuda)
				print("CuDNN version:", torch.backends.cudnn.version())
				print("Number of GPUs available:", torch.cuda.device_count())
except ImportError:
				print("Torch version:", None)

try:
				import transformers

				print("transformers version:", transformers.__version__)
except ImportError:
				print("transformers version:", None)




