


'''simple docstring'''


import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							""""""
  a_  					=							(
      None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
  )
  a_  					=							None  # compression type in fsspec. ex: "gzip"
  a_  					=							None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz






  def __init__(							self :       int	,_a :       str = ""	,_a :       Optional[str] = None	,_a :       Optional[dict] = None	,**_a :       Optional[Any] ):

        '''simple docstring'''




        super().__init__(self	,**_a )
        # always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
        A_						:  Dict          =				fsspec.open(
            _a	,mode="""rb"""	,protocol=_a	,compression=self.compression	,client_kwargs={
                """requote_redirect_url""": False,  # see https://github.com/huggingface/datasets/pull/5459
                """trust_env""": True,  # Enable reading proxy env variables.
                **(target_options or {}).pop("""client_kwargs"""	,{} ),  # To avoid issues if it was already passed.
            }	,**(target_options or {})	,)
        A_						:  Dict          =				os.path.basename(self.file.path.split("""::""" )[0] )
        A_						:  Dict          =				(
            self.compressed_name[: self.compressed_name.rindex(""".""" )]
            if """.""" in self.compressed_name
            else self.compressed_name
        )
        A_						:  int          =				None






  @classmethod
  def        _a							(							cls :       List[str]	,_a :       str ):

        '''simple docstring'''




        return super()._strip_protocol(_a ).lstrip("""/""" )






  def        _a							(							self :       Optional[Any] ):

        '''simple docstring'''




        if self.dir_cache is None:
              A_						:  Optional[Any]          =				{**self.file.fs.info(self.file.path ), """name""": self.uncompressed_name}
              A_						:  Optional[Any]          =				{f["""name"""]: f}






  def        _a							(							self :       Optional[int]	,_a :       str ):

        '''simple docstring'''




        return self.file.open().read()






  def        _a							(							self :       Optional[int]	,_a :       str	,_a :       str = "rb"	,_a :       Any=None	,_a :       str=True	,_a :       int=None	,**_a :       List[Any]	,):

        '''simple docstring'''




        A_						:  Dict          =				self._strip_protocol(_a )
        if mode != "rb":
              raise ValueError(f'Tried to read with mode {mode} on file {self.file.path} opened with mode \'rb\'' )
        return self.file.open()







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""bz2"""
  a_  					=							"""bz2"""
  a_  					=							""".bz2"""







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""gzip"""
  a_  					=							"""gzip"""
  a_  					=							""".gz"""







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""lz4"""
  a_  					=							"""lz4"""
  a_  					=							""".lz4"""







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""xz"""
  a_  					=							"""xz"""
  a_  					=							""".xz"""







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""zstd"""
  a_  					=							"""zstd"""
  a_  					=							""".zst"""






  def __init__(							self :       Union[str, Any]	,_a :       str	,_a :       str = "rb"	,_a :       Optional[str] = None	,_a :       Optional[dict] = None	,_a :       int = DEFAULT_BLOCK_SIZE	,**_a :       Union[str, Any]	,):

        '''simple docstring'''




        super().__init__(
            fo=_a	,mode=_a	,target_protocol=_a	,target_options=_a	,block_size=_a	,**_a	,)
        # We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
        #
        # File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
        #     out.close = close
        # AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
        #
        # see https://github.com/intake/filesystem_spec/issues/725
        A_						:  Optional[Any]          =				self.file.__enter__



        class 	__lowerCAmelCase		:


          '''simple docstring'''







          def __init__(							self :       Tuple	,_a :       List[Any] ):

                '''simple docstring'''




                A_						:  Tuple          =				file_






          def __enter__(							self :       Tuple ):

                '''simple docstring'''




                self._file.__enter__()
                return self






          def __exit__(							self :       Union[str, Any]	,*_a :       Tuple	,**_a :       List[str] ):

                '''simple docstring'''




                self._file.__exit__(*_a	,**_a )






          def __iter__(							self :       Any ):

                '''simple docstring'''




                return iter(self._file )






          def        _a							(							self :       Dict ):

                '''simple docstring'''




                return next(self._file )






          def __getattr__(							self :       str	,_a :       Tuple ):

                '''simple docstring'''




                return getattr(self._file	,_a )

        def fixed_enter(*_a :       Dict	,**_a :       Dict ):
              return WrappedFile(_enter(*_a	,**_a ) )

        A_						:  List[str]          =				fixed_enter




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


__magic_name__			=      logging.get_logger(__name__)

__magic_name__			=      {
    '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		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""owlvit_text_model"""






  def __init__(							self :       Union[str, Any]	,_a :       Any=49408	,_a :       Any=512	,_a :       Tuple=2048	,_a :       Dict=12	,_a :       Optional[int]=8	,_a :       Tuple=16	,_a :       Tuple="quick_gelu"	,_a :       Optional[Any]=1e-5	,_a :       List[Any]=0.0	,_a :       Optional[int]=0.02	,_a :       Dict=1.0	,_a :       Dict=0	,_a :       Any=49406	,_a :       Tuple=49407	,**_a :       List[Any]	,):

        '''simple docstring'''




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

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






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

        '''simple docstring'''




        cls._set_token_in_kwargs(_a )

        A_   ,					A_						:  int          =				cls.get_config_dict(_a	,**_a )

        # get the text config dict if we are loading from OwlViTConfig
        if config_dict.get("""model_type""" ) == "owlvit":
              A_						:  Union[str, 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(_a	,**_a )







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""owlvit_vision_model"""






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

        '''simple docstring'''




        super().__init__(**_a )

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






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

        '''simple docstring'''




        cls._set_token_in_kwargs(_a )

        A_   ,					A_						:  Optional[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":
              A_						:  List[str]          =				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		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""owlvit"""
  a_  					=							True






  def __init__(							self :       Union[str, Any]	,_a :       List[str]=None	,_a :       List[str]=None	,_a :       Dict=512	,_a :       List[Any]=2.6592	,_a :       Optional[Any]=True	,**_a :       Optional[int]	,):

        '''simple docstring'''




        super().__init__(**_a )

        if text_config is None:
              A_						:  List[Any]          =				{}
              logger.info("""text_config is None. Initializing the OwlViTTextConfig with default values.""" )

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

        A_						:  Dict          =				OwlViTTextConfig(**_a )
        A_						:  Dict          =				OwlViTVisionConfig(**_a )

        A_						:  Any          =				projection_dim
        A_						:  Optional[int]          =				logit_scale_init_value
        A_						:  Optional[int]          =				return_dict
        A_						:  Dict          =				1.0






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

        '''simple docstring'''




        cls._set_token_in_kwargs(_a )

        A_   ,					A_						:  List[Any]          =				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        _a							(							cls :       int	,_a :       Dict	,_a :       Dict	,**_a :       List[str] ):

        '''simple docstring'''




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

        return cls.from_dict(_a	,**_a )






  def        _a							(							self :       Optional[int] ):

        '''simple docstring'''




        A_						:  Dict          =				copy.deepcopy(self.__dict__ )
        A_						:  str          =				self.text_config.to_dict()
        A_						:  Optional[int]          =				self.vision_config.to_dict()
        A_						:  List[Any]          =				self.__class__.model_type
        return output







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  @property
  def        _a							(							self :       int ):

        '''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        _a							(							self :       str ):

        '''simple docstring'''




        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[Any] ):

        '''simple docstring'''




        return 1e-4






  def        _a							(							self :       int	,_a :       "ProcessorMixin"	,_a :       int = -1	,_a :       int = -1	,_a :       Optional["TensorType"] = None	,):

        '''simple docstring'''




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






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

        '''simple docstring'''




        return 14
