





from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_clip import CLIPTokenizer


A__:  Optional[Any]       					=					logging.get_logger(__name__)

A__:  Optional[int]       					=					{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

A__:  List[Any]       					=					{
    '''vocab_file''': {
        '''openai/clip-vit-base-patch32''': '''https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''openai/clip-vit-base-patch32''': '''https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''openai/clip-vit-base-patch32''': (
            '''https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/tokenizer.json'''
        ),
    },
}

A__:  int       					=					{
    '''openai/clip-vit-base-patch32''': 77,
}




class    _a  (  UpperCamelCase__):

      """simple docstring"""


      UpperCamelCase__       						=   VOCAB_FILES_NAMES
      UpperCamelCase__       						=   PRETRAINED_VOCAB_FILES_MAP
      UpperCamelCase__       						=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      UpperCamelCase__       						=   ["""input_ids""", """attention_mask"""]
      UpperCamelCase__       						=   CLIPTokenizer






      def __init__(						self:	int					,  __lowerCamelCase:	str=None					,  __lowerCamelCase:	Dict=None					,  __lowerCamelCase:	Union[str, Any]=None					,  __lowerCamelCase:	Any="<|endoftext|>"					,  __lowerCamelCase:	List[str]="<|startoftext|>"					,  __lowerCamelCase:	List[Any]="<|endoftext|>"					,  __lowerCamelCase:	Dict="<|endoftext|>"					,  **__lowerCamelCase:	Tuple					,  ):
          '''simple docstring'''


          super().__init__(
              __lowerCamelCase					,  __lowerCamelCase					,  tokenizer_file=__lowerCamelCase					,  unk_token=__lowerCamelCase					,  bos_token=__lowerCamelCase					,  eos_token=__lowerCamelCase					,  pad_token=__lowerCamelCase					,  **__lowerCamelCase					,  )

          if not isinstance(self.backend_tokenizer.pre_tokenizer					,  pre_tokenizers.Sequence			):
              raise ValueError(
                  "The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been"
                  " heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using"
                  " to be compatible with this version.The easiest way to do so is"
                  " `CLIPTokenizerFast.from_pretrained(\"path_to_local_folder_or_hub_repo, from_slow=True)`. If you want"
                  " to use your existing tokenizer, you will have to revert to a version prior to 4.17.0 of"
                  " transformers."			)

          self._wrap_decode_method_backend_tokenizer()






      def 	UpperCAmelCase_   (						self:	int			):
          '''simple docstring'''


          UpperCamelCase__:					Optional[int]												=      self.backend_tokenizer.decode

          def new_decode_method(*__lowerCamelCase:	Tuple					,  **__lowerCamelCase:	int			):
              UpperCamelCase__:					List[str]												=      orig_decode_method(*__lowerCamelCase					,  **__lowerCamelCase			)
              UpperCamelCase__:					List[Any]												=      text.replace(self.backend_tokenizer.model.end_of_word_suffix					,  " "			).strip()
              return text

          UpperCamelCase__:					Tuple												=      new_decode_method






      def 	UpperCAmelCase_   (						self:	Union[str, Any]					,  __lowerCamelCase:	List[int]					,  __lowerCamelCase:	Optional[List[int]] = None			):
          '''simple docstring'''


          UpperCamelCase__:					Union[str, Any]												=      [self.bos_token_id]
          UpperCamelCase__:					Optional[int]												=      [self.eos_token_id]

          if token_ids_a is None:
              return bos_token + token_ids_a + eos_token
          return bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token






      def 	UpperCAmelCase_   (						self:	str					,  __lowerCamelCase:	List[int]					,  __lowerCamelCase:	Optional[List[int]] = None			):
          '''simple docstring'''


          UpperCamelCase__:					Optional[Any]												=      [self.bos_token_id]
          UpperCamelCase__:					Dict												=      [self.eos_token_id]

          if token_ids_a is None:
              return len(bos_token + token_ids_a + eos_token			) * [0]
          return len(bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token			) * [0]






      def 	UpperCAmelCase_   (						self:	str					,  __lowerCamelCase:	str					,  __lowerCamelCase:	Optional[str] = None			):
          '''simple docstring'''


          UpperCamelCase__:					Tuple												=      self._tokenizer.model.save(__lowerCamelCase					,  name=__lowerCamelCase			)
          return tuple(__lowerCamelCase			)








import inspect

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
   import jax




@require_flax
class    _a  :

      """simple docstring"""


      def 	UpperCAmelCase_   (						self:	int			):
          '''simple docstring'''


          UpperCamelCase__							,				UpperCamelCase__:					Optional[int]												=      self.prepare_init_args_and_inputs_for_common()

          UpperCamelCase__:					Tuple												=      self.model_class(**__lowerCamelCase			)
          UpperCamelCase__:					Union[str, Any]												=      model.init(inputs_dict["prng_key"]					,  inputs_dict["sample"]			)
          jax.lax.stop_gradient(__lowerCamelCase			)

          UpperCamelCase__:					int												=      model.apply(__lowerCamelCase					,  inputs_dict["sample"]			)

          if isinstance(__lowerCamelCase					,  __lowerCamelCase			):
              UpperCamelCase__:					str												=      output.sample

          self.assertIsNotNone(__lowerCamelCase			)
          UpperCamelCase__:					Union[str, Any]												=      inputs_dict["sample"].shape
          self.assertEqual(output.shape					,  __lowerCamelCase					,  "Input and output shapes do not match"			)






      def 	UpperCAmelCase_   (						self:	Union[str, Any]			):
          '''simple docstring'''


          UpperCamelCase__							,				UpperCamelCase__:					List[str]												=      self.prepare_init_args_and_inputs_for_common()

          UpperCamelCase__:					List[Any]												=      16
          UpperCamelCase__:					int												=      (16, 32)

          UpperCamelCase__:					Tuple												=      self.model_class(**__lowerCamelCase			)
          UpperCamelCase__:					Union[str, Any]												=      model.init(inputs_dict["prng_key"]					,  inputs_dict["sample"]			)
          jax.lax.stop_gradient(__lowerCamelCase			)

          UpperCamelCase__:					Union[str, Any]												=      model.apply(__lowerCamelCase					,  inputs_dict["sample"]			)

          if isinstance(__lowerCamelCase					,  __lowerCamelCase			):
              UpperCamelCase__:					Dict												=      output.sample

          self.assertIsNotNone(__lowerCamelCase			)
          UpperCamelCase__:					Optional[Any]												=      inputs_dict["sample"].shape
          self.assertEqual(output.shape					,  __lowerCamelCase					,  "Input and output shapes do not match"			)






      def 	UpperCAmelCase_   (						self:	Tuple			):
          '''simple docstring'''


          UpperCamelCase__:					List[str]												=      "kwargs" in inspect.signature(self.model_class.__init__			).parameters
          UpperCamelCase__:					Any												=      len(self.model_class._deprecated_kwargs			) > 0

          if has_kwarg_in_model_class and not has_deprecated_kwarg:
              raise ValueError(
                  F"{self.model_class} has `**kwargs` in its __init__ method but has not defined any deprecated kwargs"
                  " under the `_deprecated_kwargs` class attribute. Make sure to either remove `**kwargs` if there are"
                  " no deprecated arguments or add the deprecated argument with `_deprecated_kwargs ="
                  " [<deprecated_argument>]`"			)

          if not has_kwarg_in_model_class and has_deprecated_kwarg:
              raise ValueError(
                  F"{self.model_class} doesn't have `**kwargs` in its __init__ method but has defined deprecated kwargs"
                  " under the `_deprecated_kwargs` class attribute. Make sure to either add the `**kwargs` argument to"
                  F" {self.model_class}.__init__ if there are deprecated arguments or remove the deprecated argument"
                  " from `_deprecated_kwargs = [<deprecated_argument>]`"			)

