

_lowerCAmelCase  :      str			 ="""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"""



def 			_A	(      SCREAMING_SNAKE_CASE      ):
	# Make sure the supplied data is a bytes-like object
	if not isinstance(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      ):
		UpperCAmelCase__:	int									= f"a bytes-like object is required, not '{data.__class__.__name__}'"
		raise TypeError(SCREAMING_SNAKE_CASE      )

	UpperCAmelCase__:	List[str]									= "".join(bin(SCREAMING_SNAKE_CASE      )[2:].zfill(8      ) for byte in data      )

	UpperCAmelCase__:	Union[str, Any]									= len(SCREAMING_SNAKE_CASE      ) % 6 != 0

	if padding_needed:
		# The padding that will be added later
		UpperCAmelCase__:	Optional[int]									= b"=" * ((6 - len(SCREAMING_SNAKE_CASE      ) % 6) // 2)

		# Append binary_stream with arbitrary binary digits (0's by default) to make its
		# length a multiple of 6.
		binary_stream += "0" * (6 - len(SCREAMING_SNAKE_CASE      ) % 6)
	else:
		UpperCAmelCase__:	Optional[int]									= b""

	# Encode every 6 binary digits to their corresponding Base64 character
	return (
	    "".join(
	        B64_CHARSET[int(binary_stream[index : index + 6]	,2      )]
	        for index in range(0	,len(SCREAMING_SNAKE_CASE      )	,6      )      ).encode()
	    + padding
	)



def 			_A	(      SCREAMING_SNAKE_CASE      ):
	# Make sure encoded_data is either a string or a bytes-like object
	if not isinstance(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      ) and not isinstance(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      ):
		UpperCAmelCase__:	Optional[int]									= (
		    "argument should be a bytes-like object or ASCII string, "
		    f"not '{encoded_data.__class__.__name__}'"
		)
		raise TypeError(SCREAMING_SNAKE_CASE      )

	# In case encoded_data is a bytes-like object, make sure it contains only
	# ASCII characters so we convert it to a string object
	if isinstance(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      ):
		try:
			UpperCAmelCase__:	Any									= encoded_data.decode("utf-8"      )
		except UnicodeDecodeError:
			raise ValueError("base64 encoded data should only contain ASCII characters"      )

	UpperCAmelCase__:	List[str]									= encoded_data.count("="      )

	# Check if the encoded string contains non base64 characters
	if padding:
		assert all(
		    char in B64_CHARSET for char in encoded_data[:-padding]      ), "Invalid base64 character(s) found."
	else:
		assert all(
		    char in B64_CHARSET for char in encoded_data      ), "Invalid base64 character(s) found."

	# Check the padding
	assert len(SCREAMING_SNAKE_CASE      ) % 4 == 0 and padding < 3, "Incorrect padding"

	if padding:
		# Remove padding if there is one
		UpperCAmelCase__:	Union[str, Any]									= encoded_data[:-padding]

		UpperCAmelCase__:	List[str]									= "".join(
		    bin(B64_CHARSET.index(SCREAMING_SNAKE_CASE      )      )[2:].zfill(6      ) for char in encoded_data      )[: -padding * 2]
	else:
		UpperCAmelCase__:	Optional[Any]									= "".join(
		    bin(B64_CHARSET.index(SCREAMING_SNAKE_CASE      )      )[2:].zfill(6      ) for char in encoded_data      )

	UpperCAmelCase__:	List[Any]									= [
	    int(binary_stream[index : index + 8]	,2      )
	    for index in range(0	,len(SCREAMING_SNAKE_CASE      )	,8      )
	]

	return bytes(SCREAMING_SNAKE_CASE      )


if __name__ == "__main__":
					import doctest

					doctest.testmod()


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


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

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


_lowerCAmelCase  :      Union[str, Any]			 ={
    """DecisionTransformerConfig""",
    """EncoderDecoderConfig""",
    """MusicgenConfig""",
    """RagConfig""",
    """SpeechEncoderDecoderConfig""",
    """TimmBackboneConfig""",
    """VisionEncoderDecoderConfig""",
    """VisionTextDualEncoderConfig""",
    """LlamaConfig""",
}



def 			_A	(      SCREAMING_SNAKE_CASE      ):
	UpperCAmelCase__:	str									= None

	# source code of `config_class`
	UpperCAmelCase__:	Optional[int]									= inspect.getsource(SCREAMING_SNAKE_CASE      )
	UpperCAmelCase__:	List[Any]									= _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("/"      ):
			UpperCAmelCase__:	Any									= ckpt_link[:-1]

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

	return checkpoint



def 			_A	(      ):
	UpperCAmelCase__:	List[str]									= []

	for config_class in list(CONFIG_MAPPING.values()      ):
		# Skip deprecated models
		if "models.deprecated" in config_class.__module__:
			continue
		UpperCAmelCase__:	Optional[Any]									= get_checkpoint_from_config_class(SCREAMING_SNAKE_CASE      )

		UpperCAmelCase__:	List[str]									= 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:
		UpperCAmelCase__:	Dict									= "\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()