



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


__lowerCamelCase      =    logging.get_logger(__name__)

__lowerCamelCase      =    {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

__lowerCamelCase      =    {
    """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"""
        ),
    },
}

__lowerCamelCase      =    {
    """openai/clip-vit-base-patch32""": 7_7,
}



class 						_snake_case					(	lowerCamelCase ):





 """simple docstring"""



 lowerCamelCase_								=	VOCAB_FILES_NAMES
 lowerCamelCase_								=	PRETRAINED_VOCAB_FILES_MAP
 lowerCamelCase_								=	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 lowerCamelCase_								=	["input_ids", "attention_mask"]
 lowerCamelCase_								=	CLIPTokenizer
 def __init__(  self		,			a=None		,			a=None		,			a=None		,			a="<|endoftext|>"		,			a="<|startoftext|>"		,			a="<|endoftext|>"		,			a="<|endoftext|>"		,			**a		,			)		->							Tuple:




   """simple docstring"""







   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 lowercase_						(  self    )		->							int:




   """simple docstring"""







   _A							=			self.backend_tokenizer.decode

   def new_decode_method(*a		,			**a    ):
     _A							=			orig_decode_method(*UpperCAmelCase_		,			**UpperCAmelCase_    )
     _A							=			text.replace(self.backend_tokenizer.model.end_of_word_suffix		,			''' '''    ).strip()
     return text

   _A							=			new_decode_method
 def lowercase_						(  self		,			a		,			a = None    )		->							Any:




   """simple docstring"""







   _A							=			[self.bos_token_id]
   _A							=			[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 lowercase_						(  self		,			a		,			a = None    )		->							List[str]:




   """simple docstring"""







   _A							=			[self.bos_token_id]
   _A							=			[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 lowercase_						(  self		,			a		,			a = None    )		->							Tuple:




   """simple docstring"""







   _A							=			self._tokenizer.model.save(UpperCAmelCase_		,			name=UpperCAmelCase_    )
   return tuple(UpperCAmelCase_    )




"""simple docstring"""







from typing import TYPE_CHECKING

from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available


UpperCAmelCase:   int       			=							{
    """configuration_utils""": ["""GenerationConfig"""],
    """streamers""": ["""TextIteratorStreamer""", """TextStreamer"""],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase:   List[Any]       			=							[
		    """Constraint""",
		    """ConstraintListState""",
		    """DisjunctiveConstraint""",
		    """PhrasalConstraint""",
		]
		UpperCAmelCase:   Optional[Any]       			=							[
		    """BeamHypotheses""",
		    """BeamScorer""",
		    """BeamSearchScorer""",
		    """ConstrainedBeamSearchScorer""",
		]
		UpperCAmelCase:   Any       			=							[
		    """EpsilonLogitsWarper""",
		    """EtaLogitsWarper""",
		    """ForcedBOSTokenLogitsProcessor""",
		    """ForcedEOSTokenLogitsProcessor""",
		    """HammingDiversityLogitsProcessor""",
		    """InfNanRemoveLogitsProcessor""",
		    """LogitsProcessor""",
		    """LogitsProcessorList""",
		    """LogitsWarper""",
		    """MinLengthLogitsProcessor""",
		    """MinNewTokensLengthLogitsProcessor""",
		    """NoBadWordsLogitsProcessor""",
		    """NoRepeatNGramLogitsProcessor""",
		    """PrefixConstrainedLogitsProcessor""",
		    """RepetitionPenaltyLogitsProcessor""",
		    """SequenceBiasLogitsProcessor""",
		    """EncoderRepetitionPenaltyLogitsProcessor""",
		    """TemperatureLogitsWarper""",
		    """TopKLogitsWarper""",
		    """TopPLogitsWarper""",
		    """TypicalLogitsWarper""",
		    """EncoderNoRepeatNGramLogitsProcessor""",
		    """ExponentialDecayLengthPenalty""",
		    """LogitNormalization""",
		]
		UpperCAmelCase:   str       			=							[
		    """MaxNewTokensCriteria""",
		    """MaxLengthCriteria""",
		    """MaxTimeCriteria""",
		    """StoppingCriteria""",
		    """StoppingCriteriaList""",
		    """validate_stopping_criteria""",
		]
		UpperCAmelCase:   Optional[Any]       			=							[
		    """GenerationMixin""",
		    """top_k_top_p_filtering""",
		    """GreedySearchEncoderDecoderOutput""",
		    """GreedySearchDecoderOnlyOutput""",
		    """SampleEncoderDecoderOutput""",
		    """SampleDecoderOnlyOutput""",
		    """BeamSearchEncoderDecoderOutput""",
		    """BeamSearchDecoderOnlyOutput""",
		    """BeamSampleEncoderDecoderOutput""",
		    """BeamSampleDecoderOnlyOutput""",
		    """ContrastiveSearchEncoderDecoderOutput""",
		    """ContrastiveSearchDecoderOnlyOutput""",
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase:   Any       			=							[
		    """TFForcedBOSTokenLogitsProcessor""",
		    """TFForcedEOSTokenLogitsProcessor""",
		    """TFLogitsProcessor""",
		    """TFLogitsProcessorList""",
		    """TFLogitsWarper""",
		    """TFMinLengthLogitsProcessor""",
		    """TFNoBadWordsLogitsProcessor""",
		    """TFNoRepeatNGramLogitsProcessor""",
		    """TFRepetitionPenaltyLogitsProcessor""",
		    """TFTemperatureLogitsWarper""",
		    """TFTopKLogitsWarper""",
		    """TFTopPLogitsWarper""",
		    """TFForceTokensLogitsProcessor""",
		    """TFSuppressTokensAtBeginLogitsProcessor""",
		    """TFSuppressTokensLogitsProcessor""",
		]
		UpperCAmelCase:   Tuple       			=							[
		    """TFGenerationMixin""",
		    """tf_top_k_top_p_filtering""",
		    """TFGreedySearchDecoderOnlyOutput""",
		    """TFGreedySearchEncoderDecoderOutput""",
		    """TFSampleEncoderDecoderOutput""",
		    """TFSampleDecoderOnlyOutput""",
		    """TFBeamSearchEncoderDecoderOutput""",
		    """TFBeamSearchDecoderOnlyOutput""",
		    """TFBeamSampleEncoderDecoderOutput""",
		    """TFBeamSampleDecoderOnlyOutput""",
		    """TFContrastiveSearchEncoderDecoderOutput""",
		    """TFContrastiveSearchDecoderOnlyOutput""",
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase:   Tuple       			=							[
		    """FlaxForcedBOSTokenLogitsProcessor""",
		    """FlaxForcedEOSTokenLogitsProcessor""",
		    """FlaxLogitsProcessor""",
		    """FlaxLogitsProcessorList""",
		    """FlaxLogitsWarper""",
		    """FlaxMinLengthLogitsProcessor""",
		    """FlaxTemperatureLogitsWarper""",
		    """FlaxTopKLogitsWarper""",
		    """FlaxTopPLogitsWarper""",
		]
		UpperCAmelCase:   int       			=							[
		    """FlaxGenerationMixin""",
		    """FlaxGreedySearchOutput""",
		    """FlaxSampleOutput""",
		    """FlaxBeamSearchOutput""",
		]

if TYPE_CHECKING:
		from .configuration_utils import GenerationConfig
		from .streamers import TextIteratorStreamer, TextStreamer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
				from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
				from .logits_process import (
				    EncoderNoRepeatNGramLogitsProcessor,
				    EncoderRepetitionPenaltyLogitsProcessor,
				    EpsilonLogitsWarper,
				    EtaLogitsWarper,
				    ExponentialDecayLengthPenalty,
				    ForcedBOSTokenLogitsProcessor,
				    ForcedEOSTokenLogitsProcessor,
				    HammingDiversityLogitsProcessor,
				    InfNanRemoveLogitsProcessor,
				    LogitNormalization,
				    LogitsProcessor,
				    LogitsProcessorList,
				    LogitsWarper,
				    MinLengthLogitsProcessor,
				    MinNewTokensLengthLogitsProcessor,
				    NoBadWordsLogitsProcessor,
				    NoRepeatNGramLogitsProcessor,
				    PrefixConstrainedLogitsProcessor,
				    RepetitionPenaltyLogitsProcessor,
				    SequenceBiasLogitsProcessor,
				    TemperatureLogitsWarper,
				    TopKLogitsWarper,
				    TopPLogitsWarper,
				    TypicalLogitsWarper,
				)
				from .stopping_criteria import (
				    MaxLengthCriteria,
				    MaxNewTokensCriteria,
				    MaxTimeCriteria,
				    StoppingCriteria,
				    StoppingCriteriaList,
				    validate_stopping_criteria,
				)
				from .utils import (
				    BeamSampleDecoderOnlyOutput,
				    BeamSampleEncoderDecoderOutput,
				    BeamSearchDecoderOnlyOutput,
				    BeamSearchEncoderDecoderOutput,
				    ContrastiveSearchDecoderOnlyOutput,
				    ContrastiveSearchEncoderDecoderOutput,
				    GenerationMixin,
				    GreedySearchDecoderOnlyOutput,
				    GreedySearchEncoderDecoderOutput,
				    SampleDecoderOnlyOutput,
				    SampleEncoderDecoderOutput,
				    top_k_top_p_filtering,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tf_logits_process import (
				    TFForcedBOSTokenLogitsProcessor,
				    TFForcedEOSTokenLogitsProcessor,
				    TFForceTokensLogitsProcessor,
				    TFLogitsProcessor,
				    TFLogitsProcessorList,
				    TFLogitsWarper,
				    TFMinLengthLogitsProcessor,
				    TFNoBadWordsLogitsProcessor,
				    TFNoRepeatNGramLogitsProcessor,
				    TFRepetitionPenaltyLogitsProcessor,
				    TFSuppressTokensAtBeginLogitsProcessor,
				    TFSuppressTokensLogitsProcessor,
				    TFTemperatureLogitsWarper,
				    TFTopKLogitsWarper,
				    TFTopPLogitsWarper,
				)
				from .tf_utils import (
				    TFBeamSampleDecoderOnlyOutput,
				    TFBeamSampleEncoderDecoderOutput,
				    TFBeamSearchDecoderOnlyOutput,
				    TFBeamSearchEncoderDecoderOutput,
				    TFContrastiveSearchDecoderOnlyOutput,
				    TFContrastiveSearchEncoderDecoderOutput,
				    TFGenerationMixin,
				    TFGreedySearchDecoderOnlyOutput,
				    TFGreedySearchEncoderDecoderOutput,
				    TFSampleDecoderOnlyOutput,
				    TFSampleEncoderDecoderOutput,
				    tf_top_k_top_p_filtering,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .flax_logits_process import (
				    FlaxForcedBOSTokenLogitsProcessor,
				    FlaxForcedEOSTokenLogitsProcessor,
				    FlaxLogitsProcessor,
				    FlaxLogitsProcessorList,
				    FlaxLogitsWarper,
				    FlaxMinLengthLogitsProcessor,
				    FlaxTemperatureLogitsWarper,
				    FlaxTopKLogitsWarper,
				    FlaxTopPLogitsWarper,
				)
				from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
		import sys

		UpperCAmelCase:   Optional[Any]       			=							_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



