



'''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					(				lowerCAmelCase_="no"						,      lowerCAmelCase_ = default_json_config_file						,      lowerCAmelCase_ = False  )      ->				Optional[int]:
		_a					:				Dict				=							Path(lowerCAmelCase_  )
		path.parent.mkdir(parents=lowerCAmelCase_						,      exist_ok=lowerCAmelCase_  )
		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
		_a					:				List[str]				=							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}"""  )
		_a					:				Dict				=							{
		    'compute_environment': 'LOCAL_MACHINE',
		    'mixed_precision': mixed_precision,
		}
		if torch.cuda.is_available():
				_a					:				List[Any]				=							torch.cuda.device_count()
				_a					:				List[Any]				=							num_gpus
				_a					:				Optional[Any]				=							False
				if num_gpus > 1:
						_a					:				int				=							'MULTI_GPU'
				else:
						_a					:				Tuple				=							'NO'
		elif is_xpu_available() and use_xpu:
				_a					:				Optional[Any]				=							torch.xpu.device_count()
				_a					:				Optional[int]				=							num_xpus
				_a					:				Union[str, Any]				=							False
				if num_xpus > 1:
						_a					:				Tuple				=							'MULTI_XPU'
				else:
						_a					:				List[str]				=							'NO'
		elif is_npu_available():
				_a					:				str				=							torch.npu.device_count()
				_a					:				Union[str, Any]				=							num_npus
				_a					:				Tuple				=							False
				if num_npus > 1:
						_a					:				List[str]				=							'MULTI_NPU'
				else:
						_a					:				List[str]				=							'NO'
		else:
				_a					:				Optional[int]				=							0
				_a					:				Optional[int]				=							True
				_a					:				List[str]				=							1
				_a					:				Union[str, Any]				=							'NO'
		_a					:				Union[str, Any]				=							ClusterConfig(**lowerCAmelCase_  )
		config.to_json_file(lowerCAmelCase_  )
		return path



def 					__lowerCamelCase					(				lowerCAmelCase_						,      lowerCAmelCase_  )      ->				Tuple:
		_a					:				List[str]				=							parser.add_parser('default'						,      parents=lowerCAmelCase_						,      help=lowerCAmelCase_						,      formatter_class=lowerCAmelCase_  )
		parser.add_argument(
		    '--config_file'						,      default=lowerCAmelCase_						,      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=lowerCAmelCase_						,      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=lowerCAmelCase_  )
		return parser



def 					__lowerCamelCase					(				lowerCAmelCase_  )      ->				Any:
		_a					:				str				=							write_basic_config(args.mixed_precision						,      args.save_location  )
		if config_file:
				print(f"""accelerate configuration saved at {config_file}"""  )









'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__lowerCAmelCase						      =       {
    '''configuration_data2vec_audio''': ['''DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''Data2VecAudioConfig'''],
    '''configuration_data2vec_text''': [
        '''DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''Data2VecTextConfig''',
        '''Data2VecTextOnnxConfig''',
    ],
    '''configuration_data2vec_vision''': [
        '''DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''Data2VecVisionConfig''',
        '''Data2VecVisionOnnxConfig''',
    ],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__lowerCAmelCase						      =       [
							    '''DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''Data2VecAudioForAudioFrameClassification''',
							    '''Data2VecAudioForCTC''',
							    '''Data2VecAudioForSequenceClassification''',
							    '''Data2VecAudioForXVector''',
							    '''Data2VecAudioModel''',
							    '''Data2VecAudioPreTrainedModel''',
							]
							__lowerCAmelCase						      =       [
							    '''DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''Data2VecTextForCausalLM''',
							    '''Data2VecTextForMaskedLM''',
							    '''Data2VecTextForMultipleChoice''',
							    '''Data2VecTextForQuestionAnswering''',
							    '''Data2VecTextForSequenceClassification''',
							    '''Data2VecTextForTokenClassification''',
							    '''Data2VecTextModel''',
							    '''Data2VecTextPreTrainedModel''',
							]
							__lowerCAmelCase						      =       [
							    '''DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''Data2VecVisionForImageClassification''',
							    '''Data2VecVisionForMaskedImageModeling''',
							    '''Data2VecVisionForSemanticSegmentation''',
							    '''Data2VecVisionModel''',
							    '''Data2VecVisionPreTrainedModel''',
							]

if is_tf_available():
							__lowerCAmelCase						      =       [
							    '''TFData2VecVisionForImageClassification''',
							    '''TFData2VecVisionForSemanticSegmentation''',
							    '''TFData2VecVisionModel''',
							    '''TFData2VecVisionPreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_dataavec_audio import DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP, DataaVecAudioConfig
							from .configuration_dataavec_text import (
							    DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    DataaVecTextConfig,
							    DataaVecTextOnnxConfig,
							)
							from .configuration_dataavec_vision import (
							    DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    DataaVecVisionConfig,
							    DataaVecVisionOnnxConfig,
							)

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_dataavec_audio import (
														    DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DataaVecAudioForAudioFrameClassification,
														    DataaVecAudioForCTC,
														    DataaVecAudioForSequenceClassification,
														    DataaVecAudioForXVector,
														    DataaVecAudioModel,
														    DataaVecAudioPreTrainedModel,
														)
														from .modeling_dataavec_text import (
														    DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DataaVecTextForCausalLM,
														    DataaVecTextForMaskedLM,
														    DataaVecTextForMultipleChoice,
														    DataaVecTextForQuestionAnswering,
														    DataaVecTextForSequenceClassification,
														    DataaVecTextForTokenClassification,
														    DataaVecTextModel,
														    DataaVecTextPreTrainedModel,
														)
														from .modeling_dataavec_vision import (
														    DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DataaVecVisionForImageClassification,
														    DataaVecVisionForMaskedImageModeling,
														    DataaVecVisionForSemanticSegmentation,
														    DataaVecVisionModel,
														    DataaVecVisionPreTrainedModel,
														)
							if is_tf_available():
														from .modeling_tf_dataavec_vision import (
														    TFDataaVecVisionForImageClassification,
														    TFDataaVecVisionForSemanticSegmentation,
														    TFDataaVecVisionModel,
														    TFDataaVecVisionPreTrainedModel,
														)

else:
							import sys

							__lowerCAmelCase						      =       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




