


'''simple docstring'''
import argparse
import os
import re

import packaging.version


__snake_case											=					'examples/'
__snake_case											=					{
    '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'),
}
__snake_case											=					{
    'init': 'src/diffusers/__init__.py',
    'setup': 'setup.py',
}
__snake_case											=					'README.md'


def       a				(      __a			, __a			, __a       )  ->     Optional[int]:



					'''simple docstring'''






					with open(_UpperCamelCase			, '''r'''			, encoding='''utf-8'''			, newline='''\n'''       ) as f:
										UpperCamelCase__       :Union[str, Any]							 =			f.read()
					UpperCamelCase__ ,    UpperCamelCase__       :int							 =			REPLACE_PATTERNS[pattern]
					UpperCamelCase__       :Tuple							 =			replace.replace('''VERSION'''			, _UpperCamelCase       )
					UpperCamelCase__       :str							 =			re_pattern.sub(_UpperCamelCase			, _UpperCamelCase       )
					with open(_UpperCamelCase			, '''w'''			, encoding='''utf-8'''			, newline='''\n'''       ) as f:
										f.write(_UpperCamelCase       )


def       a				(      __a       )  ->     str:



					'''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				(      __a			, __a=False       )  ->     List[Any]:



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



					'''simple docstring'''






					UpperCamelCase__       :Any							 =			'''🤗 Transformers currently provides the following architectures'''
					UpperCamelCase__       :Any							 =			'''1. Want to contribute a new model?'''
					with open(_UpperCamelCase			, '''r'''			, encoding='''utf-8'''			, newline='''\n'''       ) as f:
										UpperCamelCase__       :Union[str, Any]							 =			f.readlines()

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

					UpperCamelCase__       :List[str]							 =			start_index
					# Update the lines in the model list.
					while not lines[index].startswith(_end_prompt       ):
										if lines[index].startswith('''1.'''       ):
															UpperCamelCase__       :Optional[int]							 =			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				(      )  ->     str:



					'''simple docstring'''






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


def       a				(      __a=False       )  ->     Tuple:



					'''simple docstring'''






					UpperCamelCase__       :Dict							 =			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:
										UpperCamelCase__       :Any							 =			default_version.base_version
					elif patch:
										UpperCamelCase__       :List[str]							 =			f'''{default_version.major}.{default_version.minor}.{default_version.micro + 1}'''
					else:
										UpperCamelCase__       :Tuple							 =			f'''{default_version.major}.{default_version.minor + 1}.0'''

					# Now let's ask nicely if that's the right one.
					UpperCamelCase__       :Union[str, Any]							 =			input(f'''Which version are you releasing? [{default_version}]'''       )
					if len(_UpperCamelCase       ) == 0:
										UpperCamelCase__       :Union[str, Any]							 =			default_version

					print(f'''Updating version to {version}.'''       )
					global_version_update(_UpperCamelCase			, patch=_UpperCamelCase       )


def       a				(      )  ->     str:



					'''simple docstring'''






					UpperCamelCase__       :Any							 =			get_version()
					UpperCamelCase__       :Any							 =			f'''{current_version.major}.{current_version.minor + 1}.0.dev0'''
					UpperCamelCase__       :List[str]							 =			current_version.base_version

					# Check with the user we got that right.
					UpperCamelCase__       :List[Any]							 =			input(f'''Which version are we developing now? [{dev_version}]'''       )
					if len(_UpperCamelCase       ) == 0:
										UpperCamelCase__       :Any							 =			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__":
		__snake_case											=					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.''')
		__snake_case											=					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 collections
import os
from typing import List, Optional, Tuple

from transformers.utils import is_jieba_available, requires_backends


if is_jieba_available():
		import jieba

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


__snake_case											=					logging.get_logger(__name__)

__snake_case											=					{'''vocab_file''': '''vocab.txt'''}

__snake_case											=					{
    '''vocab_file''': {
        '''openbmb/cpm-ant-10b''': '''https://huggingface.co/openbmb/cpm-ant-10b/blob/main/vocab.txt''',
    },
}

__snake_case											=					{
    '''openbmb/cpm-ant-10b''': 1024,
}


def       a				(      __a       )  ->     Tuple:



					'''simple docstring'''






					UpperCamelCase__       :List[str]							 =			collections.OrderedDict()
					with open(__a			, '''r'''			, encoding='''utf-8'''       ) as reader:
										UpperCamelCase__       :Dict							 =			reader.readlines()
					for index, token in enumerate(__a       ):
										UpperCamelCase__       :str							 =			token.rstrip('''\n'''       )
										UpperCamelCase__       :Optional[int]							 =			index
					return vocab
class        lowercase     (							A__ ):

		"""simple docstring"""

		def __init__(		self   ,       UpperCamelCase_   ,       UpperCamelCase_="<unk>"   ,       UpperCamelCase_=200							):

							'''simple docstring'''


							UpperCamelCase__       :Tuple							 =			vocab
							UpperCamelCase__       :List[str]							 =			unk_token
							UpperCamelCase__       :Tuple							 =			max_input_chars_per_word




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :Optional[int]							 =			list(UpperCamelCase_							)
							if len(UpperCamelCase_							) > self.max_input_chars_per_word:
												return [self.unk_token]

							UpperCamelCase__       :List[Any]							 =			0
							UpperCamelCase__       :str							 =			[]
							while start < len(UpperCamelCase_							):
												UpperCamelCase__       :int							 =			len(UpperCamelCase_							)
												UpperCamelCase__       :List[Any]							 =			None
												while start < end:
																	UpperCamelCase__       :int							 =			''''''.join(chars[start:end]							)
																	if substr in self.vocab:
																						UpperCamelCase__       :List[Any]							 =			substr
																						break
																	end -= 1
												if cur_substr is None:
																	sub_tokens.append(self.unk_token							)
																	start += 1
												else:
																	sub_tokens.append(UpperCamelCase_							)
																	UpperCamelCase__       :Any							 =			end

							return sub_tokens



