






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






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

										# Used in the tests to check the size of the first attention layer
										lowercase    :      List[str]       = n_head
										# Used in the tests to check the size of the first hidden state
										lowercase    :      int       = self.d_model
										# Used in the tests to check the number of output hidden states/attentions
										lowercase    :      int       = 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  :Any				)      ->Any:
										lowercase    :      str       = ids_tensor([self.batch_size, self.seq_length]			, self.vocab_size				)

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

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

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

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

										lowercase    :      Optional[int]       = [input_ids, input_mask]
										lowercase    :      Tuple       = model(lowercase_				)

										lowercase    :      List[Any]       = model(lowercase_				)
										self.parent.assertEqual(result.last_hidden_state.shape			, (self.batch_size, self.seq_length, self.d_model)				)

										lowercase    :      Tuple       = False
										lowercase    :      Optional[Any]       = TFFunnelModel(config=lowercase_				)
										lowercase    :      Any       = 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  :List[str]			, __magic_name__  :List[Any]			, __magic_name__  :Any			, __magic_name__  :str			, __magic_name__  :int			, __magic_name__  :Optional[Any]			, __magic_name__  :Dict			, __magic_name__  :Any			, )      ->List[str]:
										lowercase    :      Tuple       = TFFunnelBaseModel(config=lowercase_				)
										lowercase    :      List[str]       = {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										lowercase    :      int       = model(lowercase_				)

										lowercase    :      Optional[Any]       = [input_ids, input_mask]
										lowercase    :      Any       = model(lowercase_				)

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

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

										lowercase    :      Tuple       = False
										lowercase    :      Union[str, Any]       = TFFunnelBaseModel(config=lowercase_				)
										lowercase    :      Optional[Any]       = model(lowercase_				)
										self.parent.assertEqual(result.last_hidden_state.shape			, (self.batch_size, 2, self.d_model)				)






						def      __snake_case      (		self  :List[str]			, __magic_name__  :Tuple			, __magic_name__  :Tuple			, __magic_name__  :Optional[int]			, __magic_name__  :List[str]			, __magic_name__  :Tuple			, __magic_name__  :List[Any]			, __magic_name__  :Optional[Any]			, )      ->List[str]:
										lowercase    :      Tuple       = TFFunnelForPreTraining(config=lowercase_				)
										lowercase    :      Optional[int]       = {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										lowercase    :      Tuple       = model(lowercase_				)
										self.parent.assertEqual(result.logits.shape			, (self.batch_size, self.seq_length)				)






						def      __snake_case      (		self  :Optional[Any]			, __magic_name__  :Any			, __magic_name__  :Dict			, __magic_name__  :Any			, __magic_name__  :List[str]			, __magic_name__  :List[Any]			, __magic_name__  :Tuple			, __magic_name__  :List[str]			, )      ->Optional[int]:
										lowercase    :      str       = TFFunnelForMaskedLM(config=lowercase_				)
										lowercase    :      Optional[int]       = {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										lowercase    :      Tuple       = model(lowercase_				)
										self.parent.assertEqual(result.logits.shape			, (self.batch_size, self.seq_length, self.vocab_size)				)






						def      __snake_case      (		self  :Optional[int]			, __magic_name__  :Any			, __magic_name__  :Optional[int]			, __magic_name__  :Tuple			, __magic_name__  :List[str]			, __magic_name__  :Union[str, Any]			, __magic_name__  :int			, __magic_name__  :Optional[Any]			, )      ->Union[str, Any]:
										lowercase    :      str       = self.num_labels
										lowercase    :      Union[str, Any]       = TFFunnelForSequenceClassification(config=lowercase_				)
										lowercase    :      str       = {"""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  :int			, __magic_name__  :Dict			, __magic_name__  :Tuple			, __magic_name__  :Union[str, Any]			, __magic_name__  :int			, __magic_name__  :Any			, __magic_name__  :Optional[Any]			, __magic_name__  :str			, )      ->List[str]:
										lowercase    :      Optional[int]       = self.num_choices
										lowercase    :      Tuple       = TFFunnelForMultipleChoice(config=lowercase_				)
										lowercase    :      List[str]       = tf.tile(tf.expand_dims(lowercase_			, 1				)			, (1, self.num_choices, 1)				)
										lowercase    :      List[str]       = 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    :      Union[str, Any]       = {
										    """input_ids""": multiple_choice_inputs_ids,
										    """attention_mask""": multiple_choice_input_mask,
										    """token_type_ids""": multiple_choice_token_type_ids,
										}
										lowercase    :      Tuple       = model(lowercase_				)
										self.parent.assertEqual(result.logits.shape			, (self.batch_size, self.num_choices)				)






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






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


@require_tf
class      UpperCamelCase		(lowercase__						,						lowercase__						,						unittest.TestCase     ):
						_SCREAMING_SNAKE_CASE  : Dict												=		(
						    (
						        TFFunnelModel,
						        TFFunnelForMaskedLM,
						        TFFunnelForPreTraining,
						        TFFunnelForQuestionAnswering,
						        TFFunnelForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						_SCREAMING_SNAKE_CASE  : List[str]												=		(
						    {
						        """feature-extraction""": (TFFunnelBaseModel, TFFunnelModel),
						        """fill-mask""": TFFunnelForMaskedLM,
						        """question-answering""": TFFunnelForQuestionAnswering,
						        """text-classification""": TFFunnelForSequenceClassification,
						        """token-classification""": TFFunnelForTokenClassification,
						        """zero-shot""": TFFunnelForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						_SCREAMING_SNAKE_CASE  : Tuple												=		False
						_SCREAMING_SNAKE_CASE  : Union[str, Any]												=		False






						def      __snake_case      (		self  :List[Any]				)      ->List[str]:
										lowercase    :      Any       = TFFunnelModelTester(self				)
										lowercase    :      Dict       = ConfigTester(self			, config_class=lowercase_				)






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






						def      __snake_case      (		self  :Optional[int]				)      ->List[str]:
										lowercase    :      Optional[Any]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowercase_				)






						def      __snake_case      (		self  :Any				)      ->Union[str, Any]:
										lowercase    :      Optional[Any]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*lowercase_				)






						def      __snake_case      (		self  :str				)      ->Optional[int]:
										lowercase    :      Optional[Any]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*lowercase_				)






						def      __snake_case      (		self  :Any				)      ->Optional[int]:
										lowercase    :      int       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*lowercase_				)






						def      __snake_case      (		self  :Optional[Any]				)      ->int:
										lowercase    :      Union[str, Any]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowercase_				)


@require_tf
class      UpperCamelCase		(lowercase__						,						unittest.TestCase     ):
						_SCREAMING_SNAKE_CASE  : Optional[int]												=		(
						    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
						)
						_SCREAMING_SNAKE_CASE  : Optional[Any]												=		False
						_SCREAMING_SNAKE_CASE  : int												=		False






						def      __snake_case      (		self  :Optional[Any]				)      ->Optional[int]:
										lowercase    :      List[str]       = TFFunnelModelTester(self			, base=lowercase_				)
										lowercase    :      Tuple       = ConfigTester(self			, config_class=lowercase_				)






						def      __snake_case      (		self  :int				)      ->Optional[Any]:
										self.config_tester.run_common_tests()






						def      __snake_case      (		self  :List[Any]				)      ->str:
										lowercase    :      Optional[Any]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_base_model(*lowercase_				)






						def      __snake_case      (		self  :List[Any]				)      ->Any:
										lowercase    :      List[str]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*lowercase_				)






						def      __snake_case      (		self  :Any				)      ->List[str]:
										lowercase    :      Optional[int]       = self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*lowercase_				)




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_lowerCAmelCase:						Optional[Any]   				=       {
    'configuration_swiftformer': [
        'SWIFTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'SwiftFormerConfig',
        'SwiftFormerOnnxConfig',
    ]
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCAmelCase:						List[str]   				=       [
	    'SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'SwiftFormerForImageClassification',
	    'SwiftFormerModel',
	    'SwiftFormerPreTrainedModel',
	]

if TYPE_CHECKING:
	from .configuration_swiftformer import (
	    SWIFTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    SwiftFormerConfig,
	    SwiftFormerOnnxConfig,
	)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_swiftformer import (
		    SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    SwiftFormerForImageClassification,
		    SwiftFormerModel,
		    SwiftFormerPreTrainedModel,
		)

else:
	import sys

	_lowerCAmelCase:						List[Any]   				=       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

