



"""simple docstring"""




from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available, is_vision_available
from ...utils import OptionalDependencyNotAvailable


_lowerCAmelCase    : int							=							{"configuration_dpt": ["DPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "DPTConfig"]}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase    : Optional[Any]							=							["DPTFeatureExtractor"]
 _lowerCAmelCase    : Any							=							["DPTImageProcessor"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase    : Optional[int]							=							[
     "DPT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "DPTForDepthEstimation",
     "DPTForSemanticSegmentation",
     "DPTModel",
     "DPTPreTrainedModel",
 ]


if TYPE_CHECKING:
 from .configuration_dpt import DPT_PRETRAINED_CONFIG_ARCHIVE_MAP, DPTConfig

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_dpt import DPTFeatureExtractor
  from .image_processing_dpt import DPTImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_dpt import (
      DPT_PRETRAINED_MODEL_ARCHIVE_LIST,
      DPTForDepthEstimation,
      DPTForSemanticSegmentation,
      DPTModel,
      DPTPreTrainedModel,
  )


else:
 import sys

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





"""simple docstring"""




import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
 from ...processing_utils import ProcessorMixin
 from ...utils import TensorType

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


_lowerCAmelCase    : Dict							=							logging.get_logger(__name__)

_lowerCAmelCase    : List[str]							=							{
    "google/owlvit-base-patch32": "https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json",
    "google/owlvit-base-patch16": "https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json",
    "google/owlvit-large-patch14": "https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json",
}






class      UpperCAmelCase_  (    _UpperCamelCase						):
      __SCREAMING_SNAKE_CASE						:       int								=			'owlvit_text_model'



      def __init__(					self					:     int					,     A					:     int=4_9_4_0_8					,     A					:     Optional[Any]=5_1_2					,     A					:     Optional[Any]=2_0_4_8					,     A					:     str=1_2					,     A					:     int=8					,     A					:     Tuple=1_6					,     A					:     List[Any]="quick_gelu"					,     A					:     Tuple=1e-5					,     A					:     Union[str, Any]=0.0					,     A					:     List[Any]=0.02					,     A					:     str=1.0					,     A					:     str=0					,     A					:     List[str]=4_9_4_0_6					,     A					:     str=4_9_4_0_7					,     **A					:     Optional[Any]					,     ):
           super().__init__(pad_token_id=A					,     bos_token_id=A					,     eos_token_id=A					,     **A						)

           _UpperCAmelCase      :     Union[str, Any]        =   vocab_size
           _UpperCAmelCase      :     str        =   hidden_size
           _UpperCAmelCase      :     List[Any]        =   intermediate_size
           _UpperCAmelCase      :     Any        =   num_hidden_layers
           _UpperCAmelCase      :     str        =   num_attention_heads
           _UpperCAmelCase      :     List[str]        =   max_position_embeddings
           _UpperCAmelCase      :     List[Any]        =   hidden_act
           _UpperCAmelCase      :     Tuple        =   layer_norm_eps
           _UpperCAmelCase      :     List[str]        =   attention_dropout
           _UpperCAmelCase      :     Optional[Any]        =   initializer_range
           _UpperCAmelCase      :     List[Any]        =   initializer_factor



      @classmethod
      def 						snake_case_ (					cls					:     Any					,     A					:     Union[str, os.PathLike]					,     **A					:     Dict						):
           cls._set_token_in_kwargs(A						)

           _UpperCAmelCase    ,	_UpperCAmelCase      :     List[str]        =   cls.get_config_dict(A					,     **A						)

           # get the text config dict if we are loading from OwlViTConfig
           if config_dict.get("model_type"						) == "owlvit":
                _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(A					,     **A						)







class      UpperCAmelCase_  (    _UpperCamelCase						):
      __SCREAMING_SNAKE_CASE						:       Tuple								=			'owlvit_vision_model'



      def __init__(					self					:     Union[str, Any]					,     A					:     Optional[int]=7_6_8					,     A					:     int=3_0_7_2					,     A					:     List[str]=1_2					,     A					:     List[str]=1_2					,     A					:     Optional[int]=3					,     A					:     Optional[int]=7_6_8					,     A					:     str=3_2					,     A					:     Tuple="quick_gelu"					,     A					:     Dict=1e-5					,     A					:     Optional[int]=0.0					,     A					:     List[Any]=0.02					,     A					:     str=1.0					,     **A					:     Tuple					,     ):
           super().__init__(**A						)

           _UpperCAmelCase      :     List[str]        =   hidden_size
           _UpperCAmelCase      :     Tuple        =   intermediate_size
           _UpperCAmelCase      :     Optional[Any]        =   num_hidden_layers
           _UpperCAmelCase      :     Dict        =   num_attention_heads
           _UpperCAmelCase      :     Optional[Any]        =   num_channels
           _UpperCAmelCase      :     Union[str, Any]        =   image_size
           _UpperCAmelCase      :     Dict        =   patch_size
           _UpperCAmelCase      :     List[str]        =   hidden_act
           _UpperCAmelCase      :     Union[str, Any]        =   layer_norm_eps
           _UpperCAmelCase      :     Any        =   attention_dropout
           _UpperCAmelCase      :     Tuple        =   initializer_range
           _UpperCAmelCase      :     Tuple        =   initializer_factor



      @classmethod
      def 						snake_case_ (					cls					:     Optional[int]					,     A					:     Union[str, os.PathLike]					,     **A					:     int						):
           cls._set_token_in_kwargs(A						)

           _UpperCAmelCase    ,	_UpperCAmelCase      :     Dict        =   cls.get_config_dict(A					,     **A						)

           # get the vision config dict if we are loading from OwlViTConfig
           if config_dict.get("model_type"						) == "owlvit":
                _UpperCAmelCase      :     Tuple        =   config_dict["vision_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_  (    _UpperCamelCase						):
      __SCREAMING_SNAKE_CASE						:       List[str]								=			'owlvit'
      __SCREAMING_SNAKE_CASE						:       Optional[Any]								=			True



      def __init__(					self					:     Optional[Any]					,     A					:     Dict=None					,     A					:     Tuple=None					,     A					:     Optional[Any]=5_1_2					,     A					:     Optional[Any]=2.6_592					,     A					:     int=True					,     **A					:     Tuple					,     ):
           super().__init__(**A						)

           if text_config is None:
                _UpperCAmelCase      :     List[Any]        =   {}
                logger.info("text_config is None. Initializing the OwlViTTextConfig with default values."						)

           if vision_config is None:
                _UpperCAmelCase      :     Tuple        =   {}
                logger.info("vision_config is None. initializing the OwlViTVisionConfig with default values."						)

           _UpperCAmelCase      :     str        =   OwlViTTextConfig(**A						)
           _UpperCAmelCase      :     int        =   OwlViTVisionConfig(**A						)

           _UpperCAmelCase      :     Optional[Any]        =   projection_dim
           _UpperCAmelCase      :     str        =   logit_scale_init_value
           _UpperCAmelCase      :     Optional[Any]        =   return_dict
           _UpperCAmelCase      :     str        =   1.0



      @classmethod
      def 						snake_case_ (					cls					:     Dict					,     A					:     Union[str, os.PathLike]					,     **A					:     Any						):
           cls._set_token_in_kwargs(A						)

           _UpperCAmelCase    ,	_UpperCAmelCase      :     str        =   cls.get_config_dict(A					,     **A						)

           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						)



      @classmethod
      def 						snake_case_ (					cls					:     Optional[int]					,     A					:     Dict					,     A					:     Dict					,     **A					:     Optional[Any]						):
           _UpperCAmelCase      :     Optional[Any]        =   {}
           _UpperCAmelCase      :     int        =   text_config
           _UpperCAmelCase      :     Dict        =   vision_config

           return cls.from_dict(A					,     **A						)



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







class      UpperCAmelCase_  (    _UpperCamelCase						):



      @property
      def 						snake_case_ (					self					:     List[str]						):
           return OrderedDict(
               [
                   ("input_ids", {0: "batch", 1: "sequence"}),
                   ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
                   ("attention_mask", {0: "batch", 1: "sequence"}),
               ]						)



      @property
      def 						snake_case_ (					self					:     Optional[int]						):
           return OrderedDict(
               [
                   ("logits_per_image", {0: "batch"}),
                   ("logits_per_text", {0: "batch"}),
                   ("text_embeds", {0: "batch"}),
                   ("image_embeds", {0: "batch"}),
               ]						)



      @property
      def 						snake_case_ (					self					:     str						):
           return 1e-4



      def 						snake_case_ (					self					:     str					,     A					:     "ProcessorMixin"					,     A					:     int = -1					,     A					:     int = -1					,     A					:     Optional["TensorType"] = None					,     ):
           _UpperCAmelCase      :     Optional[Any]        =   super().generate_dummy_inputs(
               processor.tokenizer					,     batch_size=A					,     seq_length=A					,     framework=A						)
           _UpperCAmelCase      :     Union[str, Any]        =   super().generate_dummy_inputs(
               processor.image_processor					,     batch_size=A					,     framework=A						)
           return {**text_input_dict, **image_input_dict}



      @property
      def 						snake_case_ (					self					:     List[Any]						):
           return 1_4
