'''simple docstring'''



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
__magic_name__   :						Optional[int]    =			"""src/transformers"""


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

__magic_name__   :						Union[str, Any]    =			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)`
__magic_name__   :						List[Any]    =			re.compile(r"""\[(.+?)\]\((https://huggingface\.co/.+?)\)""")


__magic_name__   :						Dict    =			{
    """DecisionTransformerConfig""",
    """EncoderDecoderConfig""",
    """MusicgenConfig""",
    """RagConfig""",
    """SpeechEncoderDecoderConfig""",
    """TimmBackboneConfig""",
    """VisionEncoderDecoderConfig""",
    """VisionTextDualEncoderConfig""",
    """LlamaConfig""",
}




def 				snake_case_      (		SCREAMING_SNAKE_CASE__       ):







  '''simple docstring'''



  _snake_case     		=				None

  # source code of `config_class`
  _snake_case     		=				inspect.getsource(SCREAMING_SNAKE_CASE__       )
  _snake_case     		=				_re_checkpoint.findall(SCREAMING_SNAKE_CASE__       )

  # 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("/"       ):
      _snake_case     		=				ckpt_link[:-1]

    # verify the checkpoint name corresponds to the checkpoint link
    _snake_case     		=				f'''https://huggingface.co/{ckpt_name}'''
    if ckpt_link == ckpt_link_from_name:
      _snake_case     		=				ckpt_name
      break

  return checkpoint




def 				snake_case_      (		):







  '''simple docstring'''



  _snake_case     		=				[]

  for config_class in list(CONFIG_MAPPING.values()       ):
    # Skip deprecated models
    if "models.deprecated" in config_class.__module__:
      continue
    _snake_case     		=				get_checkpoint_from_config_class(SCREAMING_SNAKE_CASE__       )

    _snake_case     		=				config_class.__name__
    if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
      configs_without_checkpoint.append(SCREAMING_SNAKE_CASE__       )

  if len(SCREAMING_SNAKE_CASE__       ) > 0:
    _snake_case     		=				"\n".join(sorted(SCREAMING_SNAKE_CASE__       )       )
    raise ValueError(f'''The following configurations don\'t contain any valid checkpoint:\n{message}'''       )


if __name__ == "__main__":
 check_config_docstrings_have_checkpoints()









'''simple docstring'''



def 				snake_case_      (		SCREAMING_SNAKE_CASE__       ):







  '''simple docstring'''



  _snake_case     		=				[0 for i in range(len(SCREAMING_SNAKE_CASE__       )       )]

  # initialize interval's left pointer and right pointer
  _snake_case		,		_snake_case     		=				0, 0

  for i in range(1					,	len(SCREAMING_SNAKE_CASE__       )       ):
    # case when current index is inside the interval
    if i <= right_pointer:
      _snake_case     		=				min(right_pointer - i + 1					,	z_result[i - left_pointer]       )
      _snake_case     		=				min_edge

    while go_next(SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__       ):
      z_result[i] += 1

    # if new index's result gives us more right interval,
    # we've to update left_pointer and right_pointer
    if i + z_result[i] - 1 > right_pointer:
      _snake_case		,		_snake_case     		=				i, i + z_result[i] - 1

  return z_result




def 				snake_case_      (		SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__       ):







  '''simple docstring'''



  return i + z_result[i] < len(SCREAMING_SNAKE_CASE__       ) and s[z_result[i]] == s[i + z_result[i]]




def 				snake_case_      (		SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__       ):







  '''simple docstring'''



  _snake_case     		=				0
  # concatenate 'pattern' and 'input_str' and call z_function
  # with concatenated string
  _snake_case     		=				z_function(pattern + input_str       )

  for val in z_result:
    # if value is greater then length of the pattern string
    # that means this index is starting position of substring
    # which is equal to pattern string
    if val >= len(SCREAMING_SNAKE_CASE__       ):
      answer += 1

  return answer


if __name__ == "__main__":
 import doctest

 doctest.testmod()


