
"""simple docstring"""







from pathlib import Path

import torch

from ...utils import is_npu_available, is_xpu_available
from .config_args import ClusterConfig, default_json_config_file
from .config_utils import SubcommandHelpFormatter


lowerCamelCase__        =		'Create a default config file for Accelerate with only a few flags set.'
def    __lowerCAmelCase    (_UpperCamelCase="no"	,  _UpperCamelCase = default_json_config_file	,  _UpperCamelCase = False		):
	__lowerCAmelCase      :						int						      =				Path(UpperCAmelCase_		)
	path.parent.mkdir(parents=UpperCAmelCase_	,  exist_ok=UpperCAmelCase_		)
	if path.exists():
		print(
		    F"Configuration already exists at {save_location}, will not override. Run `accelerate config` manually or pass a different `save_location`."		)
		return False
	__lowerCAmelCase      :						Optional[int]						      =				mixed_precision.lower()
	if mixed_precision not in ["no", "fp16", "bf16", "fp8"]:
		raise ValueError(
		    F"`mixed_precision` should be one of 'no', 'fp16', 'bf16', or 'fp8'. Received {mixed_precision}"		)
	__lowerCAmelCase      :						str						      =				{
	    'compute_environment': 'LOCAL_MACHINE',
	    'mixed_precision': mixed_precision,
	}
	if torch.cuda.is_available():
		__lowerCAmelCase      :						int						      =				torch.cuda.device_count()
		__lowerCAmelCase      :						Tuple						      =				num_gpus
		__lowerCAmelCase      :						Dict						      =				False
		if num_gpus > 1:
			__lowerCAmelCase      :						Optional[Any]						      =				'MULTI_GPU'
		else:
			__lowerCAmelCase      :						Optional[Any]						      =				'NO'
	elif is_xpu_available() and use_xpu:
		__lowerCAmelCase      :						str						      =				torch.xpu.device_count()
		__lowerCAmelCase      :						List[str]						      =				num_xpus
		__lowerCAmelCase      :						Optional[Any]						      =				False
		if num_xpus > 1:
			__lowerCAmelCase      :						Optional[Any]						      =				'MULTI_XPU'
		else:
			__lowerCAmelCase      :						Any						      =				'NO'
	elif is_npu_available():
		__lowerCAmelCase      :						Dict						      =				torch.npu.device_count()
		__lowerCAmelCase      :						Optional[Any]						      =				num_npus
		__lowerCAmelCase      :						Dict						      =				False
		if num_npus > 1:
			__lowerCAmelCase      :						Any						      =				'MULTI_NPU'
		else:
			__lowerCAmelCase      :						Optional[int]						      =				'NO'
	else:
		__lowerCAmelCase      :						Union[str, Any]						      =				0
		__lowerCAmelCase      :						List[str]						      =				True
		__lowerCAmelCase      :						str						      =				1
		__lowerCAmelCase      :						List[Any]						      =				'NO'
	__lowerCAmelCase      :						Any						      =				ClusterConfig(**UpperCAmelCase_		)
	config.to_json_file(UpperCAmelCase_		)
	return path
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):
	__lowerCAmelCase      :						int						      =				parser.add_parser('default'	,  parents=UpperCAmelCase_	,  help=UpperCAmelCase_	,  formatter_class=UpperCAmelCase_		)
	parser.add_argument(
	    '--config_file'	,  default=UpperCAmelCase_	,  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\'.'
	    )	,  dest='save_location'	,  )

	parser.add_argument(
	    '--mixed_precision'	,  choices=['no', 'fp16', 'bf16']	,  type=UpperCAmelCase_	,  help='Whether or not to use mixed precision training. '
	    'Choose between FP16 and BF16 (bfloat16) training. '
	    'BF16 training is only supported on Nvidia Ampere GPUs and PyTorch 1.10 or later.'	,  default='no'	,  )
	parser.set_defaults(func=UpperCAmelCase_		)
	return parser
def    __lowerCAmelCase    (_UpperCamelCase		):
	__lowerCAmelCase      :						List[Any]						      =				write_basic_config(args.mixed_precision	,  args.save_location		)
	if config_file:
		print(F"accelerate configuration saved at {config_file}"		)

"""simple docstring"""







import warnings
from functools import wraps
from typing import Callable
def    __lowerCAmelCase    (_UpperCamelCase		):

	@wraps(_UpperCamelCase		)
	def _inner_fn(*_UpperCamelCase	,  **_UpperCamelCase		):
		warnings.warn(
		    (F"'{fn.__name__}' is experimental and might be subject to breaking changes in the future.")	,  _UpperCamelCase	,  )
		return fn(*_UpperCamelCase	,  **_UpperCamelCase		)

	return _inner_fn