





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import TensorType, logging


if TYPE_CHECKING:
					from ...onnx.config import PatchingSpec
					from ...tokenization_utils_base import PreTrainedTokenizerBase


__A     =    logging.get_logger(__name__)

__A     =    {
    "allenai/longformer-base-4096": "https://huggingface.co/allenai/longformer-base-4096/resolve/main/config.json",
    "allenai/longformer-large-4096": "https://huggingface.co/allenai/longformer-large-4096/resolve/main/config.json",
    "allenai/longformer-large-4096-finetuned-triviaqa": (
        "https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/config.json"
    ),
    "allenai/longformer-base-4096-extra.pos.embd.only": (
        "https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/config.json"
    ),
    "allenai/longformer-large-4096-extra.pos.embd.only": (
        "https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/config.json"
    ),
}



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







	'''simple docstring'''
	lowercase_		=      "longformer"

	def __init__(self    :       Optional[Any]	,			UpperCAmelCase_    :       Union[List[int], int] = 512	,			UpperCAmelCase_    :       int = 2	,			UpperCAmelCase_    :       int = 1	,			UpperCAmelCase_    :       int = 0	,			UpperCAmelCase_    :       int = 2	,			UpperCAmelCase_    :       int = 30_522	,			UpperCAmelCase_    :       int = 768	,			UpperCAmelCase_    :       int = 12	,			UpperCAmelCase_    :       int = 12	,			UpperCAmelCase_    :       int = 3_072	,			UpperCAmelCase_    :       str = "gelu"	,			UpperCAmelCase_    :       float = 0.1	,			UpperCAmelCase_    :       float = 0.1	,			UpperCAmelCase_    :       int = 512	,			UpperCAmelCase_    :       int = 2	,			UpperCAmelCase_    :       float = 0.02	,			UpperCAmelCase_    :       float = 1E-1_2	,			UpperCAmelCase_    :       bool = False	,			**UpperCAmelCase_    :       Union[str, Any]	,			)	->Optional[int]:



			'''simple docstring'''



			super().__init__(pad_token_id=UpperCAmelCase_	,			**UpperCAmelCase_)

			lowerCamelCase__:				Any        =attention_window
			lowerCamelCase__:				List[str]        =sep_token_id
			lowerCamelCase__:				str        =bos_token_id
			lowerCamelCase__:				Any        =eos_token_id
			lowerCamelCase__:				Optional[Any]        =vocab_size
			lowerCamelCase__:				List[str]        =hidden_size
			lowerCamelCase__:				str        =num_hidden_layers
			lowerCamelCase__:				Union[str, Any]        =num_attention_heads
			lowerCamelCase__:				Union[str, Any]        =hidden_act
			lowerCamelCase__:				List[str]        =intermediate_size
			lowerCamelCase__:				Union[str, Any]        =hidden_dropout_prob
			lowerCamelCase__:				Optional[int]        =attention_probs_dropout_prob
			lowerCamelCase__:				Union[str, Any]        =max_position_embeddings
			lowerCamelCase__:				List[Any]        =type_vocab_size
			lowerCamelCase__:				int        =initializer_range
			lowerCamelCase__:				List[Any]        =layer_norm_eps
			lowerCamelCase__:				int        =onnx_export



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







	'''simple docstring'''

	def __init__(self    :       Tuple	,			UpperCAmelCase_    :       "PretrainedConfig"	,			UpperCAmelCase_    :       str = "default"	,			UpperCAmelCase_    :       "List[PatchingSpec]" = None)	->Tuple:



			'''simple docstring'''



			super().__init__(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_)
			lowerCamelCase__:				Dict        =True

	@property
	def 							SCREAMING_SNAKE_CASE_ (self    :       List[Any])	->Mapping[str, Mapping[int, str]]:



			'''simple docstring'''



			if self.task == "multiple-choice":
					lowerCamelCase__:				Any        ={0: "batch", 1: "choice", 2: "sequence"}
			else:
					lowerCamelCase__:				Tuple        ={0: "batch", 1: "sequence"}
			return OrderedDict(
			    [
			        ("input_ids", dynamic_axis),
			        ("attention_mask", dynamic_axis),
			        ("global_attention_mask", dynamic_axis),
			    ])

	@property
	def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Mapping[str, Mapping[int, str]]:



			'''simple docstring'''



			lowerCamelCase__:				Dict        =super().outputs
			if self.task == "default":
					lowerCamelCase__:				List[str]        ={0: "batch"}
			return outputs

	@property
	def 							SCREAMING_SNAKE_CASE_ (self    :       List[Any])	->float:



			'''simple docstring'''



			return 1E-4

	@property
	def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->int:



			'''simple docstring'''



			return max(super().default_onnx_opset	,			14)







	def 							SCREAMING_SNAKE_CASE_ (self    :       Any	,			UpperCAmelCase_    :       "PreTrainedTokenizerBase"	,			UpperCAmelCase_    :       int = -1	,			UpperCAmelCase_    :       int = -1	,			UpperCAmelCase_    :       bool = False	,			UpperCAmelCase_    :       Optional[TensorType] = None	,			)	->Mapping[str, Any]:



			'''simple docstring'''



			lowerCamelCase__:				str        =super().generate_dummy_inputs(
			    preprocessor=UpperCAmelCase_	,			batch_size=UpperCAmelCase_	,			seq_length=UpperCAmelCase_	,			is_pair=UpperCAmelCase_	,			framework=UpperCAmelCase_)
			import torch

			# for some reason, replacing this code by inputs["global_attention_mask"] = torch.randint(2, inputs["input_ids"].shape, dtype=torch.int64)
			# makes the export fail randomly
			lowerCamelCase__:				Any        =torch.zeros_like(inputs["input_ids"])
			# make every second token global
			lowerCamelCase__:				Dict        =1

			return inputs








