



'''simple docstring'''





import dataclasses
import json
import warnings
from dataclasses import dataclass, field
from time import time
from typing import List

from ..utils import logging


UpperCAmelCase    					=   logging.get_logger(__name__)

def      A (       A_							:					int=None    ,							A_							:					Tuple=None       ):
						return field(default_factory=lambda: default    ,							metadata=A_       )





@dataclass
class 						a   :
				_snake_case		    = list_field(
				    default=[]				,metadata={
				        '''help''': (
				            '''Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version'''
				            ''' of all available models'''
				        )
				    }				,)

				_snake_case		    = list_field(
				    default=[8]				,metadata={'''help''': '''List of batch sizes for which memory and time performance will be evaluated'''}    )

				_snake_case		    = list_field(
				    default=[8, 32, 128, 512]				,metadata={'''help''': '''List of sequence lengths for which memory and time performance will be evaluated'''}				,)

				_snake_case		    = field(
				    default=__magic_name__				,metadata={'''help''': '''Whether to benchmark inference of model. Inference can be disabled via --no-inference.'''}				,)
				_snake_case		    = field(
				    default=__magic_name__				,metadata={'''help''': '''Whether to run on available cuda devices. Cuda can be disabled via --no-cuda.'''}				,)
				_snake_case		    = field(
				    default=__magic_name__				,metadata={'''help''': '''Whether to run on available tpu devices. TPU can be disabled via --no-tpu.'''}    )
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Use FP16 to accelerate inference.'''}    )
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Benchmark training of model'''}    )
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Verbose memory tracing'''}    )
				_snake_case		    = field(
				    default=__magic_name__				,metadata={'''help''': '''Whether to perform speed measurements. Speed measurements can be disabled via --no-speed.'''}				,)
				_snake_case		    = field(
				    default=__magic_name__				,metadata={
				        '''help''': '''Whether to perform memory measurements. Memory measurements can be disabled via --no-memory'''
				    }				,)
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Trace memory line by line'''}    )
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Save result to a CSV file'''}    )
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Save all print statements in a log file'''}    )
				_snake_case		    = field(default=__magic_name__				,metadata={'''help''': '''Whether to print environment information'''}    )
				_snake_case		    = field(
				    default=__magic_name__				,metadata={
				        '''help''': (
				            '''Whether to use multiprocessing for memory and speed measurement. It is highly recommended to use'''
				            ''' multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled'''
				            ''' for debugging / testing and on TPU.'''
				        )
				    }				,)
				_snake_case		    = field(
				    default=F"""inference_time_{round(time()    )}.csv"""				,metadata={'''help''': '''CSV filename used if saving time results to csv.'''}				,)
				_snake_case		    = field(
				    default=F"""inference_memory_{round(time()    )}.csv"""				,metadata={'''help''': '''CSV filename used if saving memory results to csv.'''}				,)
				_snake_case		    = field(
				    default=F"""train_time_{round(time()    )}.csv"""				,metadata={'''help''': '''CSV filename used if saving time results to csv for training.'''}				,)
				_snake_case		    = field(
				    default=F"""train_memory_{round(time()    )}.csv"""				,metadata={'''help''': '''CSV filename used if saving memory results to csv for training.'''}				,)
				_snake_case		    = field(
				    default=F"""env_info_{round(time()    )}.csv"""				,metadata={'''help''': '''CSV filename used if saving environment information.'''}				,)
				_snake_case		    = field(
				    default=F"""log_{round(time()    )}.csv"""				,metadata={'''help''': '''Log filename used if print statements are saved in log.'''}				,)
				_snake_case		    = field(default=3				,metadata={'''help''': '''Times an experiment will be run.'''}    )
				_snake_case		    = field(
				    default=__magic_name__				,metadata={
				        '''help''': (
				            '''Instead of loading the model as defined in `config.architectures` if exists, just load the pretrain'''
				            ''' model weights.'''
				        )
				    }				,)




				def 	__snake_case							(							self	:				str      ):
										warnings.warn(
										    F"""The class {self.__class__} is deprecated. Hugging Face Benchmarking utils"""
										    ''' are deprecated in general and it is advised to use external Benchmarking libraries '''
										    ''' to benchmark Transformer models.''',    SCREAMING_SNAKE_CASE_,    )




				def 	__snake_case							(							self	:				Optional[int]      ):
										return json.dumps(dataclasses.asdict(self      ),    indent=2      )




				@property
				def 	__snake_case							(							self	:				Union[str, Any]      ):
										if len(self.models      ) <= 0:
																raise ValueError(
																    '''Please make sure you provide at least one model name / model identifier, *e.g.* `--models'''
																    ''' bert-base-cased` or `args.models = [\'bert-base-cased\'].'''      )
										return self.models




				@property
				def 	__snake_case							(							self	:				Any      ):
										if not self.multi_process:
																return False
										elif self.is_tpu:
																logger.info('''Multiprocessing is currently not possible on TPU.'''      )
																return False
										else:
																return True



'''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()

