



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


SCREAMING_SNAKE_CASE__     :						Dict	=  logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__     :						Optional[Any]	=  {
    '''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 							a__( snake_case__     ):
			a_	: str									=      '''owlvit_text_model'''






			def __init__(     self					,   _UpperCAmelCase=4_9408					,   _UpperCAmelCase=512					,   _UpperCAmelCase=2048					,   _UpperCAmelCase=12					,   _UpperCAmelCase=8					,   _UpperCAmelCase=16					,   _UpperCAmelCase="quick_gelu"					,   _UpperCAmelCase=1E-5					,   _UpperCAmelCase=0.0					,   _UpperCAmelCase=0.02					,   _UpperCAmelCase=1.0					,   _UpperCAmelCase=0					,   _UpperCAmelCase=4_9406					,   _UpperCAmelCase=4_9407					,   **_UpperCAmelCase					,   )							->							List[str]:
					super().__init__(pad_token_id=_UpperCAmelCase					,   bos_token_id=_UpperCAmelCase					,   eos_token_id=_UpperCAmelCase					,   **_UpperCAmelCase						)

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






			@classmethod
			def 						_lowercase  (     cls					,   _UpperCAmelCase					,   **_UpperCAmelCase						)							->							"PretrainedConfig":
					cls._set_token_in_kwargs(_UpperCAmelCase						)

					snake_case__     ,	snake_case__	     =cls.get_config_dict(_UpperCAmelCase					,   **_UpperCAmelCase						)

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





class 							a__( snake_case__     ):
			a_	: Optional[int]									=      '''owlvit_vision_model'''






			def __init__(     self					,   _UpperCAmelCase=768					,   _UpperCAmelCase=3072					,   _UpperCAmelCase=12					,   _UpperCAmelCase=12					,   _UpperCAmelCase=3					,   _UpperCAmelCase=768					,   _UpperCAmelCase=32					,   _UpperCAmelCase="quick_gelu"					,   _UpperCAmelCase=1E-5					,   _UpperCAmelCase=0.0					,   _UpperCAmelCase=0.02					,   _UpperCAmelCase=1.0					,   **_UpperCAmelCase					,   )							->							Union[str, Any]:
					super().__init__(**_UpperCAmelCase						)

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






			@classmethod
			def 						_lowercase  (     cls					,   _UpperCAmelCase					,   **_UpperCAmelCase						)							->							"PretrainedConfig":
					cls._set_token_in_kwargs(_UpperCAmelCase						)

					snake_case__     ,	snake_case__	     =cls.get_config_dict(_UpperCAmelCase					,   **_UpperCAmelCase						)

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





class 							a__( snake_case__     ):
			a_	: Dict									=      '''owlvit'''
			a_	: Union[str, Any]									=      True






			def __init__(     self					,   _UpperCAmelCase=None					,   _UpperCAmelCase=None					,   _UpperCAmelCase=512					,   _UpperCAmelCase=2.6_592					,   _UpperCAmelCase=True					,   **_UpperCAmelCase					,   )							->							Any:
					super().__init__(**_UpperCAmelCase						)

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

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

					snake_case__	     =OwlViTTextConfig(**_UpperCAmelCase						)
					snake_case__	     =OwlViTVisionConfig(**_UpperCAmelCase						)

					snake_case__	     =projection_dim
					snake_case__	     =logit_scale_init_value
					snake_case__	     =return_dict
					snake_case__	     =1.0






			@classmethod
			def 						_lowercase  (     cls					,   _UpperCAmelCase					,   **_UpperCAmelCase						)							->							"PretrainedConfig":
					cls._set_token_in_kwargs(_UpperCAmelCase						)

					snake_case__     ,	snake_case__	     =cls.get_config_dict(_UpperCAmelCase					,   **_UpperCAmelCase						)

					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(_UpperCAmelCase					,   **_UpperCAmelCase						)






			@classmethod
			def 						_lowercase  (     cls					,   _UpperCAmelCase					,   _UpperCAmelCase					,   **_UpperCAmelCase						)							->							Optional[int]:
					snake_case__	     ={}
					snake_case__	     =text_config
					snake_case__	     =vision_config

					return cls.from_dict(_UpperCAmelCase					,   **_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Any:
					snake_case__	     =copy.deepcopy(self.__dict__						)
					snake_case__	     =self.text_config.to_dict()
					snake_case__	     =self.vision_config.to_dict()
					snake_case__	     =self.__class__.model_type
					return output





class 							a__( snake_case__     ):






			@property
			def 						_lowercase  (     self						)							->							Mapping[str, Mapping[int, 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 						_lowercase  (     self						)							->							Mapping[str, Mapping[int, str]]:
					return OrderedDict(
					    [
					        ('logits_per_image', {0: 'batch'}),
					        ('logits_per_text', {0: 'batch'}),
					        ('text_embeds', {0: 'batch'}),
					        ('image_embeds', {0: 'batch'}),
					    ]						)






			@property
			def 						_lowercase  (     self						)							->							float:
					return 1E-4






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase = -1					,   _UpperCAmelCase = -1					,   _UpperCAmelCase = None					,   )							->							Mapping[str, Any]:
					snake_case__	     =super().generate_dummy_inputs(
					    processor.tokenizer					,   batch_size=_UpperCAmelCase					,   seq_length=_UpperCAmelCase					,   framework=_UpperCAmelCase						)
					snake_case__	     =super().generate_dummy_inputs(
					    processor.image_processor					,   batch_size=_UpperCAmelCase					,   framework=_UpperCAmelCase						)
					return {**text_input_dict, **image_input_dict}






			@property
			def 						_lowercase  (     self						)							->							int:
					return 14









'''simple docstring'''

from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
			if not (is_transformers_available() and is_torch_available() and is_transformers_version('''>=''', '''4.25.0''')):
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			from ...utils.dummy_torch_and_transformers_objects import UnCLIPImageVariationPipeline, UnCLIPPipeline
else:
			from .pipeline_unclip import UnCLIPPipeline
			from .pipeline_unclip_image_variation import UnCLIPImageVariationPipeline
			from .text_proj import UnCLIPTextProjModel




