




'''simple docstring'''





import argparse
import os
import re

import packaging.version


UpperCamelCase_						:      List[str]       =						'''examples/'''
UpperCamelCase_						:      Any       =						{
    '''examples''': (re.compile(R'''^check_min_version\("[^"]+"\)\s*$''', re.MULTILINE), '''check_min_version("VERSION")\n'''),
    '''init''': (re.compile(R'''^__version__\s+=\s+"([^"]+)"\s*$''', re.MULTILINE), '''__version__ = "VERSION"\n'''),
    '''setup''': (re.compile(R'''^(\s*)version\s*=\s*"[^"]+",''', re.MULTILINE), R'''\1version="VERSION",'''),
    '''doc''': (re.compile(R'''^(\s*)release\s*=\s*"[^"]+"$''', re.MULTILINE), '''release = "VERSION"\n'''),
}
UpperCamelCase_						:      Optional[Any]       =						{
    '''init''': '''src/diffusers/__init__.py''',
    '''setup''': '''setup.py''',
}
UpperCamelCase_						:      int       =						'''README.md'''





def      __a     (       _UpperCamelCase:   Union[str, Any] ,						_UpperCamelCase:   Optional[Any] ,						_UpperCamelCase:   Any   )						->			List[Any]:

     """simple docstring"""




     with open(_UpperCamelCase ,						"r" ,						encoding="utf-8" ,						newline="\n"   ) as f:
          _snake_case							=				f.read()
     _snake_case							, _snake_case							=				REPLACE_PATTERNS[pattern]
     _snake_case							=				replace.replace("VERSION" ,						_UpperCamelCase   )
     _snake_case							=				re_pattern.sub(_UpperCamelCase ,						_UpperCamelCase   )
     with open(_UpperCamelCase ,						"w" ,						encoding="utf-8" ,						newline="\n"   ) as f:
          f.write(_UpperCamelCase   )





def      __a     (       _UpperCamelCase:   Optional[Any]   )						->			Any:

     """simple docstring"""




     for folder, directories, fnames in os.walk(_UpperCamelCase   ):
          # Removing some of the folders with non-actively maintained examples from the walk
          if "research_projects" in directories:
               directories.remove("research_projects"   )
          if "legacy" in directories:
               directories.remove("legacy"   )
          for fname in fnames:
               if fname.endswith(".py"   ):
                    update_version_in_file(os.path.join(_UpperCamelCase ,						_UpperCamelCase   ) ,						_UpperCamelCase ,						pattern="examples"   )





def      __a     (       _UpperCamelCase:   str ,						_UpperCamelCase:   List[str]=False   )						->			Tuple:

     """simple docstring"""




     for pattern, fname in REPLACE_FILES.items():
          update_version_in_file(_UpperCamelCase ,						_UpperCamelCase ,						_UpperCamelCase   )
     if not patch:
          update_version_in_examples(_UpperCamelCase   )





def      __a     (       )						->			str:

     """simple docstring"""




     _snake_case							=				"🤗 Transformers currently provides the following architectures"
     _snake_case							=				"1. Want to contribute a new model?"
     with open(_UpperCamelCase ,						"r" ,						encoding="utf-8" ,						newline="\n"   ) as f:
          _snake_case							=				f.readlines()

     # Find the start of the list.
     _snake_case							=				0
     while not lines[start_index].startswith(_start_prompt   ):
          start_index += 1
     start_index += 1

     _snake_case							=				start_index
     # Update the lines in the model list.
     while not lines[index].startswith(_end_prompt   ):
          if lines[index].startswith("1."   ):
               _snake_case							=				lines[index].replace(
                   "https://huggingface.co/docs/diffusers/main/model_doc" ,						"https://huggingface.co/docs/diffusers/model_doc" ,						)
          index += 1

     with open(_UpperCamelCase ,						"w" ,						encoding="utf-8" ,						newline="\n"   ) as f:
          f.writelines(_UpperCamelCase   )





def      __a     (       )						->			Optional[int]:

     """simple docstring"""




     with open(REPLACE_FILES["init"] ,						"r"   ) as f:
          _snake_case							=				f.read()
     _snake_case							=				REPLACE_PATTERNS["init"][0].search(_UpperCamelCase   ).groups()[0]
     return packaging.version.parse(_UpperCamelCase   )





def      __a     (       _UpperCamelCase:   Dict=False   )						->			List[Any]:

     """simple docstring"""




     _snake_case							=				get_version()
     if patch and default_version.is_devrelease:
          raise ValueError("Can't create a patch version from the dev branch, checkout a released version!"   )
     if default_version.is_devrelease:
          _snake_case							=				default_version.base_version
     elif patch:
          _snake_case							=				F"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
     else:
          _snake_case							=				F"""{default_version.major}.{default_version.minor + 1}.0"""

     # Now let's ask nicely if that's the right one.
     _snake_case							=				input(F"""Which version are you releasing? [{default_version}]"""   )
     if len(_UpperCamelCase   ) == 0:
          _snake_case							=				default_version

     print(F"""Updating version to {version}."""   )
     global_version_update(_UpperCamelCase ,						patch=_UpperCamelCase   )





def      __a     (       )						->			Any:

     """simple docstring"""




     _snake_case							=				get_version()
     _snake_case							=				F"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
     _snake_case							=				current_version.base_version

     # Check with the user we got that right.
     _snake_case							=				input(F"""Which version are we developing now? [{dev_version}]"""   )
     if len(_UpperCamelCase   ) == 0:
          _snake_case							=				dev_version

     print(F"""Updating version to {version}."""   )
     global_version_update(_UpperCamelCase   )


