


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

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

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

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

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

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

             a_   :						Optional[Any]				=    [input_ids, input_mask]
             a_   :						int				=    model(UpperCAmelCase_	)

             a_   :						Optional[Any]				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.d_model)	)

             a_   :						Optional[int]				=    False
             a_   :						Tuple				=    TFFunnelModel(config=UpperCAmelCase_	)
             a_   :						Union[str, Any]				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.d_model)	)

             a_   :						int				=    False
             a_   :						Optional[int]				=    TFFunnelModel(config=UpperCAmelCase_	)
             a_   :						str				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.d_model)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			List[Any]	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			Dict	,				SCREAMING_SNAKE_CASE__							:			str	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			Dict	,				SCREAMING_SNAKE_CASE__							:			List[str]	,				)						->     Optional[Any]:
             a_   :						List[Any]				=    TFFunnelBaseModel(config=UpperCAmelCase_	)
             a_   :						List[Any]				=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
             a_   :						Tuple				=    model(UpperCAmelCase_	)

             a_   :						Dict				=    [input_ids, input_mask]
             a_   :						Any				=    model(UpperCAmelCase_	)

             a_   :						Any				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, 2, self.d_model)	)

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

             a_   :						List[Any]				=    False
             a_   :						Optional[int]				=    TFFunnelBaseModel(config=UpperCAmelCase_	)
             a_   :						List[str]				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, 2, self.d_model)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			List[Any]	,				SCREAMING_SNAKE_CASE__							:			List[Any]	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			int	,				)						->     List[str]:
             a_   :						Union[str, Any]				=    TFFunnelForPreTraining(config=UpperCAmelCase_	)
             a_   :						Dict				=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
             a_   :						int				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Tuple	,				SCREAMING_SNAKE_CASE__							:			int	,				SCREAMING_SNAKE_CASE__							:			List[Any]	,				SCREAMING_SNAKE_CASE__							:			List[str]	,				SCREAMING_SNAKE_CASE__							:			List[Any]	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			Tuple	,				SCREAMING_SNAKE_CASE__							:			Tuple	,				)						->     int:
             a_   :						Tuple				=    TFFunnelForMaskedLM(config=UpperCAmelCase_	)
             a_   :						List[Any]				=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
             a_   :						List[Any]				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.vocab_size)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Any	,				SCREAMING_SNAKE_CASE__							:			int	,				SCREAMING_SNAKE_CASE__							:			int	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			int	,				SCREAMING_SNAKE_CASE__							:			Tuple	,				SCREAMING_SNAKE_CASE__							:			Any	,				SCREAMING_SNAKE_CASE__							:			Optional[Any]	,				)						->     Union[str, Any]:
             a_   :						Optional[Any]				=    self.num_labels
             a_   :						int				=    TFFunnelForSequenceClassification(config=UpperCAmelCase_	)
             a_   :						Optional[int]				=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
             a_   :						Dict				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_labels)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Tuple	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			int	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			Dict	,				SCREAMING_SNAKE_CASE__							:			int	,				)						->     Optional[int]:
             a_   :						Dict				=    self.num_choices
             a_   :						Dict				=    TFFunnelForMultipleChoice(config=UpperCAmelCase_	)
             a_   :						List[str]				=    tf.tile(tf.expand_dims(UpperCAmelCase_	,				1	)	,				(1, self.num_choices, 1)	)
             a_   :						str				=    tf.tile(tf.expand_dims(UpperCAmelCase_	,				1	)	,				(1, self.num_choices, 1)	)
             a_   :						List[str]				=    tf.tile(tf.expand_dims(UpperCAmelCase_	,				1	)	,				(1, self.num_choices, 1)	)
             a_   :						Union[str, Any]				=    {
                 'input_ids': multiple_choice_inputs_ids,
                 'attention_mask': multiple_choice_input_mask,
                 'token_type_ids': multiple_choice_token_type_ids,
             }
             a_   :						Dict				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_choices)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			str	,				SCREAMING_SNAKE_CASE__							:			Tuple	,				SCREAMING_SNAKE_CASE__							:			Any	,				SCREAMING_SNAKE_CASE__							:			Optional[Any]	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			str	,				SCREAMING_SNAKE_CASE__							:			List[Any]	,				SCREAMING_SNAKE_CASE__							:			List[Any]	,				)						->     Optional[int]:
             a_   :						List[str]				=    self.num_labels
             a_   :						Tuple				=    TFFunnelForTokenClassification(config=UpperCAmelCase_	)
             a_   :						Tuple				=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
             a_   :						int				=    model(UpperCAmelCase_	)
             self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.num_labels)	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			str	,				SCREAMING_SNAKE_CASE__							:			str	,				SCREAMING_SNAKE_CASE__							:			Tuple	,				SCREAMING_SNAKE_CASE__							:			Optional[int]	,				SCREAMING_SNAKE_CASE__							:			int	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				SCREAMING_SNAKE_CASE__							:			str	,				SCREAMING_SNAKE_CASE__							:			Union[str, Any]	,				)						->     str:
             a_   :						Optional[Any]				=    TFFunnelForQuestionAnswering(config=UpperCAmelCase_	)
             a_   :						Union[str, Any]				=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
             a_   :						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 			SCREAMING_SNAKE_CASE				(			self							:			Optional[Any]	)						->     Tuple:
             a_   :						List[str]				=    self.prepare_config_and_inputs()
             (
                 (
                 a_							
             )				,						(
                 a_							
             )				,						(
                 a_							
             )				,						(
                 a_							
             )				,						(
                 a_							
             )				,						(
                 a_							
             )				,						(
                 a_							
             )				,													
             )   :						List[Any]				=    config_and_inputs
             a_   :						Dict				=    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
             return config, inputs_dict
