
'''simple docstring'''





import platform
from argparse import ArgumentParser

import huggingface_hub

from .. import __version__ as version
from ..utils import is_accelerate_available, is_torch_available, is_transformers_available, is_xformers_available
from . import BaseDiffusersCLICommand

def      A (       A_							:					int       ):
						return EnvironmentCommand()





class 						a   (				__magic_name__    ):




				@staticmethod
				def 	__snake_case							(							SCREAMING_SNAKE_CASE_	:				ArgumentParser      ):
										snake_case       :     Optional[int] =    parser.add_parser('''env'''      )
										download_parser.set_defaults(func=SCREAMING_SNAKE_CASE_      )




				def 	__snake_case							(							self	:				List[str]      ):
										snake_case       :     Tuple =    huggingface_hub.__version__

										snake_case       :     List[Any] =    '''not installed'''
										snake_case       :     Optional[Any] =    '''NA'''
										if is_torch_available():
																import torch

																snake_case       :     str =    torch.__version__
																snake_case       :     Any =    torch.cuda.is_available()

										snake_case       :     Tuple =    '''not installed'''
										if is_transformers_available():
																import transformers

																snake_case       :     Dict =    transformers.__version__

										snake_case       :     Optional[Any] =    '''not installed'''
										if is_accelerate_available():
																import accelerate

																snake_case       :     List[Any] =    accelerate.__version__

										snake_case       :     Optional[int] =    '''not installed'''
										if is_xformers_available():
																import xformers

																snake_case       :     List[Any] =    xformers.__version__

										snake_case       :     str =    {
										    '''`diffusers` version''': version,
										    '''Platform''': platform.platform(),
										    '''Python version''': platform.python_version(),
										    '''PyTorch version (GPU?)''': F"""{pt_version} ({pt_cuda_available})""",
										    '''Huggingface_hub version''': hub_version,
										    '''Transformers version''': transformers_version,
										    '''Accelerate version''': accelerate_version,
										    '''xFormers version''': xformers_version,
										    '''Using GPU in script?''': '''<fill in>''',
										    '''Using distributed or parallel set-up in script?''': '''<fill in>''',
										}

										print('''\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n'''      )
										print(self.format_dict(SCREAMING_SNAKE_CASE_      )      )

										return info




				@staticmethod
				def 	__snake_case							(							SCREAMING_SNAKE_CASE_	:				str      ):
										return "\n".join([F"""- {prop}: {val}""" for prop, val in d.items()]      ) + "\n"



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


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

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


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

def      A (       A_							:					Union[str, Any]       ):
						snake_case       :     Tuple =    None

						# source code of `config_class`
						snake_case       :     Union[str, Any] =    inspect.getsource(A_       )
						snake_case       :     List[Any] =    _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('''/'''       ):
																		snake_case       :     Optional[int] =    ckpt_link[:-1]

												# verify the checkpoint name corresponds to the checkpoint link
												snake_case       :     Dict =    F"""https://huggingface.co/{ckpt_name}"""
												if ckpt_link == ckpt_link_from_name:
																		snake_case       :     Dict =    ckpt_name
																		break

						return checkpoint

def      A (       ):
						snake_case       :     List[str] =    []

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

												snake_case       :     Optional[Any] =    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:
												snake_case       :     Optional[int] =    '''\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()

