


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


_a   :   str												=   logging.get_logger(__name__)

_a   :   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 			_lowercase (	__lowercase							):
   _SCREAMING_SNAKE_CASE  :  Any          =	"owlvit_text_model"
   def __init__(						self       :      Any       ,   SCREAMING_SNAKE_CASE_       :      int=4_9408       ,   SCREAMING_SNAKE_CASE_       :      Dict=512       ,   SCREAMING_SNAKE_CASE_       :      Any=2048       ,   SCREAMING_SNAKE_CASE_       :      List[str]=12       ,   SCREAMING_SNAKE_CASE_       :      List[str]=8       ,   SCREAMING_SNAKE_CASE_       :      Union[str, Any]=16       ,   SCREAMING_SNAKE_CASE_       :      Any="quick_gelu"       ,   SCREAMING_SNAKE_CASE_       :      Optional[Any]=1e-5       ,   SCREAMING_SNAKE_CASE_       :      Tuple=0.0       ,   SCREAMING_SNAKE_CASE_       :      int=0.0_2       ,   SCREAMING_SNAKE_CASE_       :      List[Any]=1.0       ,   SCREAMING_SNAKE_CASE_       :      Optional[int]=0       ,   SCREAMING_SNAKE_CASE_       :      List[Any]=4_9406       ,   SCREAMING_SNAKE_CASE_       :      int=4_9407       ,   **SCREAMING_SNAKE_CASE_       :      Union[str, Any]       ,   ) ->							Tuple:
        super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_       ,   bos_token_id=SCREAMING_SNAKE_CASE_       ,   eos_token_id=SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )

        __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 a  (						cls       :      Dict       ,   SCREAMING_SNAKE_CASE_       :      Union[str, os.PathLike]       ,   **SCREAMING_SNAKE_CASE_       :      Union[str, Any]      ) ->							"PretrainedConfig":
        cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_      )

        __snake_case      ,       __snake_case           =						cls.get_config_dict(SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )

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




class 			_lowercase (	__lowercase							):
   _SCREAMING_SNAKE_CASE  :  Any          =	"owlvit_vision_model"
   def __init__(						self       :      Optional[int]       ,   SCREAMING_SNAKE_CASE_       :      int=768       ,   SCREAMING_SNAKE_CASE_       :      List[Any]=3072       ,   SCREAMING_SNAKE_CASE_       :      Any=12       ,   SCREAMING_SNAKE_CASE_       :      List[Any]=12       ,   SCREAMING_SNAKE_CASE_       :      str=3       ,   SCREAMING_SNAKE_CASE_       :      Any=768       ,   SCREAMING_SNAKE_CASE_       :      Optional[int]=32       ,   SCREAMING_SNAKE_CASE_       :      Union[str, Any]="quick_gelu"       ,   SCREAMING_SNAKE_CASE_       :      Any=1e-5       ,   SCREAMING_SNAKE_CASE_       :      str=0.0       ,   SCREAMING_SNAKE_CASE_       :      List[Any]=0.0_2       ,   SCREAMING_SNAKE_CASE_       :      Any=1.0       ,   **SCREAMING_SNAKE_CASE_       :      str       ,   ) ->							Optional[int]:
        super().__init__(**SCREAMING_SNAKE_CASE_      )

        __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 a  (						cls       :      List[Any]       ,   SCREAMING_SNAKE_CASE_       :      Union[str, os.PathLike]       ,   **SCREAMING_SNAKE_CASE_       :      List[Any]      ) ->							"PretrainedConfig":
        cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_      )

        __snake_case      ,       __snake_case           =						cls.get_config_dict(SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )

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




class 			_lowercase (	__lowercase							):
   _SCREAMING_SNAKE_CASE  :  Union[str, Any]          =	"owlvit"
   _SCREAMING_SNAKE_CASE  :  int          =	True
   def __init__(						self       :      Optional[int]       ,   SCREAMING_SNAKE_CASE_       :      str=None       ,   SCREAMING_SNAKE_CASE_       :      Optional[int]=None       ,   SCREAMING_SNAKE_CASE_       :      Tuple=512       ,   SCREAMING_SNAKE_CASE_       :      Dict=2.6_5_9_2       ,   SCREAMING_SNAKE_CASE_       :      Tuple=True       ,   **SCREAMING_SNAKE_CASE_       :      Any       ,   ) ->							Dict:
        super().__init__(**SCREAMING_SNAKE_CASE_      )

        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(**SCREAMING_SNAKE_CASE_      )
        __snake_case           =						OwlViTVisionConfig(**SCREAMING_SNAKE_CASE_      )

        __snake_case           =						projection_dim
        __snake_case           =						logit_scale_init_value
        __snake_case           =						return_dict
        __snake_case           =						1.0
   @classmethod
   def a  (						cls       :      Dict       ,   SCREAMING_SNAKE_CASE_       :      Union[str, os.PathLike]       ,   **SCREAMING_SNAKE_CASE_       :      Optional[int]      ) ->							"PretrainedConfig":
        cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_      )

        __snake_case      ,       __snake_case           =						cls.get_config_dict(SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )

        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(SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )
   @classmethod
   def a  (						cls       :      Optional[Any]       ,   SCREAMING_SNAKE_CASE_       :      Dict       ,   SCREAMING_SNAKE_CASE_       :      Dict       ,   **SCREAMING_SNAKE_CASE_       :      Dict      ) ->							Any:
        __snake_case           =						{}
        __snake_case           =						text_config
        __snake_case           =						vision_config

        return cls.from_dict(SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )





   def a  (						self       :      str      ) ->							str:
        __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 			_lowercase (	__lowercase							):
   @property
   def a  (						self       :      int      ) ->							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 a  (						self       :      List[str]      ) ->							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 a  (						self       :      Optional[int]      ) ->							float:
        return 1e-4
   def a  (						self       :      Optional[int]       ,   SCREAMING_SNAKE_CASE_       :      "ProcessorMixin"       ,   SCREAMING_SNAKE_CASE_       :      int = -1       ,   SCREAMING_SNAKE_CASE_       :      int = -1       ,   SCREAMING_SNAKE_CASE_       :      Optional["TensorType"] = None       ,   ) ->							Mapping[str, Any]:
        __snake_case           =						super().generate_dummy_inputs(
            processor.tokenizer       ,   batch_size=SCREAMING_SNAKE_CASE_       ,   seq_length=SCREAMING_SNAKE_CASE_       ,   framework=SCREAMING_SNAKE_CASE_      )
        __snake_case           =						super().generate_dummy_inputs(
            processor.image_processor       ,   batch_size=SCREAMING_SNAKE_CASE_       ,   framework=SCREAMING_SNAKE_CASE_      )
        return {**text_input_dict, **image_input_dict}





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





from typing import Optional
from urllib.parse import quote

import huggingface_hub as hfh
from packaging import version


def 				lowerCAmelCase__       (			a__    ,     a__    ,     a__ = None )      ->str:




  '''simple docstring'''

  if version.parse(hfh.__version__ ).release < version.parse("0.11.0" ).release:
    # old versions of hfh don't url-encode the file path
    _UpperCamelCase           =    quote(a__ )
  return hfh.hf_hub_url(a__    ,     a__    ,     repo_type="dataset"    ,     revision=a__ )