#    print("Cleaning main README, don't forget to run `make fix-copies`.")
#    clean_main_ref_in_model_list()


if __name__ == "__main__":
   UpperCamelCase_						:      int       =						argparse.ArgumentParser()
   parser.add_argument('''--post_release''', action='''store_true''', help='''Whether this is pre or post release.''')
   parser.add_argument('''--patch''', action='''store_true''', help='''Whether or not this is a patch release.''')
   UpperCamelCase_						:      List[str]       =						parser.parse_args()
   if not args.post_release:
      pre_release_work(patch=args.patch)
   elif args.patch:
      print('''Nothing to do after a patch :-)''')
   else:
      post_release_work()








'''simple docstring'''





import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
   from .tokenization_big_bird import BigBirdTokenizer
else:
   UpperCamelCase_						:      List[Any]       =						None

UpperCamelCase_						:      Tuple       =						logging.get_logger(__name__)
UpperCamelCase_						:      Any       =						{'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

UpperCamelCase_						:      Any       =						{
    '''vocab_file''': {
        '''google/bigbird-roberta-base''': '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model''',
        '''google/bigbird-roberta-large''': (
            '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model'''
        ),
        '''google/bigbird-base-trivia-itc''': (
            '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model'''
        ),
    },
    '''tokenizer_file''': {
        '''google/bigbird-roberta-base''': (
            '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/tokenizer.json'''
        ),
        '''google/bigbird-roberta-large''': (
            '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/tokenizer.json'''
        ),
        '''google/bigbird-base-trivia-itc''': (
            '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/tokenizer.json'''
        ),
    },
}

UpperCamelCase_						:      Optional[int]       =						{
    '''google/bigbird-roberta-base''': 4096,
    '''google/bigbird-roberta-large''': 4096,
    '''google/bigbird-base-trivia-itc''': 4096,
}


UpperCamelCase_						:      List[str]       =						'''▁'''

class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   List[Any]       =						VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE_							:   List[Any]       =						PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE_							:   Any       =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE_							:   str       =						BigBirdTokenizer
     SCREAMING_SNAKE_CASE_							:   Tuple       =						["""input_ids""", """attention_mask"""]
     SCREAMING_SNAKE_CASE_							:   List[int]       =						[]






     def __init__(			self ,_SCREAMING_SNAKE_CASE=None ,_SCREAMING_SNAKE_CASE=None ,_SCREAMING_SNAKE_CASE="<unk>" ,_SCREAMING_SNAKE_CASE="<s>" ,_SCREAMING_SNAKE_CASE="</s>" ,_SCREAMING_SNAKE_CASE="<pad>" ,_SCREAMING_SNAKE_CASE="[SEP]" ,_SCREAMING_SNAKE_CASE="[MASK]" ,_SCREAMING_SNAKE_CASE="[CLS]" ,**_SCREAMING_SNAKE_CASE ,)							->      Dict:
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else bos_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else eos_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else unk_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else pad_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else cls_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else sep_token

          # Mask token behave like a normal word, i.e. include the space before it
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else mask_token

          super().__init__(
              _SCREAMING_SNAKE_CASE ,tokenizer_file=_SCREAMING_SNAKE_CASE ,bos_token=_SCREAMING_SNAKE_CASE ,eos_token=_SCREAMING_SNAKE_CASE ,unk_token=_SCREAMING_SNAKE_CASE ,sep_token=_SCREAMING_SNAKE_CASE ,pad_token=_SCREAMING_SNAKE_CASE ,cls_token=_SCREAMING_SNAKE_CASE ,mask_token=_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE ,)

          _snake_case							=				vocab_file
          _snake_case							=				False if not self.vocab_file else True






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None   )							->      List[int]:
          _snake_case							=				[self.sep_token_id]
          _snake_case							=				[self.cls_token_id]
          if token_ids_a is None:
               return cls + token_ids_a + sep
          return cls + token_ids_a + sep + token_ids_a + sep






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = False   )							->      List[int]:

          if already_has_special_tokens:
               if token_ids_a is not None:
                    raise ValueError(
                        "You should not supply a second sequence if the provided sequence of "
                        "ids is already formatted with special tokens for the model."   )
               return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

          if token_ids_a is None:
               return [1] + ([0] * len(_SCREAMING_SNAKE_CASE   )) + [1]
          return [1] + ([0] * len(_SCREAMING_SNAKE_CASE   )) + [1] + ([0] * len(_SCREAMING_SNAKE_CASE   )) + [1]






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None   )							->      List[int]:
          _snake_case							=				[self.sep_token_id]
          _snake_case							=				[self.cls_token_id]

          if token_ids_a is None:
               return len(cls + token_ids_a + sep   ) * [0]
          return len(cls + token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None   )							->      Tuple[str]:
          if not self.can_save_slow_tokenizer:
               raise ValueError(
                   "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
                   "tokenizer."   )

          if not os.path.isdir(_SCREAMING_SNAKE_CASE   ):
               logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""   )
               return
          _snake_case							=				os.path.join(
              _SCREAMING_SNAKE_CASE ,(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]   )

          if os.path.abspath(self.vocab_file   ) != os.path.abspath(_SCREAMING_SNAKE_CASE   ):
               copyfile(self.vocab_file ,_SCREAMING_SNAKE_CASE   )

          return (out_vocab_file,)


