



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


lowerCAmelCase__					  =  logging.get_logger(__name__)

lowerCAmelCase__					  =  {
    '''google/pegasus-large''': '''https://huggingface.co/google/pegasus-large/resolve/main/config.json''',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}

class 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					lowercase_								=		"""pegasus"""
					lowercase_								=		["""past_key_values"""]
					lowercase_								=		{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}







					def __init__(							self :     Any				,       SCREAMING_SNAKE_CASE :     int=50_265				,       SCREAMING_SNAKE_CASE :     Optional[Any]=1_024				,       SCREAMING_SNAKE_CASE :     Dict=12				,       SCREAMING_SNAKE_CASE :     Optional[int]=4_096				,       SCREAMING_SNAKE_CASE :     Tuple=16				,       SCREAMING_SNAKE_CASE :     Tuple=12				,       SCREAMING_SNAKE_CASE :     Any=4_096				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=16				,       SCREAMING_SNAKE_CASE :     List[str]=0.0				,       SCREAMING_SNAKE_CASE :     Optional[int]=0.0				,       SCREAMING_SNAKE_CASE :     Optional[int]=True				,       SCREAMING_SNAKE_CASE :     Any=True				,       SCREAMING_SNAKE_CASE :     int="gelu"				,       SCREAMING_SNAKE_CASE :     Dict=1_024				,       SCREAMING_SNAKE_CASE :     Any=0.1				,       SCREAMING_SNAKE_CASE :     Optional[Any]=0.0				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=0.0				,       SCREAMING_SNAKE_CASE :     Any=0.02				,       SCREAMING_SNAKE_CASE :     List[Any]=0				,       SCREAMING_SNAKE_CASE :     Optional[Any]=False				,       SCREAMING_SNAKE_CASE :     Optional[int]=0				,       SCREAMING_SNAKE_CASE :     List[str]=1				,       SCREAMING_SNAKE_CASE :     Optional[Any]=1				,       **SCREAMING_SNAKE_CASE :     Optional[int]				,       ):
									lowercase__					:   List[Any]													=					vocab_size
									lowercase__					:   Union[str, Any]													=					max_position_embeddings
									lowercase__					:   List[Any]													=					d_model
									lowercase__					:   int													=					encoder_ffn_dim
									lowercase__					:   int													=					encoder_layers
									lowercase__					:   Optional[Any]													=					encoder_attention_heads
									lowercase__					:   str													=					decoder_ffn_dim
									lowercase__					:   str													=					decoder_layers
									lowercase__					:   List[Any]													=					decoder_attention_heads
									lowercase__					:   Optional[int]													=					dropout
									lowercase__					:   Union[str, Any]													=					attention_dropout
									lowercase__					:   Optional[int]													=					activation_dropout
									lowercase__					:   Union[str, Any]													=					activation_function
									lowercase__					:   List[str]													=					init_std
									lowercase__					:   Tuple													=					encoder_layerdrop
									lowercase__					:   int													=					decoder_layerdrop
									lowercase__					:   Any													=					use_cache
									lowercase__					:   int													=					encoder_layers
									lowercase__					:   Optional[int]													=					scale_embedding  # scale factor will be sqrt(d_model) if True
									super().__init__(
									    pad_token_id=SCREAMING_SNAKE_CASE				,       eos_token_id=SCREAMING_SNAKE_CASE				,       is_encoder_decoder=SCREAMING_SNAKE_CASE				,       decoder_start_token_id=SCREAMING_SNAKE_CASE				,       forced_eos_token_id=SCREAMING_SNAKE_CASE				,       **SCREAMING_SNAKE_CASE				,       )







					@property
					def 			snake_case					(							self :     Optional[Any]					):
									return self.encoder_attention_heads







					@property
					def 			snake_case					(							self :     Dict					):
									return self.d_model









import copy
import os
from typing import Union

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


lowerCAmelCase__					  =  logging.get_logger(__name__)

