



import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp



def 		lowerCAmelCase__    (					)->  Dict:
    A__		 =					ArgumentParser(
        description=(
            '''PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes'''
        )	)

    # Optional arguments for the launch helper
    parser.add_argument('''--num_cores''' ,       type=lowerCamelCase_ ,       default=1 ,       help='''Number of TPU cores to use (1 or 8).'''	)

    # positional
    parser.add_argument(
        '''training_script''' ,       type=lowerCamelCase_ ,       help=(
            '''The full path to the single TPU training '''
            '''program/script to be launched in parallel, '''
            '''followed by all the arguments for the '''
            '''training script'''
        ) ,       )

    # rest from the training program
    parser.add_argument('''training_script_args''' ,       nargs=lowerCamelCase_	)

    return parser.parse_args()



def 		lowerCAmelCase__    (					)->  str:
    A__		 =					parse_args()

    # Import training_script as a module.
    A__		 =					Path(args.training_script	)
    sys.path.append(str(script_fpath.parent.resolve()	)	)
    A__		 =					script_fpath.stem
    A__		 =					importlib.import_module(lowerCamelCase_	)

    # Patch sys.argv
    A__		 =					[args.training_script] + args.training_script_args + ["""--tpu_num_cores""", str(args.num_cores	)]

    xmp.spawn(mod._mp_fn ,       args=() ,       nprocs=args.num_cores	)


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:
    A__		 =					XGBClassifier()
    classifier.fit(UpperCamelCase_ ,       UpperCamelCase_	)
    return classifier



def 		lowerCAmelCase__    (					)->  None:
    A__		 =					load_iris()
    A__ ,	A__		 =					data_handling(UpperCamelCase_	)
    A__ ,	A__ ,	A__ ,	A__		 =					train_test_split(
        UpperCamelCase_ ,       UpperCamelCase_ ,       test_size=0.25	)

    A__		 =					iris['''target_names''']

    # Create an XGBoost Classifier from the training data
    A__		 =					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()