@require_tf
class 					SCREAMING_SNAKE_CASE__    (							_lowerCAmelCase		,       _lowerCAmelCase		,       unittest.TestCase     ):
      snake_case__							:	Tuple	  =		(
          (
              TFFunnelModel,
              TFFunnelForMaskedLM,
              TFFunnelForPreTraining,
              TFFunnelForQuestionAnswering,
              TFFunnelForTokenClassification,
          )
          if is_tf_available()
          else ()
      )
      snake_case__							:	Any	  =		(
          {
              '''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__							:	Optional[Any]	  =		False
      snake_case__							:	int	  =		False
      def 			SCREAMING_SNAKE_CASE				(			self							:			Optional[Any]	)						->     int:
             a_   :						int				=    TFFunnelModelTester(self	)
             a_   :						List[Any]				=    ConfigTester(self	,				config_class=UpperCAmelCase_	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Union[str, Any]	)						->     Optional[Any]:
             self.config_tester.run_common_tests()
      def 			SCREAMING_SNAKE_CASE				(			self							:			Optional[int]	)						->     Optional[Any]:
             a_   :						List[str]				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*UpperCAmelCase_	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Optional[Any]	)						->     Dict:
             a_   :						Any				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase_	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			List[str]	)						->     Union[str, Any]:
             a_   :						Dict				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Union[str, Any]	)						->     Union[str, Any]:
             a_   :						List[str]				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_	)

      def 			SCREAMING_SNAKE_CASE				(			self							:			int	)						->     int:
             a_   :						Dict				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_	)
@require_tf
class 					SCREAMING_SNAKE_CASE__    (							_lowerCAmelCase		,       unittest.TestCase     ):
      snake_case__							:	List[str]	  =		(
          (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
      )
      snake_case__							:	List[Any]	  =		False
      snake_case__							:	Union[str, Any]	  =		False
      def 			SCREAMING_SNAKE_CASE				(			self							:			Optional[Any]	)						->     int:
             a_   :						Optional[int]				=    TFFunnelModelTester(self	,				base=UpperCAmelCase_	)
             a_   :						str				=    ConfigTester(self	,				config_class=UpperCAmelCase_	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Any	)						->     Optional[Any]:
             self.config_tester.run_common_tests()
      def 			SCREAMING_SNAKE_CASE				(			self							:			Any	)						->     Any:
             a_   :						Tuple				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_base_model(*UpperCAmelCase_	)
      def 			SCREAMING_SNAKE_CASE				(			self							:			Dict	)						->     List[str]:
             a_   :						Union[str, Any]				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_	)

      def 			SCREAMING_SNAKE_CASE				(			self							:			str	)						->     Any:
             a_   :						str				=    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase_	)




"""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
SCREAMING_SNAKE_CASE			  =  """src/transformers"""


# This is to make sure the transformers module imported is the one in the repo.
SCREAMING_SNAKE_CASE			  =  direct_transformers_import(PATH_TO_TRANSFORMERS)

SCREAMING_SNAKE_CASE			  =  transformers.models.auto.configuration_auto.CONFIG_MAPPING

SCREAMING_SNAKE_CASE			  =  {
    # 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 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Optional[Any]:







       """simple docstring"""
       UpperCamelCase       			=		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
                     ):
                            UpperCamelCase       			=		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}\""		,   UpperCAmelCase_		,   )
                         is not None
                     ):
                            UpperCamelCase       			=		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:
                                   UpperCamelCase       			=		True
                     if attribute_used:
                            break
              if attribute_used:
                     break

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

       # Special cases to be allowed
       UpperCamelCase       			=		True
       if not attribute_used:
              UpperCamelCase       			=		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:
                            UpperCamelCase       			=		True
                     elif attribute in ["tie_word_embeddings"] and default_value is False:
                            UpperCamelCase       			=		True

                     # Allow cases without checking the default value in the configuration class
                     elif attribute in attributes_to_allow + attributes_used_in_generation:
                            UpperCamelCase       			=		True
                     elif attribute.endswith("_token_id"					):
                            UpperCamelCase       			=		True

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

       return attribute_used or case_allowed



def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Optional[Any]:







       """simple docstring"""
       UpperCamelCase       			=		dict(inspect.signature(config_class.__init__					).parameters					)
       UpperCamelCase       			=		[x for x in list(signature.keys()					) if x not in ["self", "kwargs"]]
       UpperCamelCase       			=		[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
       UpperCamelCase       			=		{}
       if len(config_class.attribute_map					) > 0:
              UpperCamelCase       			=		{v: k for k, v in config_class.attribute_map.items()}

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

       # Get the source code strings
       UpperCamelCase       			=		[]
       for path in modeling_paths:
              if os.path.isfile(UpperCAmelCase_					):
                     with open(UpperCAmelCase_					) as fp:
                            modeling_sources.append(fp.read()					)

       UpperCamelCase       			=		[]
       for config_param, default_value in zip(UpperCAmelCase_		,   UpperCAmelCase_					):
              # `attributes` here is all the variant names for `config_param`
              UpperCamelCase       			=		[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(UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					):
                     unused_attributes.append(attributes[0]					)

       return sorted(UpperCAmelCase_					)



def 						lowerCamelCase__      (				)->				List[str]:







       """simple docstring"""
       UpperCamelCase       			=		{}
       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.)
              UpperCamelCase       			=		[
                  cls
                  for name, cls in inspect.getmembers(
                      inspect.getmodule(_config_class					)		,   lambda UpperCAmelCase_					: inspect.isclass(UpperCAmelCase_					)
                      and issubclass(UpperCAmelCase_		,   UpperCAmelCase_					)
                      and inspect.getmodule(UpperCAmelCase_					) == inspect.getmodule(_config_class					)		,   )
              ]
              for config_class in config_classes_in_module:
                     UpperCamelCase       			=		check_config_attributes_being_used(UpperCAmelCase_					)
                     if len(UpperCAmelCase_					) > 0:
                            UpperCamelCase       			=		unused_attributes

       if len(UpperCAmelCase_					) > 0:
              UpperCamelCase       			=		"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(UpperCAmelCase_					)


if __name__ == "__main__":
      check_config_attributes()





