
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


lowercase__         ='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	(							):
 __a					:    Optional[Any]													=    _ask_options(
     '''In which compute environment are you running?'''    ,  ['''This machine''', '''AWS (Amazon SageMaker)''']    ,  _convert_compute_environment    ,  )
 if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
  __a					:    str													=    get_sagemaker_input()
 else:
  __a					:    Tuple													=    get_cluster_input()
 return config




def   __UpperCamelCase	(							lowerCAmelCase__				:							Any=None    ):
 if subparsers is not None:
  __a					:    Tuple													=    subparsers.add_parser('''config'''    ,  description=snake_case__    )
 else:
  __a					:    List[Any]													=    argparse.ArgumentParser('''Accelerate config command'''    ,  description=snake_case__    )

 parser.add_argument(
     '''--config_file'''    ,  default=snake_case__    ,  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=snake_case__    )
 return parser




def   __UpperCamelCase	(							lowerCAmelCase__				:							Tuple    ):
 __a					:    Union[str, Any]													=    get_user_input()
 if args.config_file is not None:
  __a					:    Dict													=    args.config_file
 else:
  if not os.path.isdir(snake_case__    ):
   os.makedirs(snake_case__    )
  __a					:    Union[str, Any]													=    default_yaml_config_file

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




def   __UpperCamelCase	(							):
 __a					:    Dict													=    config_command_parser()
 __a					:    Dict													=    parser.parse_args()
 config_command(snake_case__    )


if __name__ == "__main__":
      main()


"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_lowercase				 =					{
    '''configuration_electra''': ['''ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ElectraConfig''', '''ElectraOnnxConfig'''],
    '''tokenization_electra''': ['''ElectraTokenizer'''],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					['''ElectraTokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					[
		    '''ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ElectraForCausalLM''',
		    '''ElectraForMaskedLM''',
		    '''ElectraForMultipleChoice''',
		    '''ElectraForPreTraining''',
		    '''ElectraForQuestionAnswering''',
		    '''ElectraForSequenceClassification''',
		    '''ElectraForTokenClassification''',
		    '''ElectraModel''',
		    '''ElectraPreTrainedModel''',
		    '''load_tf_weights_in_electra''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					[
		    '''TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFElectraForMaskedLM''',
		    '''TFElectraForMultipleChoice''',
		    '''TFElectraForPreTraining''',
		    '''TFElectraForQuestionAnswering''',
		    '''TFElectraForSequenceClassification''',
		    '''TFElectraForTokenClassification''',
		    '''TFElectraModel''',
		    '''TFElectraPreTrainedModel''',
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				 =					[
		    '''FlaxElectraForCausalLM''',
		    '''FlaxElectraForMaskedLM''',
		    '''FlaxElectraForMultipleChoice''',
		    '''FlaxElectraForPreTraining''',
		    '''FlaxElectraForQuestionAnswering''',
		    '''FlaxElectraForSequenceClassification''',
		    '''FlaxElectraForTokenClassification''',
		    '''FlaxElectraModel''',
		    '''FlaxElectraPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
		from .tokenization_electra import ElectraTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_electra_fast import ElectraTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_electra import (
				    ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ElectraForCausalLM,
				    ElectraForMaskedLM,
				    ElectraForMultipleChoice,
				    ElectraForPreTraining,
				    ElectraForQuestionAnswering,
				    ElectraForSequenceClassification,
				    ElectraForTokenClassification,
				    ElectraModel,
				    ElectraPreTrainedModel,
				    load_tf_weights_in_electra,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_electra import (
				    TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFElectraForMaskedLM,
				    TFElectraForMultipleChoice,
				    TFElectraForPreTraining,
				    TFElectraForQuestionAnswering,
				    TFElectraForSequenceClassification,
				    TFElectraForTokenClassification,
				    TFElectraModel,
				    TFElectraPreTrainedModel,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_electra import (
				    FlaxElectraForCausalLM,
				    FlaxElectraForMaskedLM,
				    FlaxElectraForMultipleChoice,
				    FlaxElectraForPreTraining,
				    FlaxElectraForQuestionAnswering,
				    FlaxElectraForSequenceClassification,
				    FlaxElectraForTokenClassification,
				    FlaxElectraModel,
				    FlaxElectraPreTrainedModel,
				)

else:
		import sys

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