


'''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 A__       (						unittest.TestCase      ):
      __UpperCamelCase       :  Dict	       =							inspect.getfile(accelerate.test_utils      )
      __UpperCamelCase       :  Dict	       =							os.path.sep.join(mod_file.split(os.path.sep      )[:-1] + ["scripts", "test_cli.py"]      )

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

      __UpperCamelCase       :  Union[str, Any]	       =							Path("tests/test_configs"      )






      @classmethod
      def __UpperCAmelCase       ( cls			:List[Any]	)       ->					List[str]:




             '''simple docstring'''
             if cls.config_path.is_file():
                    cls.config_path.rename(cls.changed_path	)






      @classmethod
      def __UpperCAmelCase       ( cls			:int	)       ->					Union[str, Any]:




             '''simple docstring'''
             if cls.changed_path.is_file():
                    cls.changed_path.rename(cls.config_path	)






      def __UpperCAmelCase       ( self			:List[Any]	)       ->					Any:




             '''simple docstring'''
             _a    : Dict     					=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 __UpperCAmelCase       ( self			:List[Any]	)       ->					Union[str, Any]:




             '''simple docstring'''
             for config in sorted(self.test_config_path.glob("""**/*.yaml"""	)	):
                    with self.subTest(config_file=SCREAMING_SNAKE_CASE	):
                           execute_subprocess_async(
                               self.base_cmd + ["""--config_file""", str(SCREAMING_SNAKE_CASE	), self.test_file_path]     ,						env=os.environ.copy()	)






      def __UpperCAmelCase       ( self			:Any	)       ->					int:




             '''simple docstring'''
             execute_subprocess_async(["""accelerate""", """test"""]     ,						env=os.environ.copy()	)







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






      def __UpperCAmelCase       ( self			:Tuple	)       ->					int:




             '''simple docstring'''
             _a    : Optional[int]     					=run_command(
                 self.cmd
                 + ["""--command""", self.command, """--tpu_zone""", self.tpu_zone, """--tpu_name""", self.tpu_name, """--debug"""]     ,						return_stdout=SCREAMING_SNAKE_CASE     ,						)
             self.assertIn(
                 f"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:Tuple	)       ->					List[str]:




             '''simple docstring'''
             _a    : Optional[Any]     					=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=SCREAMING_SNAKE_CASE     ,						)
             self.assertIn(
                 f"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:List[str]	)       ->					Optional[int]:




             '''simple docstring'''
             _a    : str     					=run_command(
                 self.cmd + ["""--config_file""", """tests/test_configs/latest.yaml""", """--debug"""]     ,						return_stdout=SCREAMING_SNAKE_CASE	)
             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"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:List[Any]	)       ->					Union[str, Any]:




             '''simple docstring'''
             _a    : str     					=run_command(
                 self.cmd + ["""--config_file""", """tests/test_configs/latest.yaml""", """--command""", self.command, """--debug"""]     ,						return_stdout=SCREAMING_SNAKE_CASE     ,						)
             self.assertIn(
                 f"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:Union[str, Any]	)       ->					List[Any]:




             '''simple docstring'''
             _a    : Optional[Any]     					=run_command(
                 self.cmd
                 + [
                     """--config_file""",
                     """tests/test_configs/latest.yaml""",
                     """--command""",
                     self.command,
                     """--command""",
                     """echo \"Hello World\"""",
                     """--debug""",
                 ]     ,						return_stdout=SCREAMING_SNAKE_CASE     ,						)
             self.assertIn(
                 f"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls; echo \"Hello World\" --worker all"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:List[Any]	)       ->					Union[str, Any]:




             '''simple docstring'''
             _a    : str     					=run_command(
                 self.cmd
                 + ["""--config_file""", """tests/test_configs/latest.yaml""", """--command_file""", self.command_file, """--debug"""]     ,						return_stdout=SCREAMING_SNAKE_CASE     ,						)
             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"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:Union[str, Any]	)       ->					Optional[Any]:




             '''simple docstring'''
             _a    : Any     					=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=SCREAMING_SNAKE_CASE     ,						)
             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"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:Union[str, Any]	)       ->					int:




             '''simple docstring'''
             _a    : Any     					=run_command(
                 self.cmd + ["""--config_file""", """tests/test_configs/latest.yaml""", """--install_accelerate""", """--debug"""]     ,						return_stdout=SCREAMING_SNAKE_CASE     ,						)
             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"     ,						SCREAMING_SNAKE_CASE     ,						)






      def __UpperCAmelCase       ( self			:Tuple	)       ->					Dict:




             '''simple docstring'''
             _a    : Any     					=run_command(
                 self.cmd
                 + [
                     """--config_file""",
                     """tests/test_configs/latest.yaml""",
                     """--install_accelerate""",
                     """--accelerate_version""",
                     """12.0.0""",
                     """--debug""",
                 ]     ,						return_stdout=SCREAMING_SNAKE_CASE     ,						)
             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"     ,						SCREAMING_SNAKE_CASE     ,						)






'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


A__:    str					    =       {}

try:
   if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Tuple					    =       ['''GPTSw3Tokenizer''']


if TYPE_CHECKING:
   try:
      if not is_sentencepiece_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_gpt_swa import GPTSwaTokenizer

else:
   import sys

   A__:    str					    =       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