import inspect
import re

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


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

__A     =    transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
__A     =    re.compile(R"\[(.+?)\]\((https://huggingface\.co/.+?)\)")


__A     =    {
    "DecisionTransformerConfig",
    "EncoderDecoderConfig",
    "MusicgenConfig",
    "RagConfig",
    "SpeechEncoderDecoderConfig",
    "TimmBackboneConfig",
    "VisionEncoderDecoderConfig",
    "VisionTextDualEncoderConfig",
    "LlamaConfig",
}





def 					lowerCAmelCase_			(	__a		)					->		Optional[int]:







  """simple docstring"""





  lowerCamelCase__:				List[Any]        =None

  # source code of `config_class`
  lowerCamelCase__:				List[Any]        =inspect.getsource(__a		)
  lowerCamelCase__:				str        =_re_checkpoint.findall(__a		)

  # Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
  # For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
  for ckpt_name, ckpt_link in checkpoints:
    # allow the link to end with `/`
    if ckpt_link.endswith("/"		):
      lowerCamelCase__:				str        =ckpt_link[:-1]

    # verify the checkpoint name corresponds to the checkpoint link
    lowerCamelCase__:				Optional[int]        =F"""https://huggingface.co/{ckpt_name}"""
    if ckpt_link == ckpt_link_from_name:
      lowerCamelCase__:				List[Any]        =ckpt_name
      break

  return checkpoint





def 					lowerCAmelCase_			(	)					->		Tuple:







  """simple docstring"""





  lowerCamelCase__:				Union[str, Any]        =[]

  for config_class in list(CONFIG_MAPPING.values()		):
    # Skip deprecated models
    if "models.deprecated" in config_class.__module__:
      continue
    lowerCamelCase__:				List[Any]        =get_checkpoint_from_config_class(__a		)

    lowerCamelCase__:				Tuple        =config_class.__name__
    if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
      configs_without_checkpoint.append(__a		)

  if len(__a		) > 0:
    lowerCamelCase__:				List[str]        ="\n".join(sorted(__a		)		)
    raise ValueError(F"""The following configurations don't contain any valid checkpoint:\n{message}"""		)


if __name__ == "__main__":
     check_config_docstrings_have_checkpoints()

