
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


lowercase_ 				=			logging.get_logger(__name__)

lowercase_ 				=			{
    """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 (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''owlvit_text_model'''



     def __init__(				self							:							Dict     ,						_A							:							int=4_9408     ,						_A							:							int=512     ,						_A							:							Optional[int]=2048     ,						_A							:							List[str]=12     ,						_A							:							Any=8     ,						_A							:							str=16     ,						_A							:							Union[str, Any]="quick_gelu"     ,						_A							:							Optional[Any]=1e-5     ,						_A							:							Tuple=0.0     ,						_A							:							Tuple=0.02     ,						_A							:							Tuple=1.0     ,						_A							:							Union[str, Any]=0     ,						_A							:							Tuple=4_9406     ,						_A							:							Any=4_9407     ,						**_A							:							Tuple     ,						):







       """simple docstring"""




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

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




     @classmethod
     def  UpperCAmelCase__							(				cls							:							Optional[int]     ,						_A							:							Union[str, os.PathLike]     ,						**_A							:							Tuple ):







       """simple docstring"""




       cls._set_token_in_kwargs(_A )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	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":
         __SCREAMING_SNAKE_CASE      :	Optional[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 (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''owlvit_vision_model'''



     def __init__(				self							:							List[str]     ,						_A							:							Optional[Any]=768     ,						_A							:							List[Any]=3072     ,						_A							:							Union[str, Any]=12     ,						_A							:							Dict=12     ,						_A							:							Tuple=3     ,						_A							:							Any=768     ,						_A							:							Optional[Any]=32     ,						_A							:							List[str]="quick_gelu"     ,						_A							:							Optional[int]=1e-5     ,						_A							:							Union[str, Any]=0.0     ,						_A							:							Tuple=0.02     ,						_A							:							Union[str, Any]=1.0     ,						**_A							:							Any     ,						):







       """simple docstring"""




       super().__init__(**_A )

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




     @classmethod
     def  UpperCAmelCase__							(				cls							:							Union[str, Any]     ,						_A							:							Union[str, os.PathLike]     ,						**_A							:							Optional[Any] ):







       """simple docstring"""




       cls._set_token_in_kwargs(_A )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	int					=		cls.get_config_dict(_A     ,						**_A )

       # get the vision config dict if we are loading from OwlViTConfig
       if config_dict.get('''model_type''' ) == "owlvit":
         __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		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 (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''owlvit'''
     lowerCAmelCase_							   =			True



     def __init__(				self							:							int     ,						_A							:							Optional[Any]=None     ,						_A							:							List[Any]=None     ,						_A							:							Optional[Any]=512     ,						_A							:							List[str]=2.65_92     ,						_A							:							List[Any]=True     ,						**_A							:							List[Any]     ,						):







       """simple docstring"""




       super().__init__(**_A )

       if text_config is None:
         __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		{}
         logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.''' )

       if vision_config is None:
         __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		{}
         logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.''' )

       __SCREAMING_SNAKE_CASE      :	Any					=		OwlViTTextConfig(**_A )
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		OwlViTVisionConfig(**_A )

       __SCREAMING_SNAKE_CASE      :	Tuple					=		projection_dim
       __SCREAMING_SNAKE_CASE      :	List[str]					=		logit_scale_init_value
       __SCREAMING_SNAKE_CASE      :	Any					=		return_dict
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		1.0



     @classmethod
     def  UpperCAmelCase__							(				cls							:							Union[str, Any]     ,						_A							:							Union[str, os.PathLike]     ,						**_A							:							Optional[Any] ):







       """simple docstring"""




       cls._set_token_in_kwargs(_A )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Tuple					=		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  UpperCAmelCase__							(				cls							:							Any     ,						_A							:							Dict     ,						_A							:							Dict     ,						**_A							:							int ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	str					=		{}
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		text_config
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		vision_config

       return cls.from_dict(_A     ,						**_A )




     def  UpperCAmelCase__							(				self							:							List[str] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		copy.deepcopy(self.__dict__ )
       __SCREAMING_SNAKE_CASE      :	str					=		self.text_config.to_dict()
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		self.vision_config.to_dict()
       __SCREAMING_SNAKE_CASE      :	Any					=		self.__class__.model_type
       return output






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







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







       """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  UpperCAmelCase__							(				self							:							Optional[int] ):







       """simple docstring"""




       return OrderedDict(
           [
               ('''logits_per_image''', {0: '''batch'''}),
               ('''logits_per_text''', {0: '''batch'''}),
               ('''text_embeds''', {0: '''batch'''}),
               ('''image_embeds''', {0: '''batch'''}),
           ] )



     @property
     def  UpperCAmelCase__							(				self							:							Optional[int] ):







       """simple docstring"""




       return 1e-4



     def  UpperCAmelCase__							(				self							:							List[str]     ,						_A							:							"ProcessorMixin"     ,						_A							:							int = -1     ,						_A							:							int = -1     ,						_A							:							Optional["TensorType"] = None     ,						):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Dict					=		super().generate_dummy_inputs(
           processor.tokenizer     ,						batch_size=_A     ,						seq_length=_A     ,						framework=_A )
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		super().generate_dummy_inputs(
           processor.image_processor     ,						batch_size=_A     ,						framework=_A )
       return {**text_input_dict, **image_input_dict}




     @property
     def  UpperCAmelCase__							(				self							:							int ):







       """simple docstring"""




       return 14




from typing import TYPE_CHECKING

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


SCREAMING_SNAKE_CASE			: List[Any]				   =					{
    "configuration_poolformer": [
        "POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "PoolFormerConfig",
        "PoolFormerOnnxConfig",
    ]
}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE			: List[str]				   =					["PoolFormerFeatureExtractor"]
 SCREAMING_SNAKE_CASE			: List[Any]				   =					["PoolFormerImageProcessor"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE			: List[Any]				   =					[
     "POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
     "PoolFormerForImageClassification",
     "PoolFormerModel",
     "PoolFormerPreTrainedModel",
 ]


if TYPE_CHECKING:
 from .configuration_poolformer import (
     POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
     PoolFormerConfig,
     PoolFormerOnnxConfig,
 )

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_poolformer import PoolFormerFeatureExtractor
  from .image_processing_poolformer import PoolFormerImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_poolformer import (
      POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
      PoolFormerForImageClassification,
      PoolFormerModel,
      PoolFormerPreTrainedModel,
  )


else:
 import sys

 SCREAMING_SNAKE_CASE			: str				   =					_LazyModule(__name__, globals()["__file__"], _import_structure)


