



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


lowerCamelCase      =		logging.get_logger(__name__)

lowerCamelCase      =		{
    """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__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''owlvit_text_model'''



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


             '''simple docstring'''




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

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







       @classmethod
       def   lowercase__       (							cls    :						int	,       _UpperCAmelCase    :						Union[str, os.PathLike]	,       **_UpperCAmelCase    :						List[str]					)				->		"PretrainedConfig":


             '''simple docstring'''




             cls._set_token_in_kwargs(_UpperCAmelCase					)

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

             # get the text config dict if we are loading from OwlViTConfig
             if config_dict.get("model_type"					) == "owlvit":
                   UpperCAmelCase_    				=							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    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''owlvit_vision_model'''



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


             '''simple docstring'''




             super().__init__(**_UpperCAmelCase					)

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







       @classmethod
       def   lowercase__       (							cls    :						Any	,       _UpperCAmelCase    :						Union[str, os.PathLike]	,       **_UpperCAmelCase    :						Union[str, Any]					)				->		"PretrainedConfig":


             '''simple docstring'''




             cls._set_token_in_kwargs(_UpperCAmelCase					)

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

             # get the vision config dict if we are loading from OwlViTConfig
             if config_dict.get("model_type"					) == "owlvit":
                   UpperCAmelCase_    				=							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    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''owlvit'''
       UpperCamelCase		=  True



       def __init__(							self    :						Tuple	,       _UpperCAmelCase    :						Any=None	,       _UpperCAmelCase    :						Dict=None	,       _UpperCAmelCase    :						Tuple=512	,       _UpperCAmelCase    :						Any=2.6592	,       _UpperCAmelCase    :						Union[str, Any]=True	,       **_UpperCAmelCase    :						Union[str, Any]	,       )				->		Tuple:


             '''simple docstring'''




             super().__init__(**_UpperCAmelCase					)

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

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

             UpperCAmelCase_    				=							OwlViTTextConfig(**_UpperCAmelCase					)
             UpperCAmelCase_    				=							OwlViTVisionConfig(**_UpperCAmelCase					)

             UpperCAmelCase_    				=							projection_dim
             UpperCAmelCase_    				=							logit_scale_init_value
             UpperCAmelCase_    				=							return_dict
             UpperCAmelCase_    				=							1.0



       @classmethod
       def   lowercase__       (							cls    :						Dict	,       _UpperCAmelCase    :						Union[str, os.PathLike]	,       **_UpperCAmelCase    :						Tuple					)				->		"PretrainedConfig":


             '''simple docstring'''




             cls._set_token_in_kwargs(_UpperCAmelCase					)

             UpperCAmelCase_				,					UpperCAmelCase_    				=							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    :						List[str]	,       _UpperCAmelCase    :						Dict	,       _UpperCAmelCase    :						Dict	,       **_UpperCAmelCase    :						Any					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							{}
             UpperCAmelCase_    				=							text_config
             UpperCAmelCase_    				=							vision_config

             return cls.from_dict(_UpperCAmelCase	,       **_UpperCAmelCase					)







       def   lowercase__       (							self    :						str					)				->		List[str]:


             '''simple docstring'''




             UpperCAmelCase_    				=							copy.deepcopy(self.__dict__					)
             UpperCAmelCase_    				=							self.text_config.to_dict()
             UpperCAmelCase_    				=							self.vision_config.to_dict()
             UpperCAmelCase_    				=							self.__class__.model_type
             return output



class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       @property
       def   lowercase__       (							self    :						Union[str, Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''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   lowercase__       (							self    :						Tuple					)				->		Mapping[str, Mapping[int, 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   lowercase__       (							self    :						Any					)				->		float:


             '''simple docstring'''




             return 1e-4



       def   lowercase__       (							self    :						List[str]	,       _UpperCAmelCase    :						"ProcessorMixin"	,       _UpperCAmelCase    :						int = -1	,       _UpperCAmelCase    :						int = -1	,       _UpperCAmelCase    :						Optional["TensorType"] = None	,       )				->		Mapping[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							super().generate_dummy_inputs(
                 processor.tokenizer	,       batch_size=_UpperCAmelCase	,       seq_length=_UpperCAmelCase	,       framework=_UpperCAmelCase					)
             UpperCAmelCase_    				=							super().generate_dummy_inputs(
                 processor.image_processor	,       batch_size=_UpperCAmelCase	,       framework=_UpperCAmelCase					)
             return {**text_input_dict, **image_input_dict}







       @property
       def   lowercase__       (							self    :						Dict					)				->		int:


             '''simple docstring'''




             return 14









"""simple docstring"""





import unittest

from transformers.models.xlm_prophetnet.tokenization_xlm_prophetnet import SPIECE_UNDERLINE, XLMProphetNetTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


lowerCamelCase      =		get_tests_dir("""fixtures/test_sentencepiece.model""")
@require_sentencepiece
class    lowercase__     (					SCREAMING_SNAKE_CASE       ,      unittest.TestCase   ):







       '''simple docstring'''


       UpperCamelCase		=  XLMProphetNetTokenizer
       UpperCamelCase		=  False
       UpperCamelCase		=  True



       def   lowercase__       (							self    :						Union[str, Any]					)				->		Any:


             '''simple docstring'''




             super().setUp()

             # We have a SentencePiece fixture for testing
             UpperCAmelCase_    				=							XLMProphetNetTokenizer(_UpperCAmelCase	,       keep_accents=_UpperCAmelCase					)
             tokenizer.save_pretrained(self.tmpdirname					)



       def   lowercase__       (							self    :						Tuple					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							"[PAD]"
             UpperCAmelCase_    				=							0

             self.assertEqual(self.get_tokenizer()._convert_token_to_id(_UpperCAmelCase					)	,       _UpperCAmelCase					)
             self.assertEqual(self.get_tokenizer()._convert_id_to_token(_UpperCAmelCase					)	,       _UpperCAmelCase					)



       def   lowercase__       (							self    :						Dict					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							list(self.get_tokenizer().get_vocab().keys()					)

             self.assertEqual(vocab_keys[0]	,       "[PAD]"					)
             self.assertEqual(vocab_keys[1]	,       "[CLS]"					)
             self.assertEqual(vocab_keys[-1]	,       "j"					)
             self.assertEqual(len(_UpperCAmelCase					)	,       1012					)



       def   lowercase__       (							self    :						Union[str, Any]					)				->		Optional[Any]:


             '''simple docstring'''




             self.assertEqual(self.get_tokenizer().vocab_size	,       1012					)



       def   lowercase__       (							self    :						Tuple					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							XLMProphetNetTokenizer(_UpperCAmelCase	,       keep_accents=_UpperCAmelCase					)

             UpperCAmelCase_    				=							tokenizer.tokenize("This is a test"					)
             self.assertListEqual(_UpperCAmelCase	,       ["▁This", "▁is", "▁a", "▁t", "est"]					)

             self.assertListEqual(
                 tokenizer.convert_tokens_to_ids(_UpperCAmelCase					)	,       [value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]	,       )

             UpperCAmelCase_    				=							tokenizer.tokenize("I was born in 92000, and this is falsé."					)
             self.assertListEqual(
                 _UpperCAmelCase	,       [
                     SPIECE_UNDERLINE + "I",
                     SPIECE_UNDERLINE + "was",
                     SPIECE_UNDERLINE + "b",
                     "or",
                     "n",
                     SPIECE_UNDERLINE + "in",
                     SPIECE_UNDERLINE + "",
                     "9",
                     "2",
                     "0",
                     "0",
                     "0",
                     ",",
                     SPIECE_UNDERLINE + "and",
                     SPIECE_UNDERLINE + "this",
                     SPIECE_UNDERLINE + "is",
                     SPIECE_UNDERLINE + "f",
                     "al",
                     "s",
                     "é",
                     ".",
                 ]	,       )
             UpperCAmelCase_    				=							tokenizer.convert_tokens_to_ids(_UpperCAmelCase					)
             self.assertListEqual(
                 _UpperCAmelCase	,       [
                     value + tokenizer.fairseq_offset
                     for value in [8, 21, 84, 55, 24, 19, 7, -9, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, -9, 4]
                 ]	,       )

             UpperCAmelCase_    				=							tokenizer.convert_ids_to_tokens(_UpperCAmelCase					)
             self.assertListEqual(
                 _UpperCAmelCase	,       [
                     SPIECE_UNDERLINE + "I",
                     SPIECE_UNDERLINE + "was",
                     SPIECE_UNDERLINE + "b",
                     "or",
                     "n",
                     SPIECE_UNDERLINE + "in",
                     SPIECE_UNDERLINE + "",
                     "[UNK]",
                     "2",
                     "0",
                     "0",
                     "0",
                     ",",
                     SPIECE_UNDERLINE + "and",
                     SPIECE_UNDERLINE + "this",
                     SPIECE_UNDERLINE + "is",
                     SPIECE_UNDERLINE + "f",
                     "al",
                     "s",
                     "[UNK]",
                     ".",
                 ]	,       )



       @cached_property
       def   lowercase__       (							self    :						Union[str, Any]					)				->		Optional[Any]:


             '''simple docstring'''




             return XLMProphetNetTokenizer.from_pretrained("microsoft/xprophetnet-large-wiki100-cased"					)



       @slow
       def   lowercase__       (							self    :						List[Any]					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							"Hello World!"
             UpperCAmelCase_    				=							[35389, 6672, 49, 2]
             self.assertListEqual(_UpperCAmelCase	,       self.big_tokenizer.encode(_UpperCAmelCase					)					)







       @slow
       def   lowercase__       (							self    :						Optional[int]					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							{"input_ids": [[11073, 82783, 18, 26, 82783, 549, 51540, 248, 17209, 1301, 217, 20, 215186, 1325, 147, 17209, 1301, 217, 20, 56370, 53, 122020, 20, 16477, 27, 87355, 4548, 20, 4728, 78392, 17, 159969, 18, 26, 24491, 629, 15, 538, 22704, 5439, 15, 2788, 24491, 9885, 15, 43534, 605, 15, 814, 18403, 33200, 29, 15, 43534, 24458, 12410, 111, 24966, 83669, 9637, 144068, 26, 850, 22346, 27, 147, 24966, 83669, 83490, 26, 39113, 735, 27, 689, 656, 2800, 1339, 4600, 53, 122020, 115785, 34, 816, 1339, 46887, 18, 147, 53905, 1951, 42238, 41170, 17732, 834, 436, 15, 27523, 98733, 217, 147, 5542, 4981, 930, 17347, 16, 2], [20091, 629, 94, 82786, 58, 490, 20, 1528, 84, 53905, 344, 80592, 110128, 18822, 5267, 1306, 62, 152537, 308, 7997, 401, 124427, 549, 35442, 225, 109, 15055, 25748, 147, 7119, 43712, 34, 767, 135366, 18, 16, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [592, 63784, 119466, 17, 147808, 88214, 18, 656, 81, 32, 3296, 10280, 16, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
             # fmt: on

             self.tokenizer_integration_test_util(
                 expected_encoding=_UpperCAmelCase	,       model_name="microsoft/xprophetnet-large-wiki100-cased"	,       revision="1acad1643ddd54a44df6a1b797ada8373685d90e"	,       )