class        lowercase     (							A__ ):

		"""simple docstring"""

		_a   			=    VOCAB_FILES_NAMES
		_a   			=    PRETRAINED_VOCAB_FILES_MAP
		_a   			=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		_a   			=    ['input_ids', 'attention_mask']
		_a   			=    False




		def __init__(		self   ,       UpperCamelCase_   ,       UpperCamelCase_="<d>"   ,       UpperCamelCase_="</d>"   ,       UpperCamelCase_="<s>"   ,       UpperCamelCase_="</s>"   ,       UpperCamelCase_="<pad>"   ,       UpperCamelCase_="<unk>"   ,       UpperCamelCase_="</n>"   ,       UpperCamelCase_="</_>"   ,       UpperCamelCase_="left"   ,       **UpperCamelCase_   ,       ):

							'''simple docstring'''


							requires_backends(self   ,       ['''jieba''']							)
							super().__init__(
							    bod_token=UpperCamelCase_   ,       eod_token=UpperCamelCase_   ,       bos_token=UpperCamelCase_   ,       eos_token=UpperCamelCase_   ,       pad_token=UpperCamelCase_   ,       unk_token=UpperCamelCase_   ,       line_token=UpperCamelCase_   ,       space_token=UpperCamelCase_   ,       padding_side=UpperCamelCase_   ,       **UpperCamelCase_   ,       )
							UpperCamelCase__       :Tuple							 =			bod_token
							UpperCamelCase__       :Dict							 =			eod_token
							UpperCamelCase__       :Optional[int]							 =			load_vocab(UpperCamelCase_							)
							UpperCamelCase__       :Tuple							 =			self.encoder[space_token]
							UpperCamelCase__       :List[Any]							 =			self.encoder[line_token]

							del self.encoder[space_token]
							del self.encoder[line_token]

							UpperCamelCase__       :Union[str, Any]							 =			collections.OrderedDict(sorted(self.encoder.items()   ,       key=lambda UpperCamelCase_							: x[1]							)							)
							UpperCamelCase__       :Union[str, Any]							 =			{v: k for k, v in self.encoder.items()}

							UpperCamelCase__       :List[Any]							 =			WordpieceTokenizer(vocab=self.encoder   ,       unk_token=self.unk_token							)




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return self.encoder[self.bod_token]




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return self.encoder[self.eod_token]




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return self.encoder["\n"]




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return len(self.encoder							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return dict(self.encoder   ,       **self.added_tokens_encoder							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :List[Any]							 =			[]
							for x in jieba.cut(UpperCamelCase_   ,       cut_all=UpperCamelCase_							):
												output_tokens.extend(self.wordpiece_tokenizer.tokenize(UpperCamelCase_							)							)
							return output_tokens




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       **UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :List[Any]							 =			[i for i in token_ids if i >= 0]
							UpperCamelCase__       :Optional[int]							 =			[
							    x for x in token_ids if x != self.pad_token_id and x != self.eos_token_id and x != self.bos_token_id
							]
							return super()._decode(UpperCamelCase_   ,       **UpperCamelCase_							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							return token in self.encoder




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							return "".join(UpperCamelCase_							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							return self.encoder.get(UpperCamelCase_   ,       self.encoder.get(self.unk_token							)							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_							):

							'''simple docstring'''


							return self.decoder.get(UpperCamelCase_   ,       self.unk_token							)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = None							):

							'''simple docstring'''


							if os.path.isdir(UpperCamelCase_							):
												UpperCamelCase__       :int							 =			os.path.join(
												    UpperCamelCase_   ,       (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']							)
							else:
												UpperCamelCase__       :str							 =			(filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
							UpperCamelCase__       :Any							 =			0
							if " " in self.encoder:
												UpperCamelCase__       :Dict							 =			self.encoder[''' ''']
												del self.encoder[" "]
							if "\n" in self.encoder:
												UpperCamelCase__       :List[str]							 =			self.encoder['''\n''']
												del self.encoder["\n"]
							UpperCamelCase__       :List[str]							 =			collections.OrderedDict(sorted(self.encoder.items()   ,       key=lambda UpperCamelCase_							: x[1]							)							)
							with open(UpperCamelCase_   ,       '''w'''   ,       encoding='''utf-8'''							) as writer:
												for token, token_index in self.encoder.items():
																	if index != token_index:
																						logger.warning(
																						    F'''Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive.'''
																						    ''' Please check that the vocabulary is not corrupted!'''							)
																						UpperCamelCase__       :Any							 =			token_index
																	writer.write(token + '''\n'''							)
																	index += 1
							return (vocab_file,)




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = None							):

							'''simple docstring'''


							if token_ids_a is None:
												return [self.bos_token_id] + token_ids_a
							return [self.bos_token_id] + token_ids_a + [self.bos_token_id] + token_ids_a




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = None   ,       UpperCamelCase_ = False							):

							'''simple docstring'''


							if already_has_special_tokens:
												return super().get_special_tokens_mask(
												    token_ids_a=UpperCamelCase_   ,       token_ids_a=UpperCamelCase_   ,       already_has_special_tokens=UpperCamelCase_							)

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