




'''simple docstring'''




# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path

from .config_args import default_config_file, load_config_from_file
from .config_utils import SubcommandHelpFormatter


a_   :	str							   = """Update an existing config file with the latest defaults while maintaining the old configuration."""





def   a_							(   __snake_case							:    Optional[Any]     )							->		Union[str, Any]:



       """simple docstring"""
       lowerCamelCase_							=args.config_file
       if config_file is None and Path(__snake_case     ).exists():
              lowerCamelCase_							=default_config_file
       elif not Path(__snake_case     ).exists():
              raise ValueError(F'''The passed config file located at {config_file} doesn\'t exist.'''     )
       lowerCamelCase_							=load_config_from_file(__snake_case     )

       if config_file.endswith('''.json'''     ):
              config.to_json_file(__snake_case     )
       else:
              config.to_yaml_file(__snake_case     )
       return config_file





def   a_							(   __snake_case							:    Dict     , __snake_case							:    Optional[Any]     )							->		Optional[Any]:



       """simple docstring"""
       lowerCamelCase_							=parser.add_parser('''update'''     , parents=__snake_case     , help=__snake_case     , formatter_class=__snake_case     )
       parser.add_argument(
           '''--config_file'''     , default=__snake_case     , help=(
               '''The path to the config file to update. Will default to a file named default_config.yaml in the cache '''
               '''location, which is the content of the environment `HF_HOME` suffixed with \'accelerate\', or if you don\'t have '''
               '''such an environment variable, your cache directory (\'~/.cache\' or the content of `XDG_CACHE_HOME`) suffixed '''
               '''with \'huggingface\'.'''
           )     , )

       parser.set_defaults(func=__snake_case     )
       return parser





def   a_							(   __snake_case							:    List[str]     )							->		Tuple:



       """simple docstring"""
       lowerCamelCase_							=update_config(__snake_case     )
       print(F'''Sucessfully updated the configuration file at {config_file}.'''     )










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


a_   :	Tuple							   = logging.get_logger(__name__)

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

a_   :	Tuple							   = {
    """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_   :	str							   = {
    """openai/clip-vit-base-patch32""": 77,
}


class 						__UpperCamelCase (				lowerCamelCase__       ):
       lowercase			:					Union[str, Any]   		=VOCAB_FILES_NAMES
       lowercase			:					Optional[int]   		=PRETRAINED_VOCAB_FILES_MAP
       lowercase			:					Any   		=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       lowercase			:					str   		=['input_ids', 'attention_mask']
       lowercase			:					List[Any]   		=CLIPTokenizer






       def __init__(							self,	lowerCAmelCase=None,	lowerCAmelCase=None,	lowerCAmelCase=None,	lowerCAmelCase="<|endoftext|>",	lowerCAmelCase="<|startoftext|>",	lowerCAmelCase="<|endoftext|>",	lowerCAmelCase="<|endoftext|>",	**lowerCAmelCase,	):



              """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   lowercase__  (							self						):



              """simple docstring"""







              lowerCamelCase_							=self.backend_tokenizer.decode

              def new_decode_method(*lowerCAmelCase,	**lowerCAmelCase						):
                     lowerCamelCase_							=orig_decode_method(*lowerCAmelCase,	**lowerCAmelCase						)
                     lowerCamelCase_							=text.replace(self.backend_tokenizer.model.end_of_word_suffix,	''' '''						).strip()
                     return text

              lowerCamelCase_							=new_decode_method






       def   lowercase__  (							self,	lowerCAmelCase,	lowerCAmelCase = None						):



              """simple docstring"""







              lowerCamelCase_							=[self.bos_token_id]
              lowerCamelCase_							=[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,	lowerCAmelCase,	lowerCAmelCase = None						):



              """simple docstring"""







              lowerCamelCase_							=[self.bos_token_id]
              lowerCamelCase_							=[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,	lowerCAmelCase,	lowerCAmelCase = None						):



              """simple docstring"""







              lowerCamelCase_							=self._tokenizer.model.save(lowerCAmelCase,	name=lowerCAmelCase						)
              return tuple(lowerCAmelCase						)




