


'''simple docstring'''






import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


__A :  str    							=				threading.Lock()
__A :  Any    							=				None

__A :  Tuple    							=				{
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

__A :  str    							=				logging.WARNING

__A :  Tuple    							=				True







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		lowerCAmelCase_      :				Tuple      =       os.getenv("""TRANSFORMERS_VERBOSITY"""							,   A__ )
		if env_level_str:
				if env_level_str in log_levels:
						return log_levels[env_level_str]
				else:
						logging.getLogger().warning(
						    f'Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '
						    f'has to be one of: { ", ".join(log_levels.keys() ) }' )
		return _default_log_level







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return __name__.split(""".""" )[0]







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return logging.getLogger(_get_library_name() )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		global _default_handler

		with _lock:
				if _default_handler:
						# This library has already configured the library root logger.
						return
				lowerCAmelCase_      :				Dict      =       logging.StreamHandler()  # Set sys.stderr as stream.
				lowerCAmelCase_      :				Optional[Any]      =       sys.stderr.flush

				# Apply our default configuration to the library root logger.
				lowerCAmelCase_      :				List[Any]      =       _get_library_root_logger()
				library_root_logger.addHandler(_default_handler )
				library_root_logger.setLevel(_get_default_logging_level() )
				lowerCAmelCase_      :				str      =       False







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		global _default_handler

		with _lock:
				if not _default_handler:
						return

				lowerCAmelCase_      :				Union[str, Any]      =       _get_library_root_logger()
				library_root_logger.removeHandler(_default_handler )
				library_root_logger.setLevel(logging.NOTSET )
				lowerCAmelCase_      :				List[Any]      =       None







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return log_levels







def     UpperCamelCase_      (   A__ :       Optional[str] = None ):
		'''simple docstring'''





		if name is None:
				lowerCAmelCase_      :				List[Any]      =       _get_library_name()

		_configure_library_root_logger()
		return logging.getLogger(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		_configure_library_root_logger()
		return _get_library_root_logger().getEffectiveLevel()







def     UpperCamelCase_      (   A__ :       int ):
		'''simple docstring'''





		_configure_library_root_logger()
		_get_library_root_logger().setLevel(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return set_verbosity(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return set_verbosity(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return set_verbosity(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		return set_verbosity(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		_configure_library_root_logger()

		assert _default_handler is not None
		_get_library_root_logger().removeHandler(_default_handler )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		_configure_library_root_logger()

		assert _default_handler is not None
		_get_library_root_logger().addHandler(_default_handler )







def     UpperCamelCase_      (   A__ :       logging.Handler ):
		'''simple docstring'''





		_configure_library_root_logger()

		assert handler is not None
		_get_library_root_logger().addHandler(A__ )







def     UpperCamelCase_      (   A__ :       logging.Handler ):
		'''simple docstring'''





		_configure_library_root_logger()

		assert handler is not None and handler not in _get_library_root_logger().handlers
		_get_library_root_logger().removeHandler(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		_configure_library_root_logger()
		lowerCAmelCase_      :				Optional[Any]      =       False







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		_configure_library_root_logger()
		lowerCAmelCase_      :				Any      =       True







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		lowerCAmelCase_      :				Union[str, Any]      =       _get_library_root_logger().handlers

		for handler in handlers:
				lowerCAmelCase_      :				List[Any]      =       logging.Formatter("""[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s""" )
				handler.setFormatter(A__ )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		lowerCAmelCase_      :				Dict      =       _get_library_root_logger().handlers

		for handler in handlers:
				handler.setFormatter(A__ )







def     UpperCamelCase_      (   self :       Any							,   *A__ :       List[Any]							,   **A__ :       Optional[Any] ):
		'''simple docstring'''





		lowerCAmelCase_      :				Any      =       os.getenv("""TRANSFORMERS_NO_ADVISORY_WARNINGS"""							,   A__ )
		if no_advisory_warnings:
				return
		self.warning(*A__							,   **A__ )


__A :  Union[str, Any]    							=				warning_advice







@functools.lru_cache(A__ )
def     UpperCamelCase_      (   self :       List[Any]							,   *A__ :       Any							,   **A__ :       Optional[Any] ):
		'''simple docstring'''





		self.warning(*A__							,   **A__ )


__A :  str    							=				warning_once






class        __snake_case	:







				"""simple docstring"""



				def __init__(       self   :  Any   ,						*lowerCamelCase   :  Tuple   ,						**lowerCamelCase   :  List[Any]		)       ->  Tuple:  # pylint: disable=unused-argument
						lowerCAmelCase_      :				List[Any]      =       args[0] if args else None

				def __iter__(       self   :  int		)       ->  Tuple:
						return iter(self._iterator		)

				def __getattr__(       self   :  int   ,						lowerCamelCase   :  List[str]		)       ->  List[str]:


						def empty_fn(*lowerCamelCase   :  Optional[Any]   ,						**lowerCamelCase   :  Optional[int]		):  # pylint: disable=unused-argument
								return

						return empty_fn

				def __enter__(       self   :  Dict		)       ->  Any:
						return self





				def __exit__(       self   :  Tuple   ,						lowerCamelCase   :  Optional[Any]   ,						lowerCamelCase   :  str   ,						lowerCamelCase   :  List[str]		)       ->  List[Any]:
						return







class        __snake_case	:







				"""simple docstring"""



				def __call__(       self   :  List[str]   ,						*lowerCamelCase   :  Optional[int]   ,						**lowerCamelCase   :  Optional[Any]		)       ->  List[Any]:


						if _tqdm_active:
								return tqdm_lib.tqdm(*__UpperCAmelCase   ,						**__UpperCAmelCase		)
						else:
								return EmptyTqdm(*__UpperCAmelCase   ,						**__UpperCAmelCase		)

				def __lowercase       (       self   :  str   ,						*lowerCamelCase   :  Any   ,						**lowerCamelCase   :  Dict		)       ->  Tuple:
						lowerCAmelCase_      :				int      =       None
						if _tqdm_active:
								return tqdm_lib.tqdm.set_lock(*__UpperCAmelCase   ,						**__UpperCAmelCase		)





				def __lowercase       (       self   :  Any		)       ->  Dict:


						if _tqdm_active:
								return tqdm_lib.tqdm.get_lock()







__A :  int    							=				_tqdm_cls()







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		global _tqdm_active
		return bool(_tqdm_active )







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		global _tqdm_active
		lowerCAmelCase_      :				Dict      =       True
		hf_hub_utils.enable_progress_bars()







def     UpperCamelCase_      (   ):
		'''simple docstring'''





		global _tqdm_active
		lowerCAmelCase_      :				List[Any]      =       False
		hf_hub_utils.disable_progress_bars()







'''simple docstring'''






# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os

from accelerate.utils import ComputeEnvironment

from .cluster import get_cluster_input
from .config_args import cache_dir, default_config_file, default_yaml_config_file, load_config_from_file  # noqa: F401
from .config_utils import _ask_field, _ask_options, _convert_compute_environment  # noqa: F401
from .sagemaker import get_sagemaker_input


__A :  str    							=				"Launches a series of prompts to create and save a `default_config.yaml` configuration file for your training system. Should always be ran first on your machine"







def     UpperCamelCase_      (   ):
  '''simple docstring'''





  lowerCAmelCase_      :				List[Any]      =       _ask_options(
      """In which compute environment are you running?"""							,   ["""This machine""", """AWS (Amazon SageMaker)"""]							,   _convert_compute_environment							,   )
  if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
    lowerCAmelCase_      :				str      =       get_sagemaker_input()
  else:
    lowerCAmelCase_      :				Optional[int]      =       get_cluster_input()
  return config







def     UpperCamelCase_      (   A__ :       Optional[Any]=None ):
  '''simple docstring'''





  if subparsers is not None:
    lowerCAmelCase_      :				List[str]      =       subparsers.add_parser("""config"""							,   description=A__ )
  else:
    lowerCAmelCase_      :				Optional[int]      =       argparse.ArgumentParser("""Accelerate config command"""							,   description=A__ )

  parser.add_argument(
      """--config_file"""							,   default=A__							,   help=(
          """The path to use to store the config file. Will default to a file named default_config.yaml in the cache """
          """location, which is the content of the environment `HF_HOME` suffixed with 'accelerate', or if you don't have """
          """such an environment variable, your cache directory ('~/.cache' or the content of `XDG_CACHE_HOME`) suffixed """
          """with 'huggingface'."""
      )							,   )

  if subparsers is not None:
    parser.set_defaults(func=A__ )
  return parser







def     UpperCamelCase_      (   A__ :       Any ):
  '''simple docstring'''





  lowerCAmelCase_      :				Dict      =       get_user_input()
  if args.config_file is not None:
    lowerCAmelCase_      :				List[str]      =       args.config_file
  else:
    if not os.path.isdir(A__ ):
      os.makedirs(A__ )
    lowerCAmelCase_      :				List[Any]      =       default_yaml_config_file

  if config_file.endswith(""".json""" ):
    config.to_json_file(A__ )
  else:
    config.to_yaml_file(A__ )
  print(f'accelerate configuration saved at {config_file}' )







def     UpperCamelCase_      (   ):
  '''simple docstring'''





  lowerCAmelCase_      :				str      =       config_command_parser()
  lowerCAmelCase_      :				Tuple      =       parser.parse_args()
  config_command(A__ )


if __name__ == "__main__":
  main()



