





"""simple docstring"""




import copy
import os
from typing import Union

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


lowerCamelCase_     :						str						=					logging.get_logger(__name__)

lowerCamelCase_     :						Any						=					{
    '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  (   UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_      : Optional[int]	    =   """bridgetower_vision_model"""

      def __init__(     self					,      snake_case_=7_6_8					,      snake_case_=1_2					,      snake_case_=3					,      snake_case_=1_6					,      snake_case_=2_8_8					,      snake_case_=1					,      snake_case_=1E-05					,      snake_case_=False					,      snake_case_=True					,      snake_case_=False					,      **snake_case_					,      ):

        """simple docstring"""

        super().__init__(**snake_case_  )
        A_  :       Optional[Any]										=  hidden_size
        A_  :       Any										=  num_hidden_layers
        A_  :       Dict										=  num_channels
        A_  :       str										=  patch_size
        A_  :       List[str]										=  image_size
        A_  :       List[str]										=  initializer_factor
        A_  :       Dict										=  layer_norm_eps
        A_  :       Dict										=  stop_gradient
        A_  :       Any										=  share_layernorm
        A_  :       Optional[int]										=  remove_last_layer

      @classmethod
      def 					lowerCamelCase_			(     cls					,      snake_case_					,      **snake_case_  ):

        """simple docstring"""

        A_						,       A_  :       Dict										=  cls.get_config_dict(snake_case_					,      **snake_case_  )

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


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_      : Optional[Any]	    =   """bridgetower_text_model"""

      def __init__(     self					,      snake_case_=5_0_2_6_5					,      snake_case_=7_6_8					,      snake_case_=1_2					,      snake_case_=1_2					,      snake_case_=1					,      snake_case_=3_0_7_2					,      snake_case_="gelu"					,      snake_case_=0.1					,      snake_case_=0.1					,      snake_case_=5_1_4					,      snake_case_=1					,      snake_case_=1E-05					,      snake_case_=1					,      snake_case_=0					,      snake_case_=2					,      snake_case_="absolute"					,      snake_case_=True					,      **snake_case_					,      ):

        """simple docstring"""

        super().__init__(**snake_case_  )

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

      @classmethod
      def 					lowerCamelCase_			(     cls					,      snake_case_					,      **snake_case_  ):

        """simple docstring"""

        A_						,       A_  :       List[Any]										=  cls.get_config_dict(snake_case_					,      **snake_case_  )

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


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_      : int	    =   """bridgetower"""

      def __init__(     self					,      snake_case_=True					,      snake_case_="gelu"					,      snake_case_=7_6_8					,      snake_case_=1					,      snake_case_=1E-05					,      snake_case_=False					,      snake_case_="add"					,      snake_case_=1_2					,      snake_case_=6					,      snake_case_=False					,      snake_case_=False					,      snake_case_=None					,      snake_case_=None					,      **snake_case_					,      ):

        """simple docstring"""

        A_  :       List[Any]										=  kwargs.pop('text_config_dict'					,      snake_case_  )
        A_  :       Any										=  kwargs.pop('vision_config_dict'					,      snake_case_  )

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

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

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

        A_  :       str										=  BridgeTowerTextConfig(**snake_case_  )
        A_  :       str										=  BridgeTowerVisionConfig(**snake_case_  )

      @classmethod
      def 					lowerCamelCase_			(     cls					,      snake_case_					,      snake_case_					,      **snake_case_  ):

        """simple docstring"""

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

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       List[str]										=  copy.deepcopy(self.__dict__  )
        A_  :       Optional[int]										=  self.text_config.to_dict()
        A_  :       str										=  self.vision_config.to_dict()
        A_  :       Optional[int]										=  self.__class__.model_type
        return output






"""simple docstring"""




import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType

class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_      : Dict	    =   ["""image_processor""", """tokenizer"""]
      lowercase_      : Union[str, Any]	    =   """ViltImageProcessor"""
      lowercase_      : Any	    =   ("""BertTokenizer""", """BertTokenizerFast""")

      def __init__(     self					,      snake_case_=None					,      snake_case_=None					,      **snake_case_  ):

        """simple docstring"""

        A_  :       Union[str, Any]										=  None
        if "feature_extractor" in kwargs:
          warnings.warn(
              'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
              ' instead.'					,      snake_case_					,      )
          A_  :       Dict										=  kwargs.pop('feature_extractor'  )

        A_  :       Dict										=  image_processor if image_processor is not None else feature_extractor
        if image_processor is None:
          raise ValueError('You need to specify an `image_processor`.'  )
        if tokenizer is None:
          raise ValueError('You need to specify a `tokenizer`.'  )

        super().__init__(snake_case_					,      snake_case_  )
        A_  :       List[str]										=  self.image_processor

      def __call__(     self					,      snake_case_					,      snake_case_ = None					,      snake_case_ = True					,      snake_case_ = False					,      snake_case_ = None					,      snake_case_ = None					,      snake_case_ = 0					,      snake_case_ = None					,      snake_case_ = None					,      snake_case_ = None					,      snake_case_ = False					,      snake_case_ = False					,      snake_case_ = False					,      snake_case_ = False					,      snake_case_ = True					,      snake_case_ = None					,      **snake_case_					,      ):

        """simple docstring"""

        A_  :       str										=  self.tokenizer(
            text=snake_case_					,      add_special_tokens=snake_case_					,      padding=snake_case_					,      truncation=snake_case_					,      max_length=snake_case_					,      stride=snake_case_					,      pad_to_multiple_of=snake_case_					,      return_token_type_ids=snake_case_					,      return_attention_mask=snake_case_					,      return_overflowing_tokens=snake_case_					,      return_special_tokens_mask=snake_case_					,      return_offsets_mapping=snake_case_					,      return_length=snake_case_					,      verbose=snake_case_					,      return_tensors=snake_case_					,      **snake_case_					,      )
        # add pixel_values + pixel_mask
        A_  :       Optional[int]										=  self.image_processor(snake_case_					,      return_tensors=snake_case_  )
        encoding.update(snake_case_  )

        return encoding

      def 					lowerCamelCase_			(     self					,      *snake_case_					,      **snake_case_  ):

        """simple docstring"""

        return self.tokenizer.batch_decode(*snake_case_					,      **snake_case_  )

      def 					lowerCamelCase_			(     self					,      *snake_case_					,      **snake_case_  ):

        """simple docstring"""

        return self.tokenizer.decode(*snake_case_					,      **snake_case_  )

      @property
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       Any										=  self.tokenizer.model_input_names
        A_  :       Any										=  self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names  )  )

      @property
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        warnings.warn(
            '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'					,      snake_case_					,      )
        return self.image_processor_class

      @property
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        warnings.warn(
            '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'					,      snake_case_					,      )
        return self.image_processor