






'''simple docstring'''







import inspect
import os
import re

from transformers.configuration_utils import PretrainedConfig
from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
_A			:    Tuple					  ='''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
_A			:    List[str]					  =direct_transformers_import(PATH_TO_TRANSFORMERS)

_A			:    int					  =transformers.models.auto.configuration_auto.CONFIG_MAPPING

_A			:    List[str]					  ={
    # used to compute the property `self.chunk_length`
    '''EncodecConfig''': ['''overlap'''],
    # used as `self.bert_model = BertModel(config, ...)`
    '''DPRConfig''': True,
    # not used in modeling files, but it's an important information
    '''FSMTConfig''': ['''langs'''],
    # used internally in the configuration class file
    '''GPTNeoConfig''': ['''attention_types'''],
    # used internally in the configuration class file
    '''EsmConfig''': ['''is_folding_model'''],
    # used during training (despite we don't have training script for these models yet)
    '''Mask2FormerConfig''': ['''ignore_value'''],
    # `ignore_value` used during training (despite we don't have training script for these models yet)
    # `norm` used in conversion script (despite not using in the modeling file)
    '''OneFormerConfig''': ['''ignore_value''', '''norm'''],
    # used during preprocessing and collation, see `collating_graphormer.py`
    '''GraphormerConfig''': ['''spatial_pos_max'''],
    # used internally in the configuration class file
    '''T5Config''': ['''feed_forward_proj'''],
    # used internally in the configuration class file
    # `tokenizer_class` get default value `T5Tokenizer` intentionally
    '''MT5Config''': ['''feed_forward_proj''', '''tokenizer_class'''],
    '''UMT5Config''': ['''feed_forward_proj''', '''tokenizer_class'''],
    # used internally in the configuration class file
    '''LongT5Config''': ['''feed_forward_proj'''],
    # used internally in the configuration class file
    '''SwitchTransformersConfig''': ['''feed_forward_proj'''],
    # having default values other than `1e-5` - we can't fix them without breaking
    '''BioGptConfig''': ['''layer_norm_eps'''],
    # having default values other than `1e-5` - we can't fix them without breaking
    '''GLPNConfig''': ['''layer_norm_eps'''],
    # having default values other than `1e-5` - we can't fix them without breaking
    '''SegformerConfig''': ['''layer_norm_eps'''],
    # having default values other than `1e-5` - we can't fix them without breaking
    '''CvtConfig''': ['''layer_norm_eps'''],
    # having default values other than `1e-5` - we can't fix them without breaking
    '''PerceiverConfig''': ['''layer_norm_eps'''],
    # used internally to calculate the feature size
    '''InformerConfig''': ['''num_static_real_features''', '''num_time_features'''],
    # used internally to calculate the feature size
    '''TimeSeriesTransformerConfig''': ['''num_static_real_features''', '''num_time_features'''],
    # used internally to calculate the feature size
    '''AutoformerConfig''': ['''num_static_real_features''', '''num_time_features'''],
    # used internally to calculate `mlp_dim`
    '''SamVisionConfig''': ['''mlp_ratio'''],
    # For (head) training, but so far not implemented
    '''ClapAudioConfig''': ['''num_classes'''],
    # Not used, but providing useful information to users
    '''SpeechT5HifiGanConfig''': ['''sampling_rate'''],
}


# TODO (ydshieh): Check the failing cases, try to fix them or move some cases to the above block once we are sure
SPECIAL_CASES_TO_ALLOW.update(
    {
        '''CLIPSegConfig''': True,
        '''DeformableDetrConfig''': True,
        '''DetaConfig''': True,
        '''DinatConfig''': True,
        '''DonutSwinConfig''': True,
        '''EfficientFormerConfig''': True,
        '''FSMTConfig''': True,
        '''JukeboxConfig''': True,
        '''LayoutLMv2Config''': True,
        '''MaskFormerSwinConfig''': True,
        '''MT5Config''': True,
        '''NatConfig''': True,
        '''OneFormerConfig''': True,
        '''PerceiverConfig''': True,
        '''RagConfig''': True,
        '''SpeechT5Config''': True,
        '''SwinConfig''': True,
        '''Swin2SRConfig''': True,
        '''Swinv2Config''': True,
        '''SwitchTransformersConfig''': True,
        '''TableTransformerConfig''': True,
        '''TapasConfig''': True,
        '''TransfoXLConfig''': True,
        '''UniSpeechConfig''': True,
        '''UniSpeechSatConfig''': True,
        '''WavLMConfig''': True,
        '''WhisperConfig''': True,
        # TODO: @Arthur (for `alignment_head` and `alignment_layer`)
        '''JukeboxPriorConfig''': True,
        # TODO: @Younes (for `is_decoder`)
        '''Pix2StructTextConfig''': True,
    }
)





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase   )   -> List[str]:
							lowerCamelCase__      :			Optional[Any] 						= False
							for attribute in attributes:
														for modeling_source in source_strings:
																					# check if we can find `config.xxx`, `getattr(config, "xxx", ...)` or `getattr(self.config, "xxx", ...)`
																					if (
																					    f'''config.{attribute}''' in modeling_source
																					    or f'''getattr(config, "{attribute}"''' in modeling_source
																					    or f'''getattr(self.config, "{attribute}"''' in modeling_source
																					):
																												lowerCamelCase__      :			Tuple 						= True
																					# Deal with multi-line cases
																					elif (
																					    re.search(
																					        rf'''getattr[ \t\v\n\r\f]*\([ \t\v\n\r\f]*(self\.)?config,[ \t\v\n\r\f]*"{attribute}"'''       ,    snake_case__       ,    )
																					    is not None
																					):
																												lowerCamelCase__      :			int 						= True
																					# `SequenceSummary` is called with `SequenceSummary(config)`
																					elif attribute in [
																					    "summary_type",
																					    "summary_use_proj",
																					    "summary_activation",
																					    "summary_last_dropout",
																					    "summary_proj_to_labels",
																					    "summary_first_dropout",
																					]:
																												if "SequenceSummary" in modeling_source:
																																			lowerCamelCase__      :			Any 						= True
																					if attribute_used:
																												break
														if attribute_used:
																					break

    # common and important attributes, even if they do not always appear in the modeling files
							lowerCamelCase__      :			Tuple 						= [
							    """bos_index""",
							    """eos_index""",
							    """pad_index""",
							    """unk_index""",
							    """mask_index""",
							    """image_size""",
							    """use_cache""",
							    """out_features""",
							    """out_indices""",
							]
							lowerCamelCase__      :			List[Any] 						= ["""encoder_no_repeat_ngram_size"""]

							# Special cases to be allowed
							lowerCamelCase__      :			Optional[int] 						= True
							if not attribute_used:
														lowerCamelCase__      :			Union[str, Any] 						= False
														for attribute in attributes:
																					# Allow if the default value in the configuration class is different from the one in `PretrainedConfig`
																					if attribute in ["is_encoder_decoder"] and default_value is True:
																												lowerCamelCase__      :			Any 						= True
																					elif attribute in ["tie_word_embeddings"] and default_value is False:
																												lowerCamelCase__      :			List[str] 						= True

																					# Allow cases without checking the default value in the configuration class
																					elif attribute in attributes_to_allow + attributes_used_in_generation:
																												lowerCamelCase__      :			List[Any] 						= True
																					elif attribute.endswith("""_token_id"""   ):
																												lowerCamelCase__      :			Tuple 						= True

																					# configuration class specific cases
																					if not case_allowed:
																												lowerCamelCase__      :			List[str] 						= SPECIAL_CASES_TO_ALLOW.get(config_class.__name__       ,    []   )
																												lowerCamelCase__      :			List[str] 						= allowed_cases is True or attribute in allowed_cases

							return attribute_used or case_allowed





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase   )   -> List[str]:
							lowerCamelCase__      :			Dict 						= dict(inspect.signature(config_class.__init__   ).parameters   )
							lowerCamelCase__      :			Tuple 						= [x for x in list(signature.keys()   ) if x not in ["""self""", """kwargs"""]]
							lowerCamelCase__      :			int 						= [signature[param].default for param in parameter_names]

							# If `attribute_map` exists, an attribute can have different names to be used in the modeling files, and as long
							# as one variant is used, the test should pass
							lowerCamelCase__      :			Union[str, Any] 						= {}
							if len(config_class.attribute_map   ) > 0:
														lowerCamelCase__      :			List[str] 						= {v: k for k, v in config_class.attribute_map.items()}

							# Get the path to modeling source files
							lowerCamelCase__      :			Union[str, Any] 						= inspect.getsourcefile(snake_case__   )
							lowerCamelCase__      :			Optional[Any] 						= os.path.dirname(snake_case__   )
							# Let's check against all frameworks: as long as one framework uses an attribute, we are good.
							lowerCamelCase__      :			Union[str, Any] 						= [os.path.join(snake_case__       ,    snake_case__   ) for fn in os.listdir(snake_case__   ) if fn.startswith("""modeling_"""   )]

							# Get the source code strings
							lowerCamelCase__      :			Union[str, Any] 						= []
							for path in modeling_paths:
														if os.path.isfile(snake_case__   ):
																					with open(snake_case__   ) as fp:
																												modeling_sources.append(fp.read()   )

							lowerCamelCase__      :			Optional[int] 						= []
							for config_param, default_value in zip(snake_case__       ,    snake_case__   ):
														# `attributes` here is all the variant names for `config_param`
														lowerCamelCase__      :			int 						= [config_param]
														# some configuration classes have non-empty `attribute_map`, and both names could be used in the
														# corresponding modeling files. As long as one of them appears, it is fine.
														if config_param in reversed_attribute_map:
																					attributes.append(reversed_attribute_map[config_param]   )

														if not check_attribute_being_used(snake_case__       ,    snake_case__       ,    snake_case__       ,    snake_case__   ):
																					unused_attributes.append(attributes[0]   )

							return sorted(snake_case__   )





def 				SCREAMING_SNAKE_CASE_ ()   -> Union[str, Any]:
							lowerCamelCase__      :			Dict 						= {}
							for _config_class in list(CONFIG_MAPPING.values()   ):
														# Skip deprecated models
														if "models.deprecated" in _config_class.__module__:
																					continue
														# Some config classes are not in `CONFIG_MAPPING` (e.g. `CLIPVisionConfig`, `Blip2VisionConfig`, etc.)
														lowerCamelCase__      :			str 						= [
														    cls
														    for name, cls in inspect.getmembers(
														        inspect.getmodule(_config_class   )       ,    lambda UpperCamelCase   : inspect.isclass(snake_case__   )
														        and issubclass(snake_case__       ,    snake_case__   )
														        and inspect.getmodule(snake_case__   ) == inspect.getmodule(_config_class   )       ,    )
														]
														for config_class in config_classes_in_module:
																					lowerCamelCase__      :			str 						= check_config_attributes_being_used(snake_case__   )
																					if len(snake_case__   ) > 0:
																												lowerCamelCase__      :			Union[str, Any] 						= unused_attributes

							if len(snake_case__   ) > 0:
														lowerCamelCase__      :			Dict 						= """The following configuration classes contain unused attributes in the corresponding modeling files:\n"""
														for name, attributes in configs_with_unused_attributes.items():
																					error += f'''{name}: {attributes}\n'''

														raise ValueError(snake_case__   )


if __name__ == "__main__":
							check_config_attributes()









'''simple docstring'''







from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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 (
			    TFConvBertForMaskedLM,
			    TFConvBertForMultipleChoice,
			    TFConvBertForQuestionAnswering,
			    TFConvBertForSequenceClassification,
			    TFConvBertForTokenClassification,
			    TFConvBertModel,
			)

class _lowercase			:




							def __init__(							self:       int    ,							UpperCamelCase__:       Dict    ,							UpperCamelCase__:       List[str]=13    ,							UpperCamelCase__:       Union[str, Any]=7    ,							UpperCamelCase__:       Union[str, Any]=True    ,							UpperCamelCase__:       List[Any]=True    ,							UpperCamelCase__:       Optional[Any]=True    ,							UpperCamelCase__:       int=True    ,							UpperCamelCase__:       List[Any]=99    ,							UpperCamelCase__:       Tuple=32    ,							UpperCamelCase__:       List[str]=2    ,							UpperCamelCase__:       Optional[Any]=4    ,							UpperCamelCase__:       Optional[int]=37    ,							UpperCamelCase__:       Any="gelu"    ,							UpperCamelCase__:       Any=0.1    ,							UpperCamelCase__:       int=0.1    ,							UpperCamelCase__:       Optional[Any]=512    ,							UpperCamelCase__:       List[str]=16    ,							UpperCamelCase__:       Optional[int]=2    ,							UpperCamelCase__:       Dict=0.02    ,							UpperCamelCase__:       Tuple=3    ,							UpperCamelCase__:       Optional[int]=4    ,							UpperCamelCase__:       Union[str, Any]=None    ,							):
														lowerCamelCase__      :			Dict 						= parent
														lowerCamelCase__      :			Union[str, Any] 						= 13
														lowerCamelCase__      :			Any 						= 7
														lowerCamelCase__      :			int 						= True
														lowerCamelCase__      :			Optional[Any] 						= True
														lowerCamelCase__      :			Dict 						= True
														lowerCamelCase__      :			List[str] 						= True
														lowerCamelCase__      :			str 						= 99
														lowerCamelCase__      :			Dict 						= 384
														lowerCamelCase__      :			Optional[Any] 						= 2
														lowerCamelCase__      :			Optional[int] 						= 4
														lowerCamelCase__      :			Optional[Any] 						= 37
														lowerCamelCase__      :			Union[str, Any] 						= """gelu"""
														lowerCamelCase__      :			int 						= 0.1
														lowerCamelCase__      :			Optional[Any] 						= 0.1
														lowerCamelCase__      :			List[Any] 						= 512
														lowerCamelCase__      :			Optional[Any] 						= 16
														lowerCamelCase__      :			Any 						= 2
														lowerCamelCase__      :			Optional[Any] 						= 0.02
														lowerCamelCase__      :			int 						= 3
														lowerCamelCase__      :			List[str] 						= 4
														lowerCamelCase__      :			Any 						= 128
														lowerCamelCase__      :			List[Any] 						= 2
														lowerCamelCase__      :			Optional[Any] 						= 9
														lowerCamelCase__      :			Any 						= 1
														lowerCamelCase__      :			Optional[int] 						= None




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

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

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

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

														lowerCamelCase__      :			List[Any] 						= ConvBertConfig(
														    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_size=self.intermediate_size    ,							hidden_act=self.hidden_act    ,							hidden_dropout_prob=self.hidden_dropout_prob    ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,							max_position_embeddings=self.max_position_embeddings    ,							type_vocab_size=self.type_vocab_size    ,							initializer_range=self.initializer_range    ,							return_dict=UpperCamelCase__    ,							)

														return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




							def 	lowerCamelCase_       (							self:       Optional[int]    ,							UpperCamelCase__:       Dict    ,							UpperCamelCase__:       List[str]    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       Any  ):
														lowerCamelCase__      :			List[Any] 						= TFConvBertModel(config=UpperCamelCase__  )
														lowerCamelCase__      :			str 						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

														lowerCamelCase__      :			List[str] 						= [input_ids, input_mask]
														lowerCamelCase__      :			Optional[int] 						= model(UpperCamelCase__  )

														lowerCamelCase__      :			Optional[Any] 						= model(UpperCamelCase__  )

														self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)  )




							def 	lowerCamelCase_       (							self:       Any    ,							UpperCamelCase__:       Tuple    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       List[str]    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Tuple  ):
														lowerCamelCase__      :			int 						= TFConvBertForMaskedLM(config=UpperCamelCase__  )
														lowerCamelCase__      :			Tuple 						= {
														    """input_ids""": input_ids,
														    """attention_mask""": input_mask,
														    """token_type_ids""": token_type_ids,
														}
														lowerCamelCase__      :			int 						= model(UpperCamelCase__  )
														self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.seq_length, self.vocab_size)  )




							def 	lowerCamelCase_       (							self:       str    ,							UpperCamelCase__:       List[str]    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       Union[str, Any]  ):
														lowerCamelCase__      :			int 						= self.num_labels
														lowerCamelCase__      :			Dict 						= TFConvBertForSequenceClassification(config=UpperCamelCase__  )
														lowerCamelCase__      :			Dict 						= {
														    """input_ids""": input_ids,
														    """attention_mask""": input_mask,
														    """token_type_ids""": token_type_ids,
														}

														lowerCamelCase__      :			Optional[Any] 						= model(UpperCamelCase__  )
														self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_labels)  )




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




							def 	lowerCamelCase_       (							self:       str    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       Tuple    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       Any    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       int  ):
														lowerCamelCase__      :			List[Any] 						= self.num_labels
														lowerCamelCase__      :			List[str] 						= TFConvBertForTokenClassification(config=UpperCamelCase__  )
														lowerCamelCase__      :			Optional[Any] 						= {
														    """input_ids""": input_ids,
														    """attention_mask""": input_mask,
														    """token_type_ids""": token_type_ids,
														}
														lowerCamelCase__      :			Tuple 						= model(UpperCamelCase__  )
														self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.seq_length, self.num_labels)  )




							def 	lowerCamelCase_       (							self:       Any    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       Tuple    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       Optional[Any]    ,							UpperCamelCase__:       List[str]    ,							UpperCamelCase__:       Optional[Any]  ):
														lowerCamelCase__      :			Optional[int] 						= TFConvBertForQuestionAnswering(config=UpperCamelCase__  )
														lowerCamelCase__      :			int 						= {
														    """input_ids""": input_ids,
														    """attention_mask""": input_mask,
														    """token_type_ids""": token_type_ids,
														}

														lowerCamelCase__      :			Optional[int] 						= model(UpperCamelCase__  )
														self.parent.assertEqual(result.start_logits.shape    ,							(self.batch_size, self.seq_length)  )
														self.parent.assertEqual(result.end_logits.shape    ,							(self.batch_size, self.seq_length)  )




							def 	lowerCamelCase_       (							self:       Optional[Any]  ):
														lowerCamelCase__      :			str 						= self.prepare_config_and_inputs()
														(
														    (
														    lowerCamelCase__
														)						,	(
														    lowerCamelCase__
														)						,	(
														    lowerCamelCase__
														)						,	(
														    lowerCamelCase__
														)						,	(
														    lowerCamelCase__
														)						,	(
														    lowerCamelCase__
														)						,	(
														    lowerCamelCase__
														)						,	
														)      :			str 						= config_and_inputs
														lowerCamelCase__      :			Optional[Any] 						= {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
														return config, inputs_dict



@require_tf
class _lowercase			(       _lowercase       ,   _lowercase       ,   unittest.TestCase	):
							a          = (
							    (
							        TFConvBertModel,
							        TFConvBertForMaskedLM,
							        TFConvBertForQuestionAnswering,
							        TFConvBertForSequenceClassification,
							        TFConvBertForTokenClassification,
							        TFConvBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							a          = (
							    {
							        """feature-extraction""": TFConvBertModel,
							        """fill-mask""": TFConvBertForMaskedLM,
							        """question-answering""": TFConvBertForQuestionAnswering,
							        """text-classification""": TFConvBertForSequenceClassification,
							        """token-classification""": TFConvBertForTokenClassification,
							        """zero-shot""": TFConvBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							a          = False
							a          = False
							a          = False




							def 	lowerCamelCase_       (							self:       str  ):
														lowerCamelCase__      :			Dict 						= TFConvBertModelTester(self  )
														lowerCamelCase__      :			Dict 						= ConfigTester(self    ,							config_class=UpperCamelCase__    ,							hidden_size=37  )




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




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														lowerCamelCase__      :			List[str] 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Any  ):
														lowerCamelCase__      :			Dict 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Tuple  ):
														lowerCamelCase__      :			int 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														lowerCamelCase__      :			int 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Any  ):
														lowerCamelCase__      :			Union[str, Any] 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       str  ):
														lowerCamelCase__      :			Tuple 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__  )




							@slow
							def 	lowerCamelCase_       (							self:       Optional[Any]  ):
														lowerCamelCase__						,	lowerCamelCase__      :			List[str] 						= self.model_tester.prepare_config_and_inputs_for_common()
														lowerCamelCase__      :			Dict 						= True
														lowerCamelCase__      :			Tuple 						= True

														if hasattr(UpperCamelCase__    ,							"""use_cache"""  ):
																					lowerCamelCase__      :			Union[str, Any] 						= True

														lowerCamelCase__      :			List[str] 						= getattr(self.model_tester    ,							"""encoder_seq_length"""    ,							self.model_tester.seq_length  )
														lowerCamelCase__      :			Tuple 						= getattr(self.model_tester    ,							"""key_length"""    ,							UpperCamelCase__  )

														for model_class in self.all_model_classes:
																					lowerCamelCase__      :			int 						= self._prepare_for_class(UpperCamelCase__    ,							UpperCamelCase__  )
																					lowerCamelCase__      :			List[Any] 						= model_class(UpperCamelCase__  )
																					lowerCamelCase__      :			Dict 						= len(model(UpperCamelCase__  )  )

																					with tempfile.TemporaryDirectory() as tmpdirname:
																												model.save_pretrained(UpperCamelCase__    ,							saved_model=UpperCamelCase__  )
																												lowerCamelCase__      :			int 						= os.path.join(UpperCamelCase__    ,							"""saved_model"""    ,							"""1"""  )
																												lowerCamelCase__      :			List[Any] 						= tf.keras.models.load_model(UpperCamelCase__  )
																												lowerCamelCase__      :			Any 						= model(UpperCamelCase__  )

																												if self.is_encoder_decoder:
																																			lowerCamelCase__      :			Dict 						= outputs["""encoder_hidden_states"""]
																																			lowerCamelCase__      :			Any 						= outputs["""encoder_attentions"""]
																												else:
																																			lowerCamelCase__      :			int 						= outputs["""hidden_states"""]
																																			lowerCamelCase__      :			Optional[int] 						= outputs["""attentions"""]

																												self.assertEqual(len(UpperCamelCase__  )    ,							UpperCamelCase__  )

																												lowerCamelCase__      :			Union[str, Any] 						= getattr(
																												    self.model_tester    ,							"""expected_num_hidden_layers"""    ,							self.model_tester.num_hidden_layers + 1  )

																												self.assertEqual(len(UpperCamelCase__  )    ,							UpperCamelCase__  )
																												self.assertListEqual(
																												    list(output_hidden_states[0].shape[-2:]  )    ,							[self.model_tester.seq_length, self.model_tester.hidden_size]    ,							)

																												self.assertEqual(len(UpperCamelCase__  )    ,							self.model_tester.num_hidden_layers  )
																												self.assertListEqual(
																												    list(output_attentions[0].shape[-3:]  )    ,							[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]    ,							)




							@slow
							def 	lowerCamelCase_       (							self:       int  ):
														lowerCamelCase__      :			Union[str, Any] 						= TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""  )
														self.assertIsNotNone(UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       List[str]  ):
														lowerCamelCase__						,	lowerCamelCase__      :			Any 						= self.model_tester.prepare_config_and_inputs_for_common()
														lowerCamelCase__      :			Union[str, Any] 						= True
														lowerCamelCase__      :			int 						= getattr(self.model_tester    ,							"""decoder_seq_length"""    ,							self.model_tester.seq_length  )
														lowerCamelCase__      :			Any 						= getattr(self.model_tester    ,							"""encoder_seq_length"""    ,							self.model_tester.seq_length  )
														lowerCamelCase__      :			Optional[int] 						= getattr(self.model_tester    ,							"""key_length"""    ,							UpperCamelCase__  )
														lowerCamelCase__      :			List[Any] 						= getattr(self.model_tester    ,							"""key_length"""    ,							UpperCamelCase__  )

														def check_decoder_attentions_output(UpperCamelCase__:       Union[str, Any]  ):
																					lowerCamelCase__      :			List[Any] 						= len(UpperCamelCase__  )
																					self.assertEqual(out_len % 2    ,							0  )
																					lowerCamelCase__      :			Any 						= outputs.decoder_attentions
																					self.assertEqual(len(UpperCamelCase__  )    ,							self.model_tester.num_hidden_layers  )
																					self.assertListEqual(
																					    list(decoder_attentions[0].shape[-3:]  )    ,							[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]    ,							)

														def check_encoder_attentions_output(UpperCamelCase__:       List[str]  ):
																					lowerCamelCase__      :			Any 						= [
																					    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
																					]
																					self.assertEqual(len(UpperCamelCase__  )    ,							self.model_tester.num_hidden_layers  )
																					self.assertListEqual(
																					    list(attentions[0].shape[-3:]  )    ,							[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]    ,							)

														for model_class in self.all_model_classes:
																					lowerCamelCase__      :			int 						= True
																					lowerCamelCase__      :			Any 						= False
																					lowerCamelCase__      :			Union[str, Any] 						= model_class(UpperCamelCase__  )
																					lowerCamelCase__      :			List[str] 						= model(self._prepare_for_class(UpperCamelCase__    ,							UpperCamelCase__  )  )
																					lowerCamelCase__      :			Optional[int] 						= len(UpperCamelCase__  )
																					self.assertEqual(config.output_hidden_states    ,							UpperCamelCase__  )
																					check_encoder_attentions_output(UpperCamelCase__  )

																					if self.is_encoder_decoder:
																												lowerCamelCase__      :			str 						= model_class(UpperCamelCase__  )
																												lowerCamelCase__      :			Tuple 						= model(self._prepare_for_class(UpperCamelCase__    ,							UpperCamelCase__  )  )
																												self.assertEqual(config.output_hidden_states    ,							UpperCamelCase__  )
																												check_decoder_attentions_output(UpperCamelCase__  )

																					# Check that output attentions can also be changed via the config
																					del inputs_dict["output_attentions"]
																					lowerCamelCase__      :			Optional[int] 						= True
																					lowerCamelCase__      :			Dict 						= model_class(UpperCamelCase__  )
																					lowerCamelCase__      :			Union[str, Any] 						= model(self._prepare_for_class(UpperCamelCase__    ,							UpperCamelCase__  )  )
																					self.assertEqual(config.output_hidden_states    ,							UpperCamelCase__  )
																					check_encoder_attentions_output(UpperCamelCase__  )

																					# Check attention is always last and order is fine
																					lowerCamelCase__      :			List[Any] 						= True
																					lowerCamelCase__      :			int 						= True
																					lowerCamelCase__      :			List[Any] 						= model_class(UpperCamelCase__  )
																					lowerCamelCase__      :			List[Any] 						= model(self._prepare_for_class(UpperCamelCase__    ,							UpperCamelCase__  )  )

																					self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)    ,							len(UpperCamelCase__  )  )
																					self.assertEqual(model.config.output_hidden_states    ,							UpperCamelCase__  )
																					check_encoder_attentions_output(UpperCamelCase__  )



@require_tf
class _lowercase			(       unittest.TestCase	):




							@slow
							def 	lowerCamelCase_       (							self:       List[str]  ):
														lowerCamelCase__      :			Dict 						= TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""  )
														lowerCamelCase__      :			Optional[Any] 						= tf.constant([[0, 1, 2, 3, 4, 5]]  )
														lowerCamelCase__      :			Optional[Any] 						= model(UpperCamelCase__  )[0]

														lowerCamelCase__      :			Dict 						= [1, 6, 768]
														self.assertEqual(output.shape    ,							UpperCamelCase__  )

														lowerCamelCase__      :			Dict 						= tf.constant(
														    [
														        [
														            [-0.03_475_493, -0.4_686_034, -0.30_638_832],
														            [0.22_637_248, -0.26_988_646, -0.7_423_424],
														            [0.10_324_868, -0.45_013_508, -0.58_280_784],
														        ]
														    ]  )
														tf.debugging.assert_near(output[:, :3, :3]    ,							UpperCamelCase__    ,							atol=1e-4  )

