





import importlib.util
import os
import platform
from argparse import ArgumentParser

import huggingface_hub

from .. import __version__ as version
from ..utils import (
    is_accelerate_available,
    is_flax_available,
    is_safetensors_available,
    is_tf_available,
    is_torch_available,
)
from . import BaseTransformersCLICommand



def 		A_				(     _lowerCAmelCase     )						-> Optional[Any]:
 return EnvironmentCommand()



def 		A_				(     _lowerCAmelCase     )						-> List[str]:
 return EnvironmentCommand(args.accelerate_config_file     )



class 					A__   (       __snake_case			):





      @staticmethod
      def        __UpperCamelCase( A_   ):
       '''simple docstring'''




       UpperCamelCase	:					Tuple       	=   parser.add_parser("env"   )
       download_parser.set_defaults(func=A_   )
       download_parser.add_argument(
           "--accelerate-config_file"       ,							default=A_       ,							help="The accelerate config file to use for the default values in the launching script."       ,							)
       download_parser.set_defaults(func=A_   )





      def __init__( self       ,							A_       ,							*A_   ):
       '''simple docstring'''




       UpperCamelCase	:					str       	=   accelerate_config_file





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Any       	=   "not installed"
       if is_safetensors_available():
        import safetensors

        UpperCamelCase	:					Tuple       	=   safetensors.__version__
       elif importlib.util.find_spec("safetensors"   ) is not None:
        import safetensors

        UpperCamelCase	:					Optional[Any]       	=   F"""{safetensors.__version__} but is ignored because of PyTorch version too old."""

       UpperCamelCase	:					Optional[Any]       	=   "not installed"
       UpperCamelCase	:					Optional[Any]       	=   "not found"
       if is_accelerate_available():
        import accelerate
        from accelerate.commands.config import default_config_file, load_config_from_file

        UpperCamelCase	:					Tuple       	=   accelerate.__version__
        # Get the default from the config file.
        if self._accelerate_config_file is not None or os.path.isfile(A_   ):
         UpperCamelCase	:					Tuple       	=   load_config_from_file(self._accelerate_config_file   ).to_dict()

        UpperCamelCase	:					Optional[Any]       	=   (
            "\n".join([F"""\t- {prop}: {val}""" for prop, val in accelerate_config.items()]   )
            if isinstance(A_       ,							A_   )
            else F"""\t{accelerate_config}"""
        )

       UpperCamelCase	:					List[Any]       	=   "not installed"
       UpperCamelCase	:					Optional[int]       	=   "NA"
       if is_torch_available():
        import torch

        UpperCamelCase	:					List[str]       	=   torch.__version__
        UpperCamelCase	:					List[Any]       	=   torch.cuda.is_available()

       UpperCamelCase	:					Union[str, Any]       	=   "not installed"
       UpperCamelCase	:					str       	=   "NA"
       if is_tf_available():
        import tensorflow as tf

        UpperCamelCase	:					List[str]       	=   tf.__version__
        try:
         # deprecated in v2.1
         UpperCamelCase	:					Dict       	=   tf.test.is_gpu_available()
        except AttributeError:
         # returns list of devices, convert to bool
         UpperCamelCase	:					List[Any]       	=   bool(tf.config.list_physical_devices("GPU"   )   )

       UpperCamelCase	:					Tuple       	=   "not installed"
       UpperCamelCase	:					Optional[Any]       	=   "not installed"
       UpperCamelCase	:					Tuple       	=   "not installed"
       UpperCamelCase	:					Optional[int]       	=   "NA"
       if is_flax_available():
        import flax
        import jax
        import jaxlib

        UpperCamelCase	:					Union[str, Any]       	=   flax.__version__
        UpperCamelCase	:					Optional[Any]       	=   jax.__version__
        UpperCamelCase	:					List[str]       	=   jaxlib.__version__
        UpperCamelCase	:					int       	=   jax.lib.xla_bridge.get_backend().platform

       UpperCamelCase	:					Optional[Any]       	=   {
           "`transformers` version": version,
           "Platform": platform.platform(),
           "Python version": platform.python_version(),
           "Huggingface_hub version": huggingface_hub.__version__,
           "Safetensors version": F"""{safetensors_version}""",
           "Accelerate version": F"""{accelerate_version}""",
           "Accelerate config": F"""{accelerate_config_str}""",
           "PyTorch version (GPU?)": F"""{pt_version} ({pt_cuda_available})""",
           "Tensorflow version (GPU?)": F"""{tf_version} ({tf_cuda_available})""",
           "Flax version (CPU?/GPU?/TPU?)": F"""{flax_version} ({jax_backend})""",
           "Jax version": F"""{jax_version}""",
           "JaxLib version": F"""{jaxlib_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(A_   )   )

       return info





      @staticmethod
      def        __UpperCamelCase( A_   ):
       '''simple docstring'''




       return "\n".join([F"""- {prop}: {val}""" for prop, val in d.items()]   ) + "\n"







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


# This is to make sure the transformers module imported is the one in the repo.
__lowerCamelCase       :     Tuple   =     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       :     Optional[Any]   =     re.compile(r"""\[(.+?)\]\((https://huggingface\.co/.+?)\)""")


__lowerCamelCase       :     List[str]   =     {
    """DecisionTransformerConfig""",
    """EncoderDecoderConfig""",
    """MusicgenConfig""",
    """RagConfig""",
    """SpeechEncoderDecoderConfig""",
    """TimmBackboneConfig""",
    """VisionEncoderDecoderConfig""",
    """VisionTextDualEncoderConfig""",
    """LlamaConfig""",
}



def 		A_				(     _lowerCAmelCase     )						-> List[str]:
 UpperCamelCase	:					Optional[Any]       	=   None

 # source code of `config_class`
 UpperCamelCase	:					Tuple       	=   inspect.getsource(_lowerCAmelCase     )
 UpperCamelCase	:					Optional[Any]       	=   _re_checkpoint.findall(_lowerCAmelCase     )

 # 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	:					Dict       	=   ckpt_link[:-1]

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

 return checkpoint



def 		A_				(     )						-> List[str]:
 UpperCamelCase	:					Optional[int]       	=   []

 for config_class in list(CONFIG_MAPPING.values()     ):
  # Skip deprecated models
  if "models.deprecated" in config_class.__module__:
   continue
  UpperCamelCase	:					Union[str, Any]       	=   get_checkpoint_from_config_class(_lowerCAmelCase     )

  UpperCamelCase	:					Optional[int]       	=   config_class.__name__
  if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
   configs_without_checkpoint.append(_lowerCAmelCase     )

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


if __name__ == "__main__":
    check_config_docstrings_have_checkpoints()
