






"""simple docstring"""


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


__SCREAMING_SNAKE_CASE      =      logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE      =      {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE      =      {
    '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'
        ),
    },
}

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




class 	__UpperCamelCase    (    __SCREAMING_SNAKE_CASE	):
					lowercase_						:							Union[str, Any]			=     VOCAB_FILES_NAMES
					lowercase_						:							List[str]			=     PRETRAINED_VOCAB_FILES_MAP
					lowercase_						:							int			=     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					lowercase_						:							Union[str, Any]			=     ["""input_ids""", """attention_mask"""]
					lowercase_						:							Union[str, Any]			=     CLIPTokenizer
					def __init__(       self       :  List[Any]    ,   UpperCAmelCase       :  Dict=None    ,   UpperCAmelCase       :  int=None    ,   UpperCAmelCase       :  Optional[Any]=None    ,   UpperCAmelCase       :  str="<|endoftext|>"    ,   UpperCAmelCase       :  List[str]="<|startoftext|>"    ,   UpperCAmelCase       :  List[Any]="<|endoftext|>"    ,   UpperCAmelCase       :  List[str]="<|endoftext|>"    ,   **UpperCAmelCase       :  Union[str, Any]    ,   )  ->					Optional[Any]:
											super().__init__(
											    UpperCamelCase__    ,   UpperCamelCase__    ,   tokenizer_file=UpperCamelCase__    ,   unk_token=UpperCamelCase__    ,   bos_token=UpperCamelCase__    ,   eos_token=UpperCamelCase__    ,   pad_token=UpperCamelCase__    ,   **UpperCamelCase__    ,   )

											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       :  Dict      )  ->					str:
											lowerCAmelCase      :Tuple				  = self.backend_tokenizer.decode

											def new_decode_method(*UpperCAmelCase       :  Any    ,   **UpperCAmelCase       :  Any      ):
																	lowerCAmelCase      :List[str]				  = orig_decode_method(*UpperCamelCase__    ,   **UpperCamelCase__      )
																	lowerCAmelCase      :List[Any]				  = text.replace(self.backend_tokenizer.model.end_of_word_suffix    ,   ' '      ).strip()
																	return text

											lowerCAmelCase      :Optional[Any]				  = new_decode_method
					def 					UpperCAmelCase__   (       self       :  str    ,   UpperCAmelCase       :  List[int]    ,   UpperCAmelCase       :  Optional[List[int]] = None      )  ->					List[int]:
											lowerCAmelCase      :Tuple				  = [self.bos_token_id]
											lowerCAmelCase      :Any				  = [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       :  Any    ,   UpperCAmelCase       :  List[int]    ,   UpperCAmelCase       :  Optional[List[int]] = None      )  ->					List[int]:
											lowerCAmelCase      :Optional[int]				  = [self.bos_token_id]
											lowerCAmelCase      :Optional[int]				  = [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    ,   UpperCAmelCase       :  str    ,   UpperCAmelCase       :  Optional[str] = None      )  ->					Tuple[str]:
											lowerCAmelCase      :int				  = self._tokenizer.model.save(UpperCamelCase__    ,   name=UpperCamelCase__      )
											return tuple(UpperCamelCase__      )







"""simple docstring"""


import unittest

import torch

from diffusers import DDIMScheduler, TextToVideoZeroPipeline
from diffusers.utils import load_pt, require_torch_gpu, slow

from ..test_pipelines_common import assert_mean_pixel_difference




@slow
@require_torch_gpu
class 	__UpperCamelCase    (    unittest.TestCase	):
					def 					UpperCAmelCase__   (       self       :  Union[str, Any]      )  ->					Optional[Any]:
											lowerCAmelCase      :Union[str, Any]				  = 'runwayml/stable-diffusion-v1-5'
											lowerCAmelCase      :Tuple				  = TextToVideoZeroPipeline.from_pretrained(UpperCAmelCase    ,   torch_dtype=torch.floataa      ).to('cuda'      )
											lowerCAmelCase      :Union[str, Any]				  = DDIMScheduler.from_config(pipe.scheduler.config      )
											lowerCAmelCase      :str				  = torch.Generator(device='cuda'      ).manual_seed(0      )

											lowerCAmelCase      :Any				  = 'A bear is playing a guitar on Times Square'
											lowerCAmelCase      :Optional[Any]				  = pipe(prompt=UpperCAmelCase    ,   generator=UpperCAmelCase      ).images

											lowerCAmelCase      :List[str]				  = load_pt(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text-to-video/A bear is playing a guitar on Times Square.pt'      )

											assert_mean_pixel_difference(UpperCAmelCase    ,   UpperCAmelCase      )