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



def      __lowerCAmelCase						(							UpperCAmelCase__				:      List[str]=None       )  ->    int:
							if subparsers is not None:
														lowerCamelCase_							  =					subparsers.add_parser("""config"""			,				description=lowerCamelCase_       )
							else:
														lowerCamelCase_							  =					argparse.ArgumentParser("""Accelerate config command"""			,				description=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\'."""
							    )			,				)

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



def      __lowerCAmelCase						(							UpperCAmelCase__				:      str       )  ->    List[Any]:
							lowerCamelCase_							  =					get_user_input()
							if args.config_file is not None:
														lowerCamelCase_							  =					args.config_file
							else:
														if not os.path.isdir(lowerCamelCase_       ):
																					os.makedirs(lowerCamelCase_       )
														lowerCamelCase_							  =					default_yaml_config_file

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



def      __lowerCAmelCase						(							)  ->    Dict:
							lowerCamelCase_							  =					config_command_parser()
							lowerCamelCase_							  =					parser.parse_args()
							config_command(lowerCamelCase_       )


if __name__ == "__main__":
		main()






import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn.metrics import ConfusionMatrixDisplay
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier



def      __lowerCAmelCase						(							UpperCAmelCase__				:      dict       )  ->    tuple:
							return (data["data"], data["target"])



def      __lowerCAmelCase						(							UpperCAmelCase__				:      np.ndarray			,				UpperCAmelCase__				:      np.ndarray       )  ->    XGBClassifier:
							lowerCamelCase_							  =					XGBClassifier()
							classifier.fit(UpperCAmelCase__			,				UpperCAmelCase__       )
							return classifier



def      __lowerCAmelCase						(							)  ->    None:
							lowerCamelCase_							  =					load_iris()
							lowerCamelCase_  ,   lowerCamelCase_							  =					data_handling(UpperCAmelCase__       )
							lowerCamelCase_  ,   lowerCamelCase_  ,   lowerCamelCase_  ,   lowerCamelCase_							  =					train_test_split(
							    UpperCAmelCase__			,				UpperCAmelCase__			,				test_size=0.2_5       )

							lowerCamelCase_							  =					iris["""target_names"""]

							# Create an XGBoost Classifier from the training data
							lowerCamelCase_							  =					xgboost(UpperCAmelCase__			,				UpperCAmelCase__       )

							# Display the confusion matrix of the classifier with both training and test sets
							ConfusionMatrixDisplay.from_estimator(
							    UpperCAmelCase__			,				UpperCAmelCase__			,				UpperCAmelCase__			,				display_labels=UpperCAmelCase__			,				cmap="""Blues"""			,				normalize="""true"""			,				)
							plt.title("""Normalized Confusion Matrix - IRIS Dataset"""       )
							plt.show()


if __name__ == "__main__":
		import doctest

		doctest.testmod(verbose=True)
		main()





