




'''simple docstring'''


import copy
import os
from typing import Union

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


_snake_case : Dict  				=						logging.get_logger(__name__)

_snake_case : str  				=						{
    'BridgeTower/bridgetower-base': 'https://huggingface.co/BridgeTower/bridgetower-base/blob/main/config.json',
    'BridgeTower/bridgetower-base-itm-mlm': (
        'https://huggingface.co/BridgeTower/bridgetower-base-itm-mlm/blob/main/config.json'
    ),
}

class      A       (						_a       ):
							lowercase_							     =							'bridgetower_vision_model'







							def __init__(    self			:    Tuple				,     lowerCAmelCase_			:    Tuple=7_68				,     lowerCAmelCase_			:    Dict=12				,     lowerCAmelCase_			:    Tuple=3				,     lowerCAmelCase_			:    Optional[Any]=16				,     lowerCAmelCase_			:    Any=2_88				,     lowerCAmelCase_			:    List[str]=1				,     lowerCAmelCase_			:    Optional[int]=1e-05				,     lowerCAmelCase_			:    str=False				,     lowerCAmelCase_			:    List[str]=True				,     lowerCAmelCase_			:    str=False				,     **lowerCAmelCase_			:    List[str]				,     )     ->				Union[str, Any]:


														"""simple docstring"""


														super().__init__(**__a   )
														_a      	=							hidden_size
														_a      	=							num_hidden_layers
														_a      	=							num_channels
														_a      	=							patch_size
														_a      	=							image_size
														_a      	=							initializer_factor
														_a      	=							layer_norm_eps
														_a      	=							stop_gradient
														_a      	=							share_layernorm
														_a      	=							remove_last_layer







							@classmethod
							def   __lowerCAmelCase     (    cls			:    str				,     lowerCAmelCase_			:    List[str]				,     **lowerCAmelCase_			:    Optional[Any]   )     ->				"PretrainedConfig":


														"""simple docstring"""


														_a	,				_a      	=							cls.get_config_dict(__a				,     **__a   )

														if config_dict.get('''model_type'''   ) == "bridgetower":
																					_a      	=							config_dict['''text_config''']

														if "model_type" in config_dict and hasattr(cls				,     '''model_type'''   ) and config_dict["model_type"] != cls.model_type:
																					logger.warning(
																					    F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
																					    F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'   )

														return cls.from_dict(__a				,     **__a   )



class      A       (						_a       ):
							lowercase_							     =							'bridgetower_text_model'







							def __init__(    self			:    List[Any]				,     lowerCAmelCase_			:    Any=5_02_65				,     lowerCAmelCase_			:    int=7_68				,     lowerCAmelCase_			:    str=12				,     lowerCAmelCase_			:    Tuple=12				,     lowerCAmelCase_			:    Union[str, Any]=1				,     lowerCAmelCase_			:    Union[str, Any]=30_72				,     lowerCAmelCase_			:    Union[str, Any]="gelu"				,     lowerCAmelCase_			:    Tuple=0.1				,     lowerCAmelCase_			:    Optional[int]=0.1				,     lowerCAmelCase_			:    int=5_14				,     lowerCAmelCase_			:    Any=1				,     lowerCAmelCase_			:    Any=1e-05				,     lowerCAmelCase_			:    List[str]=1				,     lowerCAmelCase_			:    Optional[Any]=0				,     lowerCAmelCase_			:    List[str]=2				,     lowerCAmelCase_			:    int="absolute"				,     lowerCAmelCase_			:    Dict=True				,     **lowerCAmelCase_			:    str				,     )     ->				Any:


														"""simple docstring"""


														super().__init__(**__a   )

														_a      	=							vocab_size
														_a      	=							hidden_size
														_a      	=							num_hidden_layers
														_a      	=							num_attention_heads
														_a      	=							hidden_act
														_a      	=							initializer_factor
														_a      	=							intermediate_size
														_a      	=							hidden_dropout_prob
														_a      	=							attention_probs_dropout_prob
														_a      	=							max_position_embeddings
														_a      	=							type_vocab_size
														_a      	=							layer_norm_eps
														_a      	=							position_embedding_type
														_a      	=							use_cache
														_a      	=							pad_token_id
														_a      	=							bos_token_id
														_a      	=							eos_token_id







							@classmethod
							def   __lowerCAmelCase     (    cls			:    Tuple				,     lowerCAmelCase_			:    List[str]				,     **lowerCAmelCase_			:    Optional[int]   )     ->				"PretrainedConfig":


														"""simple docstring"""


														_a	,				_a      	=							cls.get_config_dict(__a				,     **__a   )

														if config_dict.get('''model_type'''   ) == "bridgetower":
																					_a      	=							config_dict['''text_config''']

														if "model_type" in config_dict and hasattr(cls				,     '''model_type'''   ) and config_dict["model_type"] != cls.model_type:
																					logger.warning(
																					    F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
																					    F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'   )

														return cls.from_dict(__a				,     **__a   )



class      A       (						_a       ):
							lowercase_							     =							'bridgetower'







							def __init__(    self			:    int				,     lowerCAmelCase_			:    Tuple=True				,     lowerCAmelCase_			:    Any="gelu"				,     lowerCAmelCase_			:    Union[str, Any]=7_68				,     lowerCAmelCase_			:    Optional[Any]=1				,     lowerCAmelCase_			:    int=1e-05				,     lowerCAmelCase_			:    List[Any]=False				,     lowerCAmelCase_			:    Optional[Any]="add"				,     lowerCAmelCase_			:    List[str]=12				,     lowerCAmelCase_			:    Any=6				,     lowerCAmelCase_			:    List[Any]=False				,     lowerCAmelCase_			:    Tuple=False				,     lowerCAmelCase_			:    Tuple=None				,     lowerCAmelCase_			:    Dict=None				,     **lowerCAmelCase_			:    Any				,     )     ->				Optional[int]:


														"""simple docstring"""


														_a      	=							kwargs.pop('''text_config_dict'''				,     __a   )
														_a      	=							kwargs.pop('''vision_config_dict'''				,     __a   )

														super().__init__(**__a   )
														_a      	=							share_cross_modal_transformer_layers
														_a      	=							hidden_act
														_a      	=							hidden_size
														_a      	=							initializer_factor
														_a      	=							layer_norm_eps
														_a      	=							share_link_tower_layers
														_a      	=							link_tower_type
														_a      	=							num_attention_heads
														_a      	=							num_hidden_layers
														_a      	=							tie_word_embeddings
														_a      	=							init_layernorm_from_vision_encoder

														if text_config is None:
																					_a      	=							{}
																					logger.info('''`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.'''   )

														if vision_config is None:
																					_a      	=							{}
																					logger.info('''`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values.'''   )

														_a      	=							BridgeTowerTextConfig(**__a   )
														_a      	=							BridgeTowerVisionConfig(**__a   )







							@classmethod
							def   __lowerCAmelCase     (    cls			:    List[Any]				,     lowerCAmelCase_			:    Union[str, Any]				,     lowerCAmelCase_			:    Union[str, Any]				,     **lowerCAmelCase_			:    str   )     ->				str:


														"""simple docstring"""


														return cls(text_config=text_config.to_dict()				,     vision_config=vision_config.to_dict()				,     **__a   )







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


														"""simple docstring"""


														_a      	=							copy.deepcopy(self.__dict__   )
														_a      	=							self.text_config.to_dict()
														_a      	=							self.vision_config.to_dict()
														_a      	=							self.__class__.model_type
														return output



"""simple docstring"""





from datasets.utils.patching import _PatchedModuleObj, patch_submodule

from . import _test_patching



def  lowerCamelCase__						(     )				->						List[str]:


					"""simple docstring"""





					import os as original_os
					from os import path as original_path
					from os import rename as original_rename
					from os.path import dirname as original_dirname
					from os.path import join as original_join

					assert _test_patching.os is original_os
					assert _test_patching.path is original_path
					assert _test_patching.join is original_join

					assert _test_patching.renamed_os is original_os
					assert _test_patching.renamed_path is original_path
					assert _test_patching.renamed_join is original_join

					_UpperCamelCase									=    '''__test_patch_submodule_mock__'''
					with patch_submodule(_test_patching,	'''os.path.join''',	__snake_case      ):
										# Every way to access os.path.join must be patched, and the rest must stay untouched

										# check os.path.join
										assert isinstance(_test_patching.os,	_PatchedModuleObj      )
										assert isinstance(_test_patching.os.path,	_PatchedModuleObj      )
										assert _test_patching.os.path.join is mock

										# check path.join
										assert isinstance(_test_patching.path,	_PatchedModuleObj      )
										assert _test_patching.path.join is mock

										# check join
										assert _test_patching.join is mock

										# check that the other attributes are untouched
										assert _test_patching.os.rename is original_rename
										assert _test_patching.path.dirname is original_dirname
										assert _test_patching.os.path.dirname is original_dirname

										# Even renamed modules or objects must be patched

										# check renamed_os.path.join
										assert isinstance(_test_patching.renamed_os,	_PatchedModuleObj      )
										assert isinstance(_test_patching.renamed_os.path,	_PatchedModuleObj      )
										assert _test_patching.renamed_os.path.join is mock

										# check renamed_path.join
										assert isinstance(_test_patching.renamed_path,	_PatchedModuleObj      )
										assert _test_patching.renamed_path.join is mock

										# check renamed_join
										assert _test_patching.renamed_join is mock

										# check that the other attributes are untouched
										assert _test_patching.renamed_os.rename is original_rename
										assert _test_patching.renamed_path.dirname is original_dirname
										assert _test_patching.renamed_os.path.dirname is original_dirname

					# check that everthing is back to normal when the patch is over

					assert _test_patching.os is original_os
					assert _test_patching.path is original_path
					assert _test_patching.join is original_join

					assert _test_patching.renamed_os is original_os
					assert _test_patching.renamed_path is original_path
					assert _test_patching.renamed_join is original_join



def  lowerCamelCase__						(     )				->						List[str]:


					"""simple docstring"""





					assert _test_patching.open is open

					_UpperCamelCase									=    '''__test_patch_submodule_builtin_mock__'''
					# _test_patching has "open" in its globals
					assert _test_patching.open is open
					with patch_submodule(_test_patching,	'''open''',	__snake_case      ):
										assert _test_patching.open is mock

					# check that everthing is back to normal when the patch is over

					assert _test_patching.open is open



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


					"""simple docstring"""





					_UpperCamelCase									=    '''__test_patch_submodule_missing_mock__'''
					with patch_submodule(_test_patching,	'''pandas.read_csv''',	__snake_case      ):
										pass



def  lowerCamelCase__						(     )				->						Dict:


					"""simple docstring"""





					_UpperCamelCase									=    '''__test_patch_submodule_missing_builtin_mock__'''
					# _test_patching doesn't have "len" in its globals
					assert getattr(_test_patching,	'''len''',	__snake_case      ) is None
					with patch_submodule(_test_patching,	'''len''',	__snake_case      ):
										assert _test_patching.len is mock
					assert _test_patching.len is len



def  lowerCamelCase__						(     )				->						Tuple:


					"""simple docstring"""





					_UpperCamelCase									=    '''__test_patch_submodule_start_and_stop_mock__'''
					_UpperCamelCase									=    patch_submodule(_test_patching,	'''open''',	__snake_case      )
					assert _test_patching.open is open
					patch.start()
					assert _test_patching.open is mock
					patch.stop()
					assert _test_patching.open is open



def  lowerCamelCase__						(     )				->						Optional[int]:


					"""simple docstring"""





					from os import rename as original_rename
					from os.path import dirname as original_dirname
					from os.path import join as original_join

					_UpperCamelCase									=    '''__test_patch_submodule_successive_join__'''
					_UpperCamelCase									=    '''__test_patch_submodule_successive_dirname__'''
					_UpperCamelCase									=    '''__test_patch_submodule_successive_rename__'''
					assert _test_patching.os.path.join is original_join
					assert _test_patching.os.path.dirname is original_dirname
					assert _test_patching.os.rename is original_rename

					with patch_submodule(_test_patching,	'''os.path.join''',	__snake_case      ):
										with patch_submodule(_test_patching,	'''os.rename''',	__snake_case      ):
															with patch_submodule(_test_patching,	'''os.path.dirname''',	__snake_case      ):
																				assert _test_patching.os.path.join is mock_join
																				assert _test_patching.os.path.dirname is mock_dirname
																				assert _test_patching.os.rename is mock_rename

    # try another order
					with patch_submodule(_test_patching,	'''os.rename''',	__snake_case      ):
										with patch_submodule(_test_patching,	'''os.path.join''',	__snake_case      ):
															with patch_submodule(_test_patching,	'''os.path.dirname''',	__snake_case      ):
																				assert _test_patching.os.path.join is mock_join
																				assert _test_patching.os.path.dirname is mock_dirname
																				assert _test_patching.os.rename is mock_rename

					assert _test_patching.os.path.join is original_join
					assert _test_patching.os.path.dirname is original_dirname
					assert _test_patching.os.rename is original_rename



def  lowerCamelCase__						(     )				->						str:


					"""simple docstring"""





					_UpperCamelCase									=    '''__test_patch_submodule_doesnt_exist_mock__'''
					with patch_submodule(_test_patching,	'''__module_that_doesn_exist__.__attribute_that_doesn_exist__''',	__snake_case      ):
										pass
					with patch_submodule(_test_patching,	'''os.__attribute_that_doesn_exist__''',	__snake_case      ):
										pass






