


'''simple docstring'''





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 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"bridgetower_vision_model"


 def __init__(      self							:	Union[str, Any]			,       __lowerCamelCase							:	List[str]=7_6_8			,       __lowerCamelCase							:	Any=1_2			,       __lowerCamelCase							:	Any=3			,       __lowerCamelCase							:	Tuple=1_6			,       __lowerCamelCase							:	List[str]=2_8_8			,       __lowerCamelCase							:	int=1			,       __lowerCamelCase							:	Optional[Any]=1e-05			,       __lowerCamelCase							:	List[str]=False			,       __lowerCamelCase							:	Tuple=True			,       __lowerCamelCase							:	Optional[Any]=False			,       **__lowerCamelCase							:	Union[str, Any]			,       ):
    super().__init__(**__lowerCamelCase )
    UpperCAmelCase__	:Any      =      hidden_size
    UpperCAmelCase__	:Union[str, Any]      =      num_hidden_layers
    UpperCAmelCase__	:Optional[int]      =      num_channels
    UpperCAmelCase__	:List[str]      =      patch_size
    UpperCAmelCase__	:Union[str, Any]      =      image_size
    UpperCAmelCase__	:Optional[int]      =      initializer_factor
    UpperCAmelCase__	:str      =      layer_norm_eps
    UpperCAmelCase__	:str      =      stop_gradient
    UpperCAmelCase__	:Optional[Any]      =      share_layernorm
    UpperCAmelCase__	:str      =      remove_last_layer





 @classmethod
 def        __SCREAMING_SNAKE_CASE					(      cls							:	str			,       __lowerCamelCase							:	Union[str, os.PathLike]			,       **__lowerCamelCase							:	Any ):
    UpperCAmelCase__   ,						UpperCAmelCase__	:Dict      =      cls.get_config_dict(__lowerCamelCase			,       **__lowerCamelCase )

    if config_dict.get('''model_type''' ) == "bridgetower":
       UpperCAmelCase__	:str      =      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(__lowerCamelCase			,       **__lowerCamelCase )




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"bridgetower_text_model"


 def __init__(      self							:	Optional[Any]			,       __lowerCamelCase							:	Optional[Any]=5_0_2_6_5			,       __lowerCamelCase							:	Optional[Any]=7_6_8			,       __lowerCamelCase							:	Optional[Any]=1_2			,       __lowerCamelCase							:	Union[str, Any]=1_2			,       __lowerCamelCase							:	Optional[Any]=1			,       __lowerCamelCase							:	List[Any]=3_0_7_2			,       __lowerCamelCase							:	int="gelu"			,       __lowerCamelCase							:	List[str]=0.1			,       __lowerCamelCase							:	Optional[Any]=0.1			,       __lowerCamelCase							:	Union[str, Any]=5_1_4			,       __lowerCamelCase							:	Tuple=1			,       __lowerCamelCase							:	Dict=1e-05			,       __lowerCamelCase							:	int=1			,       __lowerCamelCase							:	str=0			,       __lowerCamelCase							:	List[Any]=2			,       __lowerCamelCase							:	Union[str, Any]="absolute"			,       __lowerCamelCase							:	Optional[Any]=True			,       **__lowerCamelCase							:	Dict			,       ):
    super().__init__(**__lowerCamelCase )

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





 @classmethod
 def        __SCREAMING_SNAKE_CASE					(      cls							:	int			,       __lowerCamelCase							:	Union[str, os.PathLike]			,       **__lowerCamelCase							:	Optional[Any] ):
    UpperCAmelCase__   ,						UpperCAmelCase__	:Optional[Any]      =      cls.get_config_dict(__lowerCamelCase			,       **__lowerCamelCase )

    if config_dict.get('''model_type''' ) == "bridgetower":
       UpperCAmelCase__	: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(__lowerCamelCase			,       **__lowerCamelCase )




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"bridgetower"


 def __init__(      self							:	Union[str, Any]			,       __lowerCamelCase							:	Union[str, Any]=True			,       __lowerCamelCase							:	Dict="gelu"			,       __lowerCamelCase							:	Dict=7_6_8			,       __lowerCamelCase							:	List[str]=1			,       __lowerCamelCase							:	List[str]=1e-05			,       __lowerCamelCase							:	Optional[int]=False			,       __lowerCamelCase							:	Dict="add"			,       __lowerCamelCase							:	List[str]=1_2			,       __lowerCamelCase							:	Optional[Any]=6			,       __lowerCamelCase							:	Tuple=False			,       __lowerCamelCase							:	Union[str, Any]=False			,       __lowerCamelCase							:	List[str]=None			,       __lowerCamelCase							:	Tuple=None			,       **__lowerCamelCase							:	Any			,       ):
    # TODO: remove this once the Hub files are updated.
    UpperCAmelCase__	:int      =      kwargs.pop('''text_config_dict'''			,       __lowerCamelCase )
    UpperCAmelCase__	:Optional[int]      =      kwargs.pop('''vision_config_dict'''			,       __lowerCamelCase )

    super().__init__(**__lowerCamelCase )
    UpperCAmelCase__	:Dict      =      share_cross_modal_transformer_layers
    UpperCAmelCase__	:Dict      =      hidden_act
    UpperCAmelCase__	:List[Any]      =      hidden_size
    UpperCAmelCase__	:Union[str, Any]      =      initializer_factor
    UpperCAmelCase__	:int      =      layer_norm_eps
    UpperCAmelCase__	:List[str]      =      share_link_tower_layers
    UpperCAmelCase__	:Union[str, Any]      =      link_tower_type
    UpperCAmelCase__	:Any      =      num_attention_heads
    UpperCAmelCase__	:Union[str, Any]      =      num_hidden_layers
    UpperCAmelCase__	:str      =      tie_word_embeddings
    UpperCAmelCase__	:Dict      =      init_layernorm_from_vision_encoder

    if text_config is None:
       UpperCAmelCase__	:Union[str, Any]      =      {}
       logger.info('''`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.''' )

    if vision_config is None:
       UpperCAmelCase__	:List[str]      =      {}
       logger.info('''`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values.''' )

    UpperCAmelCase__	:int      =      BridgeTowerTextConfig(**__lowerCamelCase )
    UpperCAmelCase__	:Optional[int]      =      BridgeTowerVisionConfig(**__lowerCamelCase )


 @classmethod
 def        __SCREAMING_SNAKE_CASE					(      cls							:	int			,       __lowerCamelCase							:	BridgeTowerTextConfig			,       __lowerCamelCase							:	BridgeTowerVisionConfig			,       **__lowerCamelCase							:	Dict ):
    return cls(text_config=text_config.to_dict()			,       vision_config=vision_config.to_dict()			,       **__lowerCamelCase )





 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:str      =      copy.deepcopy(self.__dict__ )
    UpperCAmelCase__	:List[str]      =      self.text_config.to_dict()
    UpperCAmelCase__	:Dict      =      self.vision_config.to_dict()
    UpperCAmelCase__	:str      =      self.__class__.model_type
    return output







