






import copy
import os
from typing import Union

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


A_		:     List[str]        =     logging.get_logger(__name__)

A_		:     Dict        =     {
    '''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 		_lowercase		(       __lowerCamelCase	):
   _UpperCAmelCase     	=			'''bridgetower_vision_model'''

   def __init__(      self			:       Tuple							,   __lowerCAmelCase			:       List[Any]=768							,   __lowerCAmelCase			:       List[str]=12							,   __lowerCAmelCase			:       Optional[int]=3							,   __lowerCAmelCase			:       Optional[Any]=16							,   __lowerCAmelCase			:       Tuple=288							,   __lowerCAmelCase			:       Any=1							,   __lowerCAmelCase			:       str=1E-05							,   __lowerCAmelCase			:       List[Any]=False							,   __lowerCAmelCase			:       Dict=True							,   __lowerCAmelCase			:       int=False							,   **__lowerCAmelCase			:       Any							,   )       ->				Optional[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 		A							(      cls			:       List[Any]							,   __lowerCAmelCase			:       List[Any]							,   **__lowerCAmelCase			:       Union[str, Any]							)       ->				List[str]:


    """simple docstring"""






    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 		_lowercase		(       __lowerCamelCase	):
   _UpperCAmelCase     	=			'''bridgetower_text_model'''

   def __init__(      self			:       Any							,   __lowerCAmelCase			:       Any=5_0265							,   __lowerCAmelCase			:       int=768							,   __lowerCAmelCase			:       int=12							,   __lowerCAmelCase			:       Optional[Any]=12							,   __lowerCAmelCase			:       List[str]=1							,   __lowerCAmelCase			:       Tuple=3072							,   __lowerCAmelCase			:       Dict="gelu"							,   __lowerCAmelCase			:       Dict=0.1							,   __lowerCAmelCase			:       Dict=0.1							,   __lowerCAmelCase			:       Union[str, Any]=514							,   __lowerCAmelCase			:       Union[str, Any]=1							,   __lowerCAmelCase			:       str=1E-05							,   __lowerCAmelCase			:       Optional[Any]=1							,   __lowerCAmelCase			:       Any=0							,   __lowerCAmelCase			:       Optional[int]=2							,   __lowerCAmelCase			:       Optional[int]="absolute"							,   __lowerCAmelCase			:       Tuple=True							,   **__lowerCAmelCase			:       List[Any]							,   )       ->				Union[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 		A							(      cls			:       int							,   __lowerCAmelCase			:       Optional[int]							,   **__lowerCAmelCase			:       List[str]							)       ->				Union[str, Any]:


    """simple docstring"""






    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 		_lowercase		(       __lowerCamelCase	):
   _UpperCAmelCase     	=			'''bridgetower'''

   def __init__(      self			:       Dict							,   __lowerCAmelCase			:       Union[str, Any]=True							,   __lowerCAmelCase			:       Dict="gelu"							,   __lowerCAmelCase			:       Optional[Any]=768							,   __lowerCAmelCase			:       Any=1							,   __lowerCAmelCase			:       int=1E-05							,   __lowerCAmelCase			:       List[str]=False							,   __lowerCAmelCase			:       Tuple="add"							,   __lowerCAmelCase			:       int=12							,   __lowerCAmelCase			:       Dict=6							,   __lowerCAmelCase			:       int=False							,   __lowerCAmelCase			:       List[str]=False							,   __lowerCAmelCase			:       List[str]=None							,   __lowerCAmelCase			:       Dict=None							,   **__lowerCAmelCase			:       List[str]							,   )       ->				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 		A							(      cls			:       List[str]							,   __lowerCAmelCase			:       Union[str, Any]							,   __lowerCAmelCase			:       Union[str, Any]							,   **__lowerCAmelCase			:       Optional[int]							)       ->				str:


    """simple docstring"""






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




   def 		A							(      self			:       List[str]							)       ->				List[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






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_		:     int        =     logging.get_logger(__name__)

A_		:     str        =     {
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}



class 		_lowercase		(       UpperCAmelCase__,   UpperCAmelCase__	):
   _UpperCAmelCase     	=			'''focalnet'''

   def __init__(      self			:       int							,   __lowerCAmelCase			:       Optional[Any]=224							,   __lowerCAmelCase			:       Any=4							,   __lowerCAmelCase			:       Any=3							,   __lowerCAmelCase			:       Tuple=96							,   __lowerCAmelCase			:       Dict=False							,   __lowerCAmelCase			:       Optional[int]=[192, 384, 768, 768]							,   __lowerCAmelCase			:       Union[str, Any]=[2, 2, 6, 2]							,   __lowerCAmelCase			:       Optional[int]=[2, 2, 2, 2]							,   __lowerCAmelCase			:       Union[str, Any]=[3, 3, 3, 3]							,   __lowerCAmelCase			:       str="gelu"							,   __lowerCAmelCase			:       Any=4.0							,   __lowerCAmelCase			:       Optional[int]=0.0							,   __lowerCAmelCase			:       Tuple=0.1							,   __lowerCAmelCase			:       str=False							,   __lowerCAmelCase			:       Optional[int]=1E-4							,   __lowerCAmelCase			:       Optional[Any]=False							,   __lowerCAmelCase			:       Union[str, Any]=False							,   __lowerCAmelCase			:       str=False							,   __lowerCAmelCase			:       Any=0.0_2							,   __lowerCAmelCase			:       str=1E-5							,   __lowerCAmelCase			:       Optional[Any]=32							,   __lowerCAmelCase			:       Dict=None							,   __lowerCAmelCase			:       str=None							,   **__lowerCAmelCase			:       Any							,   )       ->				List[str]:


    """simple docstring"""






    super().__init__(**__lowerCAmelCase							)

    a						=		image_size
    a						=		patch_size
    a						=		num_channels
    a						=		embed_dim
    a						=		use_conv_embed
    a						=		hidden_sizes
    a						=		depths
    a						=		focal_levels
    a						=		focal_windows
    a						=		hidden_act
    a						=		mlp_ratio
    a						=		hidden_dropout_prob
    a						=		drop_path_rate
    a						=		use_layerscale
    a						=		layerscale_value
    a						=		use_post_layernorm
    a						=		use_post_layernorm_in_modulation
    a						=		normalize_modulator
    a						=		initializer_range
    a						=		layer_norm_eps
    a						=		encoder_stride
    a						=		["stem"] + [f"""stage{idx}""" for idx in range(1							,   len(self.depths							) + 1							)]
    a		,  a						=		get_aligned_output_features_output_indices(
        out_features=__lowerCAmelCase							,   out_indices=__lowerCAmelCase							,   stage_names=self.stage_names							)

