

'''simple docstring'''
import copy
import os
from typing import Union

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


lowerCamelCase			:				Any 			=					logging.get_logger(__name__)

lowerCamelCase			:				Optional[int] 			=					{
    """Salesforce/blip-vqa-base""": """https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json""",
    """Salesforce/blip-vqa-capfit-large""": (
        """https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-base""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-large""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json"""
    ),
    """Salesforce/blip-itm-base-coco""": """https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-large-coco""": """https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-base-flikr""": """https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json""",
    """Salesforce/blip-itm-large-flikr""": (
        """https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json"""
    ),
}







class 							A__   (	lowerCamelCase__  ):
		A__					=    'blip_text_model'





		def __init__(		self				:     int							, _a				:     Union[str, Any]=3_0524							, _a				:     Any=768							, _a				:     Dict=768							, _a				:     List[str]=3072							, _a				:     Union[str, Any]=768							, _a				:     Dict=12							, _a				:     Any=8							, _a				:     Union[str, Any]=512							, _a				:     Optional[Any]="gelu"							, _a				:     Tuple=1e-12							, _a				:     str=0.0							, _a				:     Any=0.0							, _a				:     Tuple=0.02							, _a				:     int=3_0522							, _a				:     int=2							, _a				:     List[str]=0							, _a				:     int=102							, _a				:     str=True							, _a				:     Any=True							, **_a				:     List[str]							, )     ->   List[Any]:





							'''simple docstring'''






							super().__init__(
							    pad_token_id=_a							, bos_token_id=_a							, eos_token_id=_a							, sep_token_id=_a							, **_a							, )

							_SCREAMING_SNAKE_CASE							   =vocab_size
							_SCREAMING_SNAKE_CASE							   =hidden_size
							_SCREAMING_SNAKE_CASE							   =encoder_hidden_size
							_SCREAMING_SNAKE_CASE							   =intermediate_size
							_SCREAMING_SNAKE_CASE							   =projection_dim
							_SCREAMING_SNAKE_CASE							   =hidden_dropout_prob
							_SCREAMING_SNAKE_CASE							   =num_hidden_layers
							_SCREAMING_SNAKE_CASE							   =num_attention_heads
							_SCREAMING_SNAKE_CASE							   =max_position_embeddings
							_SCREAMING_SNAKE_CASE							   =layer_norm_eps
							_SCREAMING_SNAKE_CASE							   =hidden_act
							_SCREAMING_SNAKE_CASE							   =initializer_range
							_SCREAMING_SNAKE_CASE							   =attention_probs_dropout_prob
							_SCREAMING_SNAKE_CASE							   =is_decoder
							_SCREAMING_SNAKE_CASE							   =use_cache





		@classmethod
		def 						A  (		cls				:     Union[str, Any]							, _a				:     List[str]							, **_a				:     Optional[int]			)     ->   List[str]:





							'''simple docstring'''






							cls._set_token_in_kwargs(_a			)

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

							# get the text config dict if we are loading from BlipConfig
							if config_dict.get('model_type'			) == "blip":
												_SCREAMING_SNAKE_CASE							   =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__   (	lowerCamelCase__  ):
		A__					=    'blip_vision_model'





		def __init__(		self				:     Any							, _a				:     int=768							, _a				:     List[Any]=3072							, _a				:     int=512							, _a				:     Optional[Any]=12							, _a				:     Optional[int]=12							, _a				:     Optional[int]=384							, _a				:     List[str]=16							, _a				:     Dict="gelu"							, _a				:     Tuple=1e-5							, _a				:     Optional[int]=0.0							, _a				:     str=1e-10							, **_a				:     str							, )     ->   Optional[int]:





							'''simple docstring'''






							super().__init__(**_a			)

							_SCREAMING_SNAKE_CASE							   =hidden_size
							_SCREAMING_SNAKE_CASE							   =intermediate_size
							_SCREAMING_SNAKE_CASE							   =projection_dim
							_SCREAMING_SNAKE_CASE							   =num_hidden_layers
							_SCREAMING_SNAKE_CASE							   =num_attention_heads
							_SCREAMING_SNAKE_CASE							   =patch_size
							_SCREAMING_SNAKE_CASE							   =image_size
							_SCREAMING_SNAKE_CASE							   =initializer_range
							_SCREAMING_SNAKE_CASE							   =attention_dropout
							_SCREAMING_SNAKE_CASE							   =layer_norm_eps
							_SCREAMING_SNAKE_CASE							   =hidden_act





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





							'''simple docstring'''






							cls._set_token_in_kwargs(_a			)

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

							# get the vision config dict if we are loading from BlipConfig
							if config_dict.get('model_type'			) == "blip":
												_SCREAMING_SNAKE_CASE							   =config_dict['vision_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__   (	lowerCamelCase__  ):
		A__					=    'blip'
		A__					=    True





		def __init__(		self				:     Union[str, Any]							, _a				:     List[str]=None							, _a				:     str=None							, _a				:     int=512							, _a				:     Dict=2.65_92							, _a				:     List[str]=256							, **_a				:     Optional[int]							, )     ->   Dict:





							'''simple docstring'''






							super().__init__(**_a			)

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

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

							_SCREAMING_SNAKE_CASE							   =BlipTextConfig(**_a			)
							_SCREAMING_SNAKE_CASE							   =BlipVisionConfig(**_a			)

							_SCREAMING_SNAKE_CASE							   =self.vision_config.hidden_size

							_SCREAMING_SNAKE_CASE							   =projection_dim
							_SCREAMING_SNAKE_CASE							   =logit_scale_init_value
							_SCREAMING_SNAKE_CASE							   =1.0
							_SCREAMING_SNAKE_CASE							   =0.02
							_SCREAMING_SNAKE_CASE							   =image_text_hidden_size





		@classmethod
		def 						A  (		cls				:     List[str]							, _a				:     List[str]							, _a				:     int							, **_a				:     Dict			)     ->   Dict:





							'''simple docstring'''






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





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





							'''simple docstring'''






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



'''simple docstring'''
from datasets.utils.patching import _PatchedModuleObj, patch_submodule

from . import _test_patching


def 	_lowerCAmelCase (						)				->      int:
     """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

     _SCREAMING_SNAKE_CASE							   ='__test_patch_submodule_mock__'
     with patch_submodule(_test_patching							,			'os.path.join'							,			_UpperCamelCase    ):
          # 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 (						)				->      Optional[Any]:
     """simple docstring"""




     assert _test_patching.open is open

     _SCREAMING_SNAKE_CASE							   ='__test_patch_submodule_builtin_mock__'
     # _test_patching has "open" in its globals
     assert _test_patching.open is open
     with patch_submodule(_test_patching							,			'open'							,			_UpperCamelCase    ):
          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 (						)				->      str:
     """simple docstring"""




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


def 	_lowerCAmelCase (						)				->      Optional[Any]:
     """simple docstring"""




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


def 	_lowerCAmelCase (						)				->      str:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							   ='__test_patch_submodule_start_and_stop_mock__'
     _SCREAMING_SNAKE_CASE							   =patch_submodule(_test_patching							,			'open'							,			_UpperCamelCase    )
     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[Any]:
     """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

     _SCREAMING_SNAKE_CASE							   ='__test_patch_submodule_successive_join__'
     _SCREAMING_SNAKE_CASE							   ='__test_patch_submodule_successive_dirname__'
     _SCREAMING_SNAKE_CASE							   ='__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'							,			_UpperCamelCase    ):
          with patch_submodule(_test_patching							,			'os.rename'							,			_UpperCamelCase    ):
               with patch_submodule(_test_patching							,			'os.path.dirname'							,			_UpperCamelCase    ):
                    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'							,			_UpperCamelCase    ):
          with patch_submodule(_test_patching							,			'os.path.join'							,			_UpperCamelCase    ):
               with patch_submodule(_test_patching							,			'os.path.dirname'							,			_UpperCamelCase    ):
                    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 (						)				->      Optional[Any]:
     """simple docstring"""




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