'''simple docstring'''





import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__lowerCamelCase												=						logging.get_logger(__name__)

__lowerCamelCase												=						{
    '''nvidia/segformer-b0-finetuned-ade-512-512''': (
        '''https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'''
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"segformer"


 def __init__(      self							:	Dict			,       __lowerCamelCase							:	Dict=3			,       __lowerCamelCase							:	List[str]=4			,       __lowerCamelCase							:	List[Any]=[2, 2, 2, 2]			,       __lowerCamelCase							:	List[str]=[8, 4, 2, 1]			,       __lowerCamelCase							:	Optional[Any]=[3_2, 6_4, 1_6_0, 2_5_6]			,       __lowerCamelCase							:	Tuple=[7, 3, 3, 3]			,       __lowerCamelCase							:	Tuple=[4, 2, 2, 2]			,       __lowerCamelCase							:	Any=[1, 2, 5, 8]			,       __lowerCamelCase							:	Optional[Any]=[4, 4, 4, 4]			,       __lowerCamelCase							:	Union[str, Any]="gelu"			,       __lowerCamelCase							:	Dict=0.0			,       __lowerCamelCase							:	Union[str, Any]=0.0			,       __lowerCamelCase							:	Tuple=0.1			,       __lowerCamelCase							:	Optional[Any]=0.02			,       __lowerCamelCase							:	Optional[int]=0.1			,       __lowerCamelCase							:	str=1e-6			,       __lowerCamelCase							:	List[Any]=2_5_6			,       __lowerCamelCase							:	int=2_5_5			,       **__lowerCamelCase							:	str			,       ):
    super().__init__(**__lowerCamelCase )

    if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
       warnings.warn(
           '''Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be'''
           ''' removed, as the behaviour will default to that of reshape_last_stage = True.'''			,       __lowerCamelCase			,       )

    UpperCAmelCase__	:Dict      =      num_channels
    UpperCAmelCase__	:List[Any]      =      num_encoder_blocks
    UpperCAmelCase__	:List[str]      =      depths
    UpperCAmelCase__	:str      =      sr_ratios
    UpperCAmelCase__	:Optional[Any]      =      hidden_sizes
    UpperCAmelCase__	:List[str]      =      patch_sizes
    UpperCAmelCase__	:List[str]      =      strides
    UpperCAmelCase__	:List[str]      =      mlp_ratios
    UpperCAmelCase__	:Dict      =      num_attention_heads
    UpperCAmelCase__	:Tuple      =      hidden_act
    UpperCAmelCase__	:List[str]      =      hidden_dropout_prob
    UpperCAmelCase__	:List[Any]      =      attention_probs_dropout_prob
    UpperCAmelCase__	:int      =      classifier_dropout_prob
    UpperCAmelCase__	:str      =      initializer_range
    UpperCAmelCase__	:List[str]      =      drop_path_rate
    UpperCAmelCase__	:Dict      =      layer_norm_eps
    UpperCAmelCase__	:List[str]      =      decoder_hidden_size
    UpperCAmelCase__	:Optional[int]      =      kwargs.get('''reshape_last_stage'''			,       __lowerCamelCase )
    UpperCAmelCase__	:str      =      semantic_loss_ignore_index




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					version.parse("1.11"						)


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any] ):
    return OrderedDict(
        [
            ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
        ] )


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[int] ):
    return 1e-4





 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    return 1_2



