





"""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_			=      logging.get_logger(__name__)

a_			=      {
    """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 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					"""owlvit_text_model"""

 def __init__(   self ,						__lowerCamelCase=4_9408 ,						__lowerCamelCase=512 ,						__lowerCamelCase=2048 ,						__lowerCamelCase=12 ,						__lowerCamelCase=8 ,						__lowerCamelCase=16 ,						__lowerCamelCase="quick_gelu" ,						__lowerCamelCase=1e-5 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.0_2 ,						__lowerCamelCase=1.0 ,						__lowerCamelCase=0 ,						__lowerCamelCase=4_9406 ,						__lowerCamelCase=4_9407 ,						**__lowerCamelCase ,						):



     '''simple docstring'''




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

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







 @classmethod
 def  UpperCamelCase__(   cls ,						__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




     cls._set_token_in_kwargs(__lowerCamelCase  )

     __A			,	__A   :						str									=					cls.get_config_dict(__lowerCamelCase ,						**__lowerCamelCase  )

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






class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					"""owlvit_vision_model"""

 def __init__(   self ,						__lowerCamelCase=768 ,						__lowerCamelCase=3072 ,						__lowerCamelCase=12 ,						__lowerCamelCase=12 ,						__lowerCamelCase=3 ,						__lowerCamelCase=768 ,						__lowerCamelCase=32 ,						__lowerCamelCase="quick_gelu" ,						__lowerCamelCase=1e-5 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.0_2 ,						__lowerCamelCase=1.0 ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase  )

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







 @classmethod
 def  UpperCamelCase__(   cls ,						__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




     cls._set_token_in_kwargs(__lowerCamelCase  )

     __A			,	__A   :						str									=					cls.get_config_dict(__lowerCamelCase ,						**__lowerCamelCase  )

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






class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					"""owlvit"""
 _lowerCamelCase				=					True

 def __init__(   self ,						__lowerCamelCase=None ,						__lowerCamelCase=None ,						__lowerCamelCase=512 ,						__lowerCamelCase=2.6_5_9_2 ,						__lowerCamelCase=True ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase  )

     if text_config is None:
         __A   :						List[str]									=					{}
         logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.'''  )

     if vision_config is None:
         __A   :						List[str]									=					{}
         logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.'''  )

     __A   :						List[Any]									=					OwlViTTextConfig(**__lowerCamelCase  )
     __A   :						Optional[Any]									=					OwlViTVisionConfig(**__lowerCamelCase  )

     __A   :						Dict									=					projection_dim
     __A   :						Tuple									=					logit_scale_init_value
     __A   :						Optional[int]									=					return_dict
     __A   :						int									=					1.0

 @classmethod
 def  UpperCamelCase__(   cls ,						__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




     cls._set_token_in_kwargs(__lowerCamelCase  )

     __A			,	__A   :						int									=					cls.get_config_dict(__lowerCamelCase ,						**__lowerCamelCase  )

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

 @classmethod
 def  UpperCamelCase__(   cls ,						__lowerCamelCase ,						__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						str									=					{}
     __A   :						Optional[int]									=					text_config
     __A   :						List[Any]									=					vision_config

     return cls.from_dict(__lowerCamelCase ,						**__lowerCamelCase  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




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






class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 @property
 def  UpperCamelCase__(   self  ):



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



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



     '''simple docstring'''




     return 1e-4

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase = -1 ,						__lowerCamelCase = -1 ,						__lowerCamelCase = None ,						):



     '''simple docstring'''




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







 @property
 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     return 14











"""simple docstring"""



from pathlib import PurePosixPath
from typing import Optional

import fsspec
from fsspec import AbstractFileSystem
from huggingface_hub.hf_api import DatasetInfo

from ..utils.file_utils import get_authentication_headers_for_url
from ..utils.hub import hf_hub_url






class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					""""""
 _lowerCamelCase				=					"""hf-legacy"""  # "hf://"" is reserved for hffs

 def __init__(   self ,						__lowerCamelCase = None ,						__lowerCamelCase = None ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     super().__init__(self ,						**__lowerCamelCase  )
     __A   :						int									=					repo_info
     __A   :						Optional[int]									=					token
     __A   :						int									=					None

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     if self.dir_cache is None:
         __A   :						int									=					{}
         for hf_file in self.repo_info.siblings:
             # TODO(QL): add sizes
             __A   :						Tuple									=					{
                 '''name''': hf_file.rfilename,
                 '''size''': None,
                 '''type''': '''file''',
             }
             self.dir_cache.update(
                 {
                     str(__lowerCamelCase  ): {'''name''': str(__lowerCamelCase  ), '''size''': None, '''type''': '''directory'''}
                     for d in list(PurePosixPath(hf_file.rfilename  ).parents  )[:-1]
                 }  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase = "rb" ,						**__lowerCamelCase ,						):



     '''simple docstring'''




     if not isinstance(self.repo_info ,						__lowerCamelCase  ):
         raise NotImplementedError(F"""Open is only implemented for dataset repositories, but got {self.repo_info}"""  )
     __A   :						Union[str, Any]									=					hf_hub_url(self.repo_info.id ,						__lowerCamelCase ,						revision=self.repo_info.sha  )
     return fsspec.open(
         __lowerCamelCase ,						mode=__lowerCamelCase ,						headers=get_authentication_headers_for_url(__lowerCamelCase ,						use_auth_token=self.token  ) ,						client_kwargs={'''trust_env''': True} ,						).open()

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						**__lowerCamelCase  ):



     '''simple docstring'''




     self._get_dirs()
     __A   :						Optional[Any]									=					self._strip_protocol(__lowerCamelCase  )
     if path in self.dir_cache:
         return self.dir_cache[path]
     else:
         raise FileNotFoundError(__lowerCamelCase  )







 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase=False ,						**__lowerCamelCase  ):



     '''simple docstring'''




     self._get_dirs()
     __A   :						Any									=					PurePosixPath(path.strip('''/'''  )  )
     __A   :						Any									=					{}
     for p, f in self.dir_cache.items():
         __A   :						List[Any]									=					PurePosixPath(p.strip('''/'''  )  )
         __A   :						Dict									=					p.parent
         if root == path:
             __A   :						Union[str, Any]									=					f
     __A   :						List[str]									=					list(paths.values()  )
     if detail:
         return out
     else:
         return sorted(f['''name'''] for f in out  )




