






"""simple docstring"""





import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_multi_gpu,
    require_single_gpu,
    test_sync,
)
from accelerate.utils import patch_environment
class  __lowerCamelCase     (	unittest.TestCase	):

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							List[str]:
       UpperCamelCase__								=     inspect.getfile(accelerate.test_utils   )
       UpperCamelCase__								=     os.path.sep.join(mod_file.split(os.path.sep   )[:-1] + ['scripts', 'test_sync.py']   )

   @require_cpu
   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Dict:
       debug_launcher(test_sync.main			,					num_processes=1   )

   @require_cpu
   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Optional[Any]:
       debug_launcher(test_sync.main   )

   @require_single_gpu
   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Optional[int]:
       test_sync.main()







   @require_multi_gpu
   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Union[str, Any]:
       print(F'Found {torch.cuda.device_count()} devices.'   )
       UpperCamelCase__								=     ['torchrun', F'--nproc_per_node={torch.cuda.device_count()}', self.test_file_path]
       with patch_environment(omp_num_threads=1   ):
           execute_subprocess_async(snake_case_			,					env=os.environ.copy()   )












"""simple docstring"""





def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE = 10_00       )       ->						str:
    """simple docstring"""

    if (not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )) or (digit_position <= 0):
        raise ValueError('Digit position must be a positive integer'       )
    elif (not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )) or (precision < 0):
        raise ValueError('Precision must be a nonnegative integer'       )

    # compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
    # accurate
    UpperCamelCase__								=     (
        4 * _subsum(SCREAMING_SNAKE_CASE			,						1			,						SCREAMING_SNAKE_CASE       )
        - 2 * _subsum(SCREAMING_SNAKE_CASE			,						4			,						SCREAMING_SNAKE_CASE       )
        - _subsum(SCREAMING_SNAKE_CASE			,						5			,						SCREAMING_SNAKE_CASE       )
        - _subsum(SCREAMING_SNAKE_CASE			,						6			,						SCREAMING_SNAKE_CASE       )
    )

    # return the first hex digit of the fractional part of the result
    return hex(int((sum_result % 1) * 16       )       )[2:]







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						float:
    """simple docstring"""

    UpperCamelCase__								=     0.0
    for sum_index in range(digit_pos_to_extract + precision       ):
        UpperCamelCase__								=     8 * sum_index + denominator_addend
        if sum_index < digit_pos_to_extract:
            # if the exponential term is an integer and we mod it by the denominator
            # before dividing, only the integer part of the sum will change;
            # the fractional part will not
            UpperCamelCase__								=     pow(
                16			,						digit_pos_to_extract - 1 - sum_index			,						SCREAMING_SNAKE_CASE       )
        else:
            UpperCamelCase__								=     pow(16			,						digit_pos_to_extract - 1 - sum_index       )
        total += exponential_term / denominator
    return total


if __name__ == "__main__":
  import doctest

  doctest.testmod()