lowerCAmelCase__					  =  {
    '''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 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					lowercase_								=		"""bridgetower_vision_model"""







					def __init__(							self :     str				,       SCREAMING_SNAKE_CASE :     Dict=768				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=12				,       SCREAMING_SNAKE_CASE :     Dict=3				,       SCREAMING_SNAKE_CASE :     Dict=16				,       SCREAMING_SNAKE_CASE :     List[Any]=288				,       SCREAMING_SNAKE_CASE :     List[Any]=1				,       SCREAMING_SNAKE_CASE :     List[str]=1E-0_5				,       SCREAMING_SNAKE_CASE :     str=False				,       SCREAMING_SNAKE_CASE :     Any=True				,       SCREAMING_SNAKE_CASE :     Tuple=False				,       **SCREAMING_SNAKE_CASE :     List[str]				,       ):
									super().__init__(**SCREAMING_SNAKE_CASE					)
									lowercase__					:   Union[str, Any]													=					hidden_size
									lowercase__					:   str													=					num_hidden_layers
									lowercase__					:   str													=					num_channels
									lowercase__					:   Optional[int]													=					patch_size
									lowercase__					:   Dict													=					image_size
									lowercase__					:   List[Any]													=					initializer_factor
									lowercase__					:   int													=					layer_norm_eps
									lowercase__					:   List[str]													=					stop_gradient
									lowercase__					:   Optional[int]													=					share_layernorm
									lowercase__					:   Optional[int]													=					remove_last_layer







					@classmethod
					def 			snake_case					(							cls :     Tuple				,       SCREAMING_SNAKE_CASE :     Union[str, os.PathLike]				,       **SCREAMING_SNAKE_CASE :     str					):
									lowercase__							,							lowercase__					:   Optional[Any]													=					cls.get_config_dict(SCREAMING_SNAKE_CASE				,       **SCREAMING_SNAKE_CASE					)

									if config_dict.get("model_type"					) == "bridgetower":
													lowercase__					:   Optional[int]													=					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(SCREAMING_SNAKE_CASE				,       **SCREAMING_SNAKE_CASE					)






class 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					lowercase_								=		"""bridgetower_text_model"""







					def __init__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=50_265				,       SCREAMING_SNAKE_CASE :     Optional[int]=768				,       SCREAMING_SNAKE_CASE :     List[str]=12				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=12				,       SCREAMING_SNAKE_CASE :     List[Any]=1				,       SCREAMING_SNAKE_CASE :     Any=3_072				,       SCREAMING_SNAKE_CASE :     Union[str, Any]="gelu"				,       SCREAMING_SNAKE_CASE :     Optional[int]=0.1				,       SCREAMING_SNAKE_CASE :     List[str]=0.1				,       SCREAMING_SNAKE_CASE :     Tuple=514				,       SCREAMING_SNAKE_CASE :     List[str]=1				,       SCREAMING_SNAKE_CASE :     Dict=1E-0_5				,       SCREAMING_SNAKE_CASE :     List[str]=1				,       SCREAMING_SNAKE_CASE :     str=0				,       SCREAMING_SNAKE_CASE :     List[Any]=2				,       SCREAMING_SNAKE_CASE :     Optional[Any]="absolute"				,       SCREAMING_SNAKE_CASE :     int=True				,       **SCREAMING_SNAKE_CASE :     int				,       ):
									super().__init__(**SCREAMING_SNAKE_CASE					)

									lowercase__					:   Any													=					vocab_size
									lowercase__					:   Optional[Any]													=					hidden_size
									lowercase__					:   Optional[int]													=					num_hidden_layers
									lowercase__					:   Optional[int]													=					num_attention_heads
									lowercase__					:   int													=					hidden_act
									lowercase__					:   Optional[Any]													=					initializer_factor
									lowercase__					:   Dict													=					intermediate_size
									lowercase__					:   Tuple													=					hidden_dropout_prob
									lowercase__					:   List[Any]													=					attention_probs_dropout_prob
									lowercase__					:   Optional[int]													=					max_position_embeddings
									lowercase__					:   str													=					type_vocab_size
									lowercase__					:   str													=					layer_norm_eps
									lowercase__					:   Dict													=					position_embedding_type
									lowercase__					:   Optional[Any]													=					use_cache
									lowercase__					:   List[str]													=					pad_token_id
									lowercase__					:   Optional[Any]													=					bos_token_id
									lowercase__					:   Optional[Any]													=					eos_token_id







					@classmethod
					def 			snake_case					(							cls :     Optional[int]				,       SCREAMING_SNAKE_CASE :     Union[str, os.PathLike]				,       **SCREAMING_SNAKE_CASE :     str					):
									lowercase__							,							lowercase__					:   Optional[Any]													=					cls.get_config_dict(SCREAMING_SNAKE_CASE				,       **SCREAMING_SNAKE_CASE					)

									if config_dict.get("model_type"					) == "bridgetower":
													lowercase__					:   List[Any]													=					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(SCREAMING_SNAKE_CASE				,       **SCREAMING_SNAKE_CASE					)






class 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					lowercase_								=		"""bridgetower"""







					def __init__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Optional[int]=True				,       SCREAMING_SNAKE_CASE :     Dict="gelu"				,       SCREAMING_SNAKE_CASE :     Any=768				,       SCREAMING_SNAKE_CASE :     Dict=1				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=1E-0_5				,       SCREAMING_SNAKE_CASE :     Tuple=False				,       SCREAMING_SNAKE_CASE :     List[Any]="add"				,       SCREAMING_SNAKE_CASE :     Any=12				,       SCREAMING_SNAKE_CASE :     Any=6				,       SCREAMING_SNAKE_CASE :     Any=False				,       SCREAMING_SNAKE_CASE :     List[Any]=False				,       SCREAMING_SNAKE_CASE :     str=None				,       SCREAMING_SNAKE_CASE :     Dict=None				,       **SCREAMING_SNAKE_CASE :     List[Any]				,       ):
									# TODO: remove this once the Hub files are updated.
									lowercase__					:   int													=					kwargs.pop("text_config_dict"				,       SCREAMING_SNAKE_CASE					)
									lowercase__					:   int													=					kwargs.pop("vision_config_dict"				,       SCREAMING_SNAKE_CASE					)

									super().__init__(**SCREAMING_SNAKE_CASE					)
									lowercase__					:   Dict													=					share_cross_modal_transformer_layers
									lowercase__					:   int													=					hidden_act
									lowercase__					:   int													=					hidden_size
									lowercase__					:   Optional[int]													=					initializer_factor
									lowercase__					:   Optional[int]													=					layer_norm_eps
									lowercase__					:   str													=					share_link_tower_layers
									lowercase__					:   Optional[int]													=					link_tower_type
									lowercase__					:   List[Any]													=					num_attention_heads
									lowercase__					:   Dict													=					num_hidden_layers
									lowercase__					:   Dict													=					tie_word_embeddings
									lowercase__					:   Optional[Any]													=					init_layernorm_from_vision_encoder

									if text_config is None:
													lowercase__					:   Optional[Any]													=					{}
													logger.info("`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values."					)

									if vision_config is None:
													lowercase__					:   List[Any]													=					{}
													logger.info("`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values."					)

									lowercase__					:   Any													=					BridgeTowerTextConfig(**SCREAMING_SNAKE_CASE					)
									lowercase__					:   Dict													=					BridgeTowerVisionConfig(**SCREAMING_SNAKE_CASE					)







					@classmethod
					def 			snake_case					(							cls :     Optional[int]				,       SCREAMING_SNAKE_CASE :     BridgeTowerTextConfig				,       SCREAMING_SNAKE_CASE :     BridgeTowerVisionConfig				,       **SCREAMING_SNAKE_CASE :     List[str]					):
									return cls(text_config=text_config.to_dict()				,       vision_config=vision_config.to_dict()				,       **SCREAMING_SNAKE_CASE					)







					def 			snake_case					(							self :     Optional[int]					):
									lowercase__					:   List[str]													=					copy.deepcopy(self.__dict__					)
									lowercase__					:   Dict													=					self.text_config.to_dict()
									lowercase__					:   Tuple													=					self.vision_config.to_dict()
									lowercase__					:   Optional[Any]													=					self.__class__.model_type
									return output




