



"""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    ):







		'''simple docstring'''





		lowerCAmelCase			:					Tuple   	=				inspect.getfile(accelerate.test_utils    )
		lowerCAmelCase			:					List[str]   	=				os.path.sep.join(mod_file.split(os.path.sep    )[:-1] + ["scripts", "test_cli.py"]    )

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

		lowerCAmelCase			:					Optional[Any]   	=				Path("tests/test_configs"    )







		@classmethod
		def 					UpperCAmelCase    (	cls						:  Optional[Any]						)					->		Optional[int]:






				"""simple docstring"""



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







		@classmethod
		def 					UpperCAmelCase    (	cls						:  str						)					->		Dict:






				"""simple docstring"""



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







		def 					UpperCAmelCase    (	self						:  Dict						)					->		Optional[int]:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			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						:  Dict						)					->		Union[str, Any]:






				"""simple docstring"""



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







		def 					UpperCAmelCase    (	self						:  Tuple						)					->		str:






				"""simple docstring"""



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





class        __A       (	unittest.TestCase    ):







		'''simple docstring'''





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







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






				"""simple docstring"""



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







		def 					UpperCAmelCase    (	self						:  Any						)					->		List[str]:






				"""simple docstring"""



				lowercase__   :    Tuple				=			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=_snake_case			,)
				self.assertIn(
				    f"""{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"""			,_snake_case			,)







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






				"""simple docstring"""



				lowercase__   :    List[str]				=			run_command(
				    self.cmd + ['''--config_file''', '''tests/test_configs/latest.yaml''', '''--debug''']			,return_stdout=_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"""			,_snake_case			,)







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






				"""simple docstring"""



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







		def 					UpperCAmelCase    (	self						:  Any						)					->		int:






				"""simple docstring"""



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







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






				"""simple docstring"""



				lowercase__   :    Optional[Any]				=			run_command(
				    self.cmd
				    + ['''--config_file''', '''tests/test_configs/latest.yaml''', '''--command_file''', self.command_file, '''--debug''']			,return_stdout=_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"""			,_snake_case			,)







		def 					UpperCAmelCase    (	self						:  Any						)					->		List[str]:






				"""simple docstring"""



				lowercase__   :    Tuple				=			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=_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"""			,_snake_case			,)







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






				"""simple docstring"""



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







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






				"""simple docstring"""



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

"""simple docstring"""




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


_a      :		List[Any]           =   logging.get_logger(__name__)

_a      :		Any           =   {
    'microsoft/swinv2-tiny-patch4-window8-256': (
        'https://huggingface.co/microsoft/swinv2-tiny-patch4-window8-256/resolve/main/config.json'
    ),
}
class 						__A							( SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:			int							=		"swinv2"

     _UpperCamelCase							:			List[str]							=		{
         "num_attention_heads": "num_heads",
         "num_hidden_layers": "num_layers",
     }






     def __init__(		self				,     a__=224				,     a__=4				,     a__=3				,     a__=96				,     a__=[2, 2, 6, 2]				,     a__=[3, 6, 12, 24]				,     a__=7				,     a__=4.0				,     a__=True				,     a__=0.0				,     a__=0.0				,     a__=0.1				,     a__="gelu"				,     a__=False				,     a__=0.0_2				,     a__=1e-5				,     a__=32				,     **a__				,     ):
       super().__init__(**a__  )

       _lowerCAmelCase						:       int  			=     image_size
       _lowerCAmelCase						:       Optional[Any]  			=     patch_size
       _lowerCAmelCase						:       Any  			=     num_channels
       _lowerCAmelCase						:       List[Any]  			=     embed_dim
       _lowerCAmelCase						:       Optional[int]  			=     depths
       _lowerCAmelCase						:       List[Any]  			=     len(a__  )
       _lowerCAmelCase						:       Any  			=     num_heads
       _lowerCAmelCase						:       Tuple  			=     window_size
       _lowerCAmelCase						:       Tuple  			=     mlp_ratio
       _lowerCAmelCase						:       Any  			=     qkv_bias
       _lowerCAmelCase						:       Optional[int]  			=     hidden_dropout_prob
       _lowerCAmelCase						:       Tuple  			=     attention_probs_dropout_prob
       _lowerCAmelCase						:       str  			=     drop_path_rate
       _lowerCAmelCase						:       List[str]  			=     hidden_act
       _lowerCAmelCase						:       List[str]  			=     use_absolute_embeddings
       _lowerCAmelCase						:       Optional[int]  			=     layer_norm_eps
       _lowerCAmelCase						:       List[Any]  			=     initializer_range
       _lowerCAmelCase						:       Any  			=     encoder_stride
       # we set the hidden_size attribute in order to make Swinv2 work with VisionEncoderDecoderModel
       # this indicates the channel dimension after the last stage of the model
       _lowerCAmelCase						:       Tuple  			=     int(embed_dim * 2 ** (len(a__  ) - 1)  )
       _lowerCAmelCase						:       Tuple  			=     (0, 0, 0, 0)




