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






			'''simple docstring'''

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

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

			__UpperCamelCase :  Tuple    =	Path("""tests/test_configs"""					)

			@classmethod
			def  lowerCAmelCase__		(    cls	:    Optional[int] ):
							if cls.config_path.is_file():
											cls.config_path.rename(cls.changed_path )

			@classmethod
			def  lowerCAmelCase__		(    cls	:    Any ):
							if cls.changed_path.is_file():
											cls.changed_path.rename(cls.config_path )

			def  lowerCAmelCase__		(    self	:    int ):
							UpperCamelCase_:							List[Any]		=  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	:    int ):
							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  lowerCAmelCase__		(    self	:    int ):
							execute_subprocess_async(["""accelerate""", """test"""]  ,		env=os.environ.copy() )




class     _UpperCamelCase			(   unittest.TestCase					):






			'''simple docstring'''

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

			def  lowerCAmelCase__		(    self	:    int ):
							UpperCamelCase_:							Tuple		=  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  lowerCAmelCase__		(    self	:    Any ):
							UpperCamelCase_:							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=snake_case_  ,		)
							self.assertIn(
							    f'''{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all'''  ,		snake_case_  ,		)

			def  lowerCAmelCase__		(    self	:    Any ):
							UpperCamelCase_:							Union[str, Any]		=  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  lowerCAmelCase__		(    self	:    List[str] ):
							UpperCamelCase_:							str		=  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  lowerCAmelCase__		(    self	:    Tuple ):
							UpperCamelCase_:							int		=  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  lowerCAmelCase__		(    self	:    Optional[int] ):
							UpperCamelCase_:							Dict		=  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  lowerCAmelCase__		(    self	:    List[Any] ):
							UpperCamelCase_:							Optional[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=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  lowerCAmelCase__		(    self	:    Dict ):
							UpperCamelCase_:							List[Any]		=  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  lowerCAmelCase__		(    self	:    Any ):
							UpperCamelCase_:							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_  ,		)








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


lowerCamelCase_  :	Tuple 				=					logging.get_logger(__name__)

lowerCamelCase_  :	str 				=					{
    """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json""",
}

class     _UpperCamelCase			(   _A					):






			'''simple docstring'''

			__UpperCamelCase :  Any    =	"""lxmert"""
			__UpperCamelCase :  Optional[Any]    =	{}

			def __init__(    self	:    Dict  ,		snake_case_	:    List[str]=3_0522  ,		snake_case_	:    int=768  ,		snake_case_	:    str=12  ,		snake_case_	:    Tuple=9500  ,		snake_case_	:    Optional[Any]=1600  ,		snake_case_	:    str=400  ,		snake_case_	:    List[str]=3072  ,		snake_case_	:    Dict="gelu"  ,		snake_case_	:    Optional[Any]=0.1  ,		snake_case_	:    int=0.1  ,		snake_case_	:    Optional[int]=512  ,		snake_case_	:    Tuple=2  ,		snake_case_	:    Optional[int]=0.02  ,		snake_case_	:    Union[str, Any]=1e-12  ,		snake_case_	:    Tuple=9  ,		snake_case_	:    Tuple=5  ,		snake_case_	:    Union[str, Any]=5  ,		snake_case_	:    List[str]=2048  ,		snake_case_	:    Any=4  ,		snake_case_	:    int=6.67  ,		snake_case_	:    Dict=True  ,		snake_case_	:    Tuple=True  ,		snake_case_	:    int=True  ,		snake_case_	:    str=True  ,		snake_case_	:    List[Any]=True  ,		snake_case_	:    List[Any]=True  ,		snake_case_	:    List[str]=True  ,		**snake_case_	:    Optional[int]  ,		):
							UpperCamelCase_:							int		=  vocab_size
							UpperCamelCase_:							Tuple		=  hidden_size
							UpperCamelCase_:							Optional[Any]		=  num_attention_heads
							UpperCamelCase_:							List[str]		=  hidden_act
							UpperCamelCase_:							int		=  intermediate_size
							UpperCamelCase_:							Any		=  hidden_dropout_prob
							UpperCamelCase_:							List[Any]		=  attention_probs_dropout_prob
							UpperCamelCase_:							List[str]		=  max_position_embeddings
							UpperCamelCase_:							Optional[Any]		=  type_vocab_size
							UpperCamelCase_:							Optional[Any]		=  initializer_range
							UpperCamelCase_:							str		=  layer_norm_eps
							UpperCamelCase_:							List[str]		=  num_qa_labels
							UpperCamelCase_:							List[str]		=  num_object_labels
							UpperCamelCase_:							Tuple		=  num_attr_labels
							UpperCamelCase_:							List[Any]		=  l_layers
							UpperCamelCase_:							List[Any]		=  x_layers
							UpperCamelCase_:							Any		=  r_layers
							UpperCamelCase_:							str		=  visual_feat_dim
							UpperCamelCase_:							Union[str, Any]		=  visual_pos_dim
							UpperCamelCase_:							str		=  visual_loss_normalizer
							UpperCamelCase_:							Dict		=  task_matched
							UpperCamelCase_:							Tuple		=  task_mask_lm
							UpperCamelCase_:							List[str]		=  task_obj_predict
							UpperCamelCase_:							Any		=  task_qa
							UpperCamelCase_:							Dict		=  visual_obj_loss
							UpperCamelCase_:							Optional[Any]		=  visual_attr_loss
							UpperCamelCase_:							List[Any]		=  visual_feat_loss
							UpperCamelCase_:							Tuple		=  {"""vision""": r_layers, """cross_encoder""": x_layers, """language""": l_layers}
							super().__init__(**snake_case_ )






