


"""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


UpperCAmelCase__  							=logging.get_logger(__name__)

UpperCAmelCase__  							={
    "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    lowerCamelCase__						(		_a    ):
      a :     Any											=		"""owlvit_text_model"""
      def __init__(		self	:	Optional[int]      ,       A_	:	Dict=4_9_4_0_8      ,       A_	:	Tuple=5_1_2      ,       A_	:	str=2_0_4_8      ,       A_	:	Any=1_2      ,       A_	:	Tuple=8      ,       A_	:	Dict=1_6      ,       A_	:	List[str]="quick_gelu"      ,       A_	:	str=1e-5      ,       A_	:	int=0.0      ,       A_	:	List[Any]=0.02      ,       A_	:	Dict=1.0      ,       A_	:	Optional[Any]=0      ,       A_	:	Optional[int]=4_9_4_0_6      ,       A_	:	Optional[Any]=4_9_4_0_7      ,       **A_	:	List[Any]      ,       ):






       '''simple docstring'''


       super().__init__(pad_token_id=A_      ,       bos_token_id=A_      ,       eos_token_id=A_      ,       **A_							)

       __lowercase									=	vocab_size
       __lowercase									=	hidden_size
       __lowercase									=	intermediate_size
       __lowercase									=	num_hidden_layers
       __lowercase									=	num_attention_heads
       __lowercase									=	max_position_embeddings
       __lowercase									=	hidden_act
       __lowercase									=	layer_norm_eps
       __lowercase									=	attention_dropout
       __lowercase									=	initializer_range
       __lowercase									=	initializer_factor






      @classmethod
      def SCREAMING_SNAKE_CASE_	(		cls	:	Dict      ,       A_	:	Union[str, os.PathLike]      ,       **A_	:	List[Any]							):






       '''simple docstring'''


       cls._set_token_in_kwargs(A_							)

       __lowercase							,		__lowercase									=	cls.get_config_dict(A_      ,       **A_							)

       # get the text config dict if we are loading from OwlViTConfig
       if config_dict.get("""model_type"""							) == "owlvit":
        __lowercase									=	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    lowerCamelCase__						(		_a    ):
      a :     Union[str, Any]											=		"""owlvit_vision_model"""
      def __init__(		self	:	List[Any]      ,       A_	:	Any=7_6_8      ,       A_	:	List[str]=3_0_7_2      ,       A_	:	Optional[int]=1_2      ,       A_	:	Any=1_2      ,       A_	:	Dict=3      ,       A_	:	Dict=7_6_8      ,       A_	:	Any=3_2      ,       A_	:	Tuple="quick_gelu"      ,       A_	:	int=1e-5      ,       A_	:	Dict=0.0      ,       A_	:	Tuple=0.02      ,       A_	:	Tuple=1.0      ,       **A_	:	Optional[Any]      ,       ):






       '''simple docstring'''


       super().__init__(**A_							)

       __lowercase									=	hidden_size
       __lowercase									=	intermediate_size
       __lowercase									=	num_hidden_layers
       __lowercase									=	num_attention_heads
       __lowercase									=	num_channels
       __lowercase									=	image_size
       __lowercase									=	patch_size
       __lowercase									=	hidden_act
       __lowercase									=	layer_norm_eps
       __lowercase									=	attention_dropout
       __lowercase									=	initializer_range
       __lowercase									=	initializer_factor






      @classmethod
      def SCREAMING_SNAKE_CASE_	(		cls	:	Union[str, Any]      ,       A_	:	Union[str, os.PathLike]      ,       **A_	:	List[str]							):






       '''simple docstring'''


       cls._set_token_in_kwargs(A_							)

       __lowercase							,		__lowercase									=	cls.get_config_dict(A_      ,       **A_							)

       # get the vision config dict if we are loading from OwlViTConfig
       if config_dict.get("""model_type"""							) == "owlvit":
        __lowercase									=	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    lowerCamelCase__						(		_a    ):
      a :     Dict											=		"""owlvit"""
      a :     Union[str, Any]											=		True
      def __init__(		self	:	Union[str, Any]      ,       A_	:	List[Any]=None      ,       A_	:	Optional[Any]=None      ,       A_	:	List[Any]=5_1_2      ,       A_	:	Tuple=2.65_92      ,       A_	:	Optional[int]=True      ,       **A_	:	Optional[int]      ,       ):






       '''simple docstring'''


       super().__init__(**A_							)

       if text_config is None:
        __lowercase									=	{}
        logger.info("""text_config is None. Initializing the OwlViTTextConfig with default values."""							)

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

       __lowercase									=	OwlViTTextConfig(**A_							)
       __lowercase									=	OwlViTVisionConfig(**A_							)

       __lowercase									=	projection_dim
       __lowercase									=	logit_scale_init_value
       __lowercase									=	return_dict
       __lowercase									=	1.0
      @classmethod
      def SCREAMING_SNAKE_CASE_	(		cls	:	Optional[int]      ,       A_	:	Union[str, os.PathLike]      ,       **A_	:	Tuple							):






       '''simple docstring'''


       cls._set_token_in_kwargs(A_							)

       __lowercase							,		__lowercase									=	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 SCREAMING_SNAKE_CASE_	(		cls	:	Union[str, Any]      ,       A_	:	Dict      ,       A_	:	Dict      ,       **A_	:	Union[str, Any]							):






       '''simple docstring'''


       __lowercase									=	{}
       __lowercase									=	text_config
       __lowercase									=	vision_config

       return cls.from_dict(A_      ,       **A_							)






      def SCREAMING_SNAKE_CASE_	(		self	:	Optional[int]							):






       '''simple docstring'''


       __lowercase									=	copy.deepcopy(self.__dict__							)
       __lowercase									=	self.text_config.to_dict()
       __lowercase									=	self.vision_config.to_dict()
       __lowercase									=	self.__class__.model_type
       return output






class    lowerCamelCase__						(		_a    ):
      @property
      def SCREAMING_SNAKE_CASE_	(		self	:	Tuple							):






       '''simple docstring'''


       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 SCREAMING_SNAKE_CASE_	(		self	:	Union[str, Any]							):






       '''simple docstring'''


       return OrderedDict(
           [
               ("""logits_per_image""", {0: """batch"""}),
               ("""logits_per_text""", {0: """batch"""}),
               ("""text_embeds""", {0: """batch"""}),
               ("""image_embeds""", {0: """batch"""}),
           ]							)
      @property
      def SCREAMING_SNAKE_CASE_	(		self	:	List[Any]							):






       '''simple docstring'''


       return 1e-4
      def SCREAMING_SNAKE_CASE_	(		self	:	Union[str, Any]      ,       A_	:	"ProcessorMixin"      ,       A_	:	int = -1      ,       A_	:	int = -1      ,       A_	:	Optional["TensorType"] = None      ,       ):






       '''simple docstring'''


       __lowercase									=	super().generate_dummy_inputs(
           processor.tokenizer      ,       batch_size=A_      ,       seq_length=A_      ,       framework=A_							)
       __lowercase									=	super().generate_dummy_inputs(
           processor.image_processor      ,       batch_size=A_      ,       framework=A_							)
       return {**text_input_dict, **image_input_dict}






      @property
      def SCREAMING_SNAKE_CASE_	(		self	:	Optional[Any]							):






       '''simple docstring'''


       return 1_4




"""simple docstring"""

from typing import TYPE_CHECKING

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


UpperCAmelCase__  							={"configuration_van": ["VAN_PRETRAINED_CONFIG_ARCHIVE_MAP", "VanConfig"]}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase__  							=[
           "VAN_PRETRAINED_MODEL_ARCHIVE_LIST",
           "VanForImageClassification",
           "VanModel",
           "VanPreTrainedModel",
       ]

if TYPE_CHECKING:
       from .configuration_van import VAN_PRETRAINED_CONFIG_ARCHIVE_MAP, VanConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_van import (
                  VAN_PRETRAINED_MODEL_ARCHIVE_LIST,
                  VanForImageClassification,
                  VanModel,
                  VanPreTrainedModel,
              )

else:
       import sys

       UpperCAmelCase__  							=_LazyModule(__name__, globals()["__file__"], _import_structure)
