





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							(		_lowerCamelCase     ):
      a						       =							'''bridgetower_vision_model'''
      def __init__(		self      ,       a__=768      ,       a__=12      ,       a__=3      ,       a__=16      ,       a__=288      ,       a__=1      ,       a__=1E-05      ,       a__=False      ,       a__=True      ,       a__=False      ,       **a__      ,       ):
         super().__init__(**a__       )
         A_     :				Optional[int]			      =	hidden_size
         A_     :				Union[str, Any]			      =	num_hidden_layers
         A_     :				Union[str, Any]			      =	num_channels
         A_     :				str			      =	patch_size
         A_     :				Optional[int]			      =	image_size
         A_     :				Optional[int]			      =	initializer_factor
         A_     :				Optional[int]			      =	layer_norm_eps
         A_     :				Tuple			      =	stop_gradient
         A_     :				List[str]			      =	share_layernorm
         A_     :				List[Any]			      =	remove_last_layer






      @classmethod
      def 		_lowerCamelCase      (		cls      ,       a__      ,       **a__       ):
         A_      ,				A_     :				List[str]			      =	cls.get_config_dict(a__      ,       **a__       )

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






class    _UpperCAmelCase							(		_lowerCamelCase     ):
      a						       =							'''bridgetower_text_model'''
      def __init__(		self      ,       a__=50265      ,       a__=768      ,       a__=12      ,       a__=12      ,       a__=1      ,       a__=3072      ,       a__="gelu"      ,       a__=0.1      ,       a__=0.1      ,       a__=514      ,       a__=1      ,       a__=1E-05      ,       a__=1      ,       a__=0      ,       a__=2      ,       a__="absolute"      ,       a__=True      ,       **a__      ,       ):
         super().__init__(**a__       )

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






      @classmethod
      def 		_lowerCamelCase      (		cls      ,       a__      ,       **a__       ):
         A_      ,				A_     :				Any			      =	cls.get_config_dict(a__      ,       **a__       )

         if config_dict.get("""model_type"""       ) == "bridgetower":
            A_     :				Optional[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(a__      ,       **a__       )






class    _UpperCAmelCase							(		_lowerCamelCase     ):
      a						       =							'''bridgetower'''
      def __init__(		self      ,       a__=True      ,       a__="gelu"      ,       a__=768      ,       a__=1      ,       a__=1E-05      ,       a__=False      ,       a__="add"      ,       a__=12      ,       a__=6      ,       a__=False      ,       a__=False      ,       a__=None      ,       a__=None      ,       **a__      ,       ):
         # TODO: remove this once the Hub files are updated.
         A_     :				Dict			      =	kwargs.pop("""text_config_dict"""      ,       a__       )
         A_     :				Dict			      =	kwargs.pop("""vision_config_dict"""      ,       a__       )

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

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

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

         A_     :				int			      =	BridgeTowerTextConfig(**a__       )
         A_     :				Dict			      =	BridgeTowerVisionConfig(**a__       )
      @classmethod
      def 		_lowerCamelCase      (		cls      ,       a__      ,       a__      ,       **a__       ):
         return cls(text_config=text_config.to_dict()      ,       vision_config=vision_config.to_dict()      ,       **a__       )






      def 		_lowerCamelCase      (		self       ):
         A_     :				int			      =	copy.deepcopy(self.__dict__       )
         A_     :				Tuple			      =	self.text_config.to_dict()
         A_     :				int			      =	self.vision_config.to_dict()
         A_     :				Optional[Any]			      =	self.__class__.model_type
         return output













from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCAmelCase 				=     {
    """configuration_nllb_moe""": [
        """NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """NllbMoeConfig""",
    ]
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _lowerCAmelCase 				=     [
          """NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """NllbMoeForConditionalGeneration""",
          """NllbMoeModel""",
          """NllbMoePreTrainedModel""",
          """NllbMoeTop2Router""",
          """NllbMoeSparseMLP""",
      ]


if TYPE_CHECKING:
      from .configuration_nllb_moe import (
          NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP,
          NllbMoeConfig,
      )

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_nllb_moe import (
                NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST,
                NllbMoeForConditionalGeneration,
                NllbMoeModel,
                NllbMoePreTrainedModel,
                NllbMoeSparseMLP,
                NllbMoeTopaRouter,
            )


else:
      import sys

      _lowerCAmelCase 				=     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






