
"""simple docstring"""

import inspect
import os
import unittest
from pathlib import Path

import torch

import accelerate
from accelerate.test_utils import execute_subprocess_async
from accelerate.test_utils.testing import run_command
class      _UpperCAmelCase							(		unittest.TestCase							):
      __SCREAMING_SNAKE_CASE   :							Union[str, Any]							      =	inspect.getfile(accelerate.test_utils							)
      __SCREAMING_SNAKE_CASE   :							Dict							      =	os.path.sep.join(mod_file.split(os.path.sep							)[:-1] + ["scripts", "test_cli.py"]							)

      __SCREAMING_SNAKE_CASE   :							Optional[Any]							      =	["accelerate", "launch"]
      __SCREAMING_SNAKE_CASE   :							int							      =	Path.home() / ".cache/huggingface/accelerate"
      __SCREAMING_SNAKE_CASE   :							Any							      =	"default_config.yaml"
      __SCREAMING_SNAKE_CASE   :							List[str]							      =	config_folder / config_file
      __SCREAMING_SNAKE_CASE   :							List[str]							      =	config_folder / "_default_config.yaml"

      __SCREAMING_SNAKE_CASE   :							List[str]							      =	Path("tests/test_configs"							)




      @classmethod
      def     a_      (							cls							)						->					int:
          if cls.config_path.is_file():
              cls.config_path.rename(cls.changed_path							)




      @classmethod
      def     a_      (							cls							)						->					Dict:
          if cls.changed_path.is_file():
              cls.changed_path.rename(cls.config_path							)




      def     a_      (							self							)						->					Optional[Any]:
          UpperCAmelCase									=					self.base_cmd
          if torch.cuda.is_available() and (torch.cuda.device_count() > 1):
              cmd += ["--multi_gpu"]
          execute_subprocess_async(cmd + [self.test_file_path]   ,       env=os.environ.copy()							)




      def     a_      (							self							)						->					List[str]:
          for config in sorted(self.test_config_path.glob('**/*.yaml'							)							):
              with self.subTest(config_file=lowercase_							):
                  execute_subprocess_async(
                      self.base_cmd + ['--config_file', str(lowercase_							), self.test_file_path]   ,       env=os.environ.copy()							)




      def     a_      (							self							)						->					List[str]:
          execute_subprocess_async(['accelerate', 'test']   ,       env=os.environ.copy()							)

class      _UpperCAmelCase							(		unittest.TestCase							):
      __SCREAMING_SNAKE_CASE   :							List[Any]							      =	"test-tpu"
      __SCREAMING_SNAKE_CASE   :							Optional[Any]							      =	"us-central1-a"
      __SCREAMING_SNAKE_CASE   :							int							      =	"ls"
      __SCREAMING_SNAKE_CASE   :							str							      =	["accelerate", "tpu-config"]
      __SCREAMING_SNAKE_CASE   :							Optional[int]							      =	"cd /usr/share"
      __SCREAMING_SNAKE_CASE   :							Any							      =	"tests/test_samples/test_command_file.sh"
      __SCREAMING_SNAKE_CASE   :							List[Any]							      =	"Running gcloud compute tpus tpu-vm ssh"




      def     a_      (							self							)						->					str:
          UpperCAmelCase									=					run_command(
              self.cmd
              + ['--command', self.command, '--tpu_zone', self.tpu_zone, '--tpu_name', self.tpu_name, '--debug']   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Optional[Any]:
          UpperCAmelCase									=					run_command(
              self.cmd
              + [
                  '--config_file',
                  'tests/test_configs/0_12_0.yaml',
                  '--command',
                  self.command,
                  '--tpu_zone',
                  self.tpu_zone,
                  '--tpu_name',
                  self.tpu_name,
                  '--debug',
              ]   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Optional[Any]:
          UpperCAmelCase									=					run_command(
              self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--debug']   ,       return_stdout=lowercase_							)
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo \"hello world\"; echo \"this is a second command\" --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Tuple:
          UpperCAmelCase									=					run_command(
              self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--command', self.command, '--debug']   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Optional[int]:
          UpperCAmelCase									=					run_command(
              self.cmd
              + [
                  '--config_file',
                  'tests/test_configs/latest.yaml',
                  '--command',
                  self.command,
                  '--command',
                  'echo "Hello World"',
                  '--debug',
              ]   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls; echo \"Hello World\" --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Tuple:
          UpperCAmelCase									=					run_command(
              self.cmd
              + ['--config_file', 'tests/test_configs/latest.yaml', '--command_file', self.command_file, '--debug']   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo \"hello world\"; echo \"this is a second command\" --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Tuple:
          UpperCAmelCase									=					run_command(
              self.cmd
              + [
                  '--config_file',
                  'tests/test_configs/0_12_0.yaml',
                  '--command_file',
                  self.command_file,
                  '--tpu_zone',
                  self.tpu_zone,
                  '--tpu_name',
                  self.tpu_name,
                  '--debug',
              ]   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo \"hello world\"; echo \"this is a second command\" --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Dict:
          UpperCAmelCase									=					run_command(
              self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--install_accelerate', '--debug']   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; pip install accelerate -U; echo \"hello world\"; echo \"this is a second command\" --worker all"   ,       lowercase_   ,       )




      def     a_      (							self							)						->					Optional[Any]:
          UpperCAmelCase									=					run_command(
              self.cmd
              + [
                  '--config_file',
                  'tests/test_configs/latest.yaml',
                  '--install_accelerate',
                  '--accelerate_version',
                  '12.0.0',
                  '--debug',
              ]   ,       return_stdout=lowercase_   ,       )
          self.assertIn(
              F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; pip install accelerate==12.0.0; echo \"hello world\"; echo \"this is a second command\" --worker all"   ,       lowercase_   ,       )





"""simple docstring"""

def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      int:






    """simple docstring"""




    return number | (1 << position)




def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      int:






    """simple docstring"""




    return number & ~(1 << position)




def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      int:






    """simple docstring"""




    return number ^ (1 << position)




def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      bool:






    """simple docstring"""




    return ((number >> position) & 1) == 1




def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      int:






    """simple docstring"""




    return int((number & (1 << position)) != 0 )


if __name__ == "__main__":
   import doctest

   doctest.testmod()



