code: 
  
  
  '''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
  
  
  lowerCamelCase							:     Dict								=			logging.get_logger(__name__)
  
  lowerCamelCase							:     Tuple								=			{'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}
  
  lowerCamelCase							:     str								=			{
      '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							:     Optional[int]								=			{
      'openai/clip-vit-base-patch32': 77,
  }
  class 						__lowerCAmelCase		(lowercase_  ):
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        lowerCAmelCase__      :  str						      =							VOCAB_FILES_NAMES
        lowerCAmelCase__      :  List[Any]						      =							PRETRAINED_VOCAB_FILES_MAP
        lowerCAmelCase__      :  Optional[int]						      =							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
        lowerCAmelCase__      :  Dict						      =							["""input_ids""", """attention_mask"""]
        lowerCAmelCase__      :  int						      =							CLIPTokenizer
  
  
  
        def __init__(self					:					Any     ,		UpperCamelCase					:					Dict=None     ,		UpperCamelCase					:					List[str]=None     ,		UpperCamelCase					:					str=None     ,		UpperCamelCase					:					Any="<|endoftext|>"     ,		UpperCamelCase					:					int="<|startoftext|>"     ,		UpperCamelCase					:					Dict="<|endoftext|>"     ,		UpperCamelCase					:					Any="<|endoftext|>"     ,		**UpperCamelCase					:					List[str]     ,		):
  
               '''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    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.backend_tokenizer.decode
  
               def new_decode_method(*UpperCamelCase					:					Optional[int]     ,		**UpperCamelCase					:					List[Any]				):
                      lowercase__       =				orig_decode_method(*UpperCamelCase     ,		**UpperCamelCase				)
                      lowercase__       =				text.replace(self.backend_tokenizer.model.end_of_word_suffix     ,		''' '''				).strip()
                      return text
  
               lowercase__       =				new_decode_method
  
  
  
        def    UpperCamelCase__	(self					:					Union[str, Any]     ,		UpperCamelCase					:					List[int]     ,		UpperCamelCase					:					Optional[List[int]] = None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				[self.bos_token_id]
               lowercase__       =				[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					:					Dict     ,		UpperCamelCase					:					List[int]     ,		UpperCamelCase					:					Optional[List[int]] = None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				[self.bos_token_id]
               lowercase__       =				[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					:					int     ,		UpperCamelCase					:					str     ,		UpperCamelCase					:					Optional[str] = None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self._tokenizer.model.save(UpperCamelCase     ,		name=UpperCamelCase				)
               return tuple(UpperCamelCase				)
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  import torch
  
  from accelerate import Accelerator, DistributedType
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __enter__(self					:					List[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.enabled:
                      lowercase__       =				self.model.no_sync()
                      self.model_sync_obj.__enter__()
  
               return self
  
  
  
        def __exit__(self					:					List[str]     ,		UpperCamelCase					:					List[Any]     ,		UpperCamelCase					:					Optional[int]     ,		UpperCamelCase					:					Optional[int]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.enabled:
                      # Average all models on exit
                      self._sync_and_avg_model_params()
                      self.model_sync_obj.__exit__(UpperCamelCase     ,		UpperCamelCase     ,		UpperCamelCase				)
  
  
  
        def __init__(self					:					Dict     ,		UpperCamelCase					:					Accelerator     ,		UpperCamelCase					:					torch.nn.Module     ,		UpperCamelCase					:					int     ,		UpperCamelCase					:					bool = True				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if accelerator.distributed_type not in [
                   DistributedType.NO,
                   DistributedType.MULTI_CPU,
                   DistributedType.MULTI_GPU,
               ]:
                      raise NotImplementedError('''LocalSGD is supported only for CPUs and GPUs (no DeepSpeed or MegatronLM)'''				)
               lowercase__       =				enabled and accelerator.distributed_type != DistributedType.NO
               lowercase__       =				0
               if self.enabled:
                      lowercase__       =				accelerator
                      lowercase__       =				model
                      lowercase__       =				local_sgd_steps
  
  
  
        def    UpperCamelCase__	(self					:					List[str]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               self.num_steps += 1
               if not self.enabled:
                      return
  
               if self.num_steps % self.local_sgd_steps == 0:
                      self._sync_and_avg_model_params()
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					Any				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               self.accelerator.wait_for_everyone()
               with self.accelerator.autocast():
                      for param in self.model.parameters():
                             lowercase__       =				self.accelerator.reduce(param.data     ,		reduction='''mean'''				)
  
  
  
  
  