
"""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        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Union[str, Any]							=					inspect.getfile(accelerate.test_utils							)
				SCREAMING_SNAKE_CASE_:							Optional[int]							=					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_:							str							=					Path.home() / ".cache/huggingface/accelerate"
				SCREAMING_SNAKE_CASE_:							int							=					"default_config.yaml"
				SCREAMING_SNAKE_CASE_:							List[str]							=					config_folder / config_file
				SCREAMING_SNAKE_CASE_:							Tuple							=					config_folder / "_default_config.yaml"

				SCREAMING_SNAKE_CASE_:							Optional[int]							=					Path("tests/test_configs"							)


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







											"""simple docstring"""




											if cls.config_path.is_file():
																		cls.config_path.rename(cls.changed_path  )


				@classmethod
				def 				__lowerCamelCase	(					cls	:			Optional[Any]  )		->  Dict:







											"""simple docstring"""




											if cls.changed_path.is_file():
																		cls.changed_path.rename(cls.config_path  )


				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			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 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  List[Any]:







											"""simple docstring"""




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







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







											"""simple docstring"""




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






class        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							List[Any]							=					"test-tpu"
				SCREAMING_SNAKE_CASE_:							str							=					"us-central1-a"
				SCREAMING_SNAKE_CASE_:							Optional[int]							=					"ls"
				SCREAMING_SNAKE_CASE_:							Any							=					["accelerate", "tpu-config"]
				SCREAMING_SNAKE_CASE_:							Tuple							=					"cd /usr/share"
				SCREAMING_SNAKE_CASE_:							Optional[int]							=					"tests/test_samples/test_command_file.sh"
				SCREAMING_SNAKE_CASE_:							List[str]							=					"Running gcloud compute tpus tpu-vm ssh"


				def 				__lowerCamelCase	(					self	:			Any  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			run_command(
											    self.cmd
											    + ['--command', self.command, '--tpu_zone', self.tpu_zone, '--tpu_name', self.tpu_name, '--debug']				,     return_stdout=UpperCAmelCase_				,     )
											self.assertIn(
											    F"""{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"""				,     UpperCAmelCase_				,     )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase  	=			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=UpperCAmelCase_				,     )
											self.assertIn(
											    F"""{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"""				,     UpperCAmelCase_				,     )


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			run_command(
											    self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--debug']				,     return_stdout=UpperCAmelCase_  )
											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"""				,     UpperCAmelCase_				,     )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  Optional[Any]:







											"""simple docstring"""




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


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  Optional[int]:







											"""simple docstring"""




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


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Tuple:







											"""simple docstring"""




											_lowerCAmelCase  	=			run_command(
											    self.cmd
											    + ['--config_file', 'tests/test_configs/latest.yaml', '--command_file', self.command_file, '--debug']				,     return_stdout=UpperCAmelCase_				,     )
											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"""				,     UpperCAmelCase_				,     )


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







											"""simple docstring"""




											_lowerCAmelCase  	=			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=UpperCAmelCase_				,     )
											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"""				,     UpperCAmelCase_				,     )


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Any:







											"""simple docstring"""




											_lowerCAmelCase  	=			run_command(
											    self.cmd + ['--config_file', 'tests/test_configs/latest.yaml', '--install_accelerate', '--debug']				,     return_stdout=UpperCAmelCase_				,     )
											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"""				,     UpperCAmelCase_				,     )







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







											"""simple docstring"""




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








"""simple docstring"""



from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case          =						logging.get_logger(__name__)

_snake_case          =						{
    '''abeja/gpt-neox-japanese-2.7b''': '''https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/config.json''',
}
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Dict							=					"gpt_neox_japanese"


				def __init__(					self	:			Optional[Any]				,     UpperCAmelCase_	:			Any=32_000				,     UpperCAmelCase_	:			Dict=2_560				,     UpperCAmelCase_	:			Union[str, Any]=32				,     UpperCAmelCase_	:			Any=32				,     UpperCAmelCase_	:			Optional[Any]=4				,     UpperCAmelCase_	:			int="gelu"				,     UpperCAmelCase_	:			Union[str, Any]=1.00				,     UpperCAmelCase_	:			Any=10_000				,     UpperCAmelCase_	:			Optional[int]=2_048				,     UpperCAmelCase_	:			Optional[Any]=0.02				,     UpperCAmelCase_	:			Tuple=1E-5				,     UpperCAmelCase_	:			int=True				,     UpperCAmelCase_	:			Tuple=31_996				,     UpperCAmelCase_	:			List[Any]=31_999				,     UpperCAmelCase_	:			str=0.1				,     UpperCAmelCase_	:			List[Any]=0.0				,     **UpperCAmelCase_	:			str				,     )		->  int:







											"""simple docstring"""




											super().__init__(bos_token_id=UpperCAmelCase_				,     eos_token_id=UpperCAmelCase_				,     **UpperCAmelCase_  )
											_lowerCAmelCase  	=			vocab_size
											_lowerCAmelCase  	=			max_position_embeddings
											_lowerCAmelCase  	=			hidden_size
											_lowerCAmelCase  	=			num_hidden_layers
											_lowerCAmelCase  	=			num_attention_heads
											_lowerCAmelCase  	=			intermediate_multiple_size
											_lowerCAmelCase  	=			hidden_act
											_lowerCAmelCase  	=			rotary_pct
											_lowerCAmelCase  	=			rotary_emb_base
											_lowerCAmelCase  	=			initializer_range
											_lowerCAmelCase  	=			layer_norm_eps
											_lowerCAmelCase  	=			use_cache
											_lowerCAmelCase  	=			attention_dropout
											_lowerCAmelCase  	=			hidden_dropout






