

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

import torch_xla.distributed.xla_multiprocessing as xmp
def 						_snake_case(    )							->      Optional[Any]:





    '''simple docstring'''






    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=SCREAMING_SNAKE_CASE__    ,			default=1    ,			help='Number of TPU cores to use (1 or 8).'      )

    # positional
    parser.add_argument(
        'training_script'    ,			type=SCREAMING_SNAKE_CASE__    ,			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=SCREAMING_SNAKE_CASE__      )

    return parser.parse_args()
def 						_snake_case(    )							->      Union[str, Any]:





    '''simple docstring'''






    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(SCREAMING_SNAKE_CASE__      )

    # 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()




from timeit import timeit
def 						_snake_case(    SCREAMING_SNAKE_CASE__			:	int      )							->      int:





    '''simple docstring'''






    if number < 0:
        raise ValueError('the value of input must not be negative'      )
    A__          =   0
    while number:
        number &= number - 1
        result += 1
    return result
def 						_snake_case(    SCREAMING_SNAKE_CASE__			:	int      )							->      int:





    '''simple docstring'''






    if number < 0:
        raise ValueError('the value of input must not be negative'      )
    A__          =   0
    while number:
        if number % 2 == 1:
            result += 1
        number >>= 1
    return result
def 						_snake_case(    )							->      None:





    '''simple docstring'''






    def do_benchmark(SCREAMING_SNAKE_CASE__			:	int      ) -> None:
        A__          =   'import __main__ as z'
        print(f'Benchmark when {number = }:'      )
        print(f'{get_set_bits_count_using_modulo_operator(SCREAMING_SNAKE_CASE__      ) = }'      )
        A__          =   timeit('z.get_set_bits_count_using_modulo_operator(25)'    ,			setup=SCREAMING_SNAKE_CASE__      )
        print(f'timeit() runs in {timing} seconds'      )
        print(f'{get_set_bits_count_using_brian_kernighans_algorithm(SCREAMING_SNAKE_CASE__      ) = }'      )
        A__          =   timeit(
            'z.get_set_bits_count_using_brian_kernighans_algorithm(25)'    ,			setup=SCREAMING_SNAKE_CASE__    ,			)
        print(f'timeit() runs in {timing} seconds'      )

    for number in (25, 37, 58, 0):
        do_benchmark(SCREAMING_SNAKE_CASE__      )
        print()


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     benchmark()

