



"""simple docstring"""






import importlib
import inspect
import json
import os
import re
import shutil
import sys
from pathlib import Path
from typing import Dict, Optional, Union
from urllib import request

from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
from packaging import version

from .. import __version__
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging


lowerCAmelCase__              =							(
    '''https://raw.githubusercontent.com/huggingface/diffusers/{revision}/examples/community/{pipeline}.py'''
)


lowerCAmelCase__              =							logging.get_logger(__name__)  # pylint: disable=invalid-name






def 			snake_case_    ( ):


       '''simple docstring'''





       _lowerCamelCase		:							Optional[int]            =					"https://pypi.org/pypi/diffusers/json"
       _lowerCamelCase		:							Tuple            =					json.loads(request.urlopen(lowerCamelCase_		).read()		)["releases"].keys()
       return sorted(lowerCamelCase_,							key=lambda A_		: version.Version(lowerCamelCase_		)		)






def 			snake_case_    ( ):


       '''simple docstring'''





       if HF_MODULES_CACHE in sys.path:
              return

       sys.path.append(lowerCamelCase_		)
       os.makedirs(lowerCamelCase_,							exist_ok=lowerCamelCase_		)
       _lowerCamelCase		:							str            =					Path(lowerCamelCase_		) / "__init__.py"
       if not init_path.exists():
              init_path.touch()






def 			snake_case_    ( A_   :						Union[str, os.PathLike]		):


       '''simple docstring'''





       init_hf_modules()
       _lowerCamelCase		:							Union[str, Any]            =					Path(lowerCamelCase_		) / name
       # If the parent module does not exist yet, recursively create it.
       if not dynamic_module_path.parent.exists():
              create_dynamic_module(dynamic_module_path.parent		)
       os.makedirs(lowerCamelCase_,							exist_ok=lowerCamelCase_		)
       _lowerCamelCase		:							Tuple            =					dynamic_module_path / "__init__.py"
       if not init_path.exists():
              init_path.touch()






def 			snake_case_    ( A_   :						Tuple		):


       '''simple docstring'''





       with open(lowerCamelCase_,							'''r''',							encoding='''utf-8'''		) as f:
              _lowerCamelCase		:							Dict            =					f.read()

       # Imports of the form `import .xxx`
       _lowerCamelCase		:							Tuple            =					re.findall('''^\s*import\s+\.(\S+)\s*$''',							lowerCamelCase_,							flags=re.MULTILINE		)
       # Imports of the form `from .xxx import yyy`
       relative_imports += re.findall('''^\s*from\s+\.(\S+)\s+import''',							lowerCamelCase_,							flags=re.MULTILINE		)
       # Unique-ify
       return list(set(lowerCamelCase_		)		)






def 			snake_case_    ( A_   :						List[Any]		):


       '''simple docstring'''





       _lowerCamelCase		:							str            =					False
       _lowerCamelCase		:							Dict            =					[module_file]
       _lowerCamelCase		:							List[Any]            =					[]

       # Let's recurse through all relative imports
       while not no_change:
              _lowerCamelCase		:							Optional[int]            =					[]
              for f in files_to_check:
                     new_imports.extend(get_relative_imports(lowerCamelCase_		)		)

              _lowerCamelCase		:							Tuple            =					Path(lowerCamelCase_		).parent
              _lowerCamelCase		:							Optional[int]            =					[str(module_path / m		) for m in new_imports]
              _lowerCamelCase		:							List[Any]            =					[f for f in new_import_files if f not in all_relative_imports]
              _lowerCamelCase		:							Any            =					[F'''{f}.py''' for f in new_import_files]

              _lowerCamelCase		:							Union[str, Any]            =					len(lowerCamelCase_		) == 0
              all_relative_imports.extend(lowerCamelCase_		)

       return all_relative_imports






def 			snake_case_    ( A_   :						Optional[int]		):


       '''simple docstring'''





       with open(lowerCamelCase_,							'''r''',							encoding='''utf-8'''		) as f:
              _lowerCamelCase		:							Dict            =					f.read()

       # Imports of the form `import xxx`
       _lowerCamelCase		:							int            =					re.findall('''^\s*import\s+(\S+)\s*$''',							lowerCamelCase_,							flags=re.MULTILINE		)
       # Imports of the form `from xxx import yyy`
       imports += re.findall('''^\s*from\s+(\S+)\s+import''',							lowerCamelCase_,							flags=re.MULTILINE		)
       # Only keep the top-level module
       _lowerCamelCase		:							List[str]            =					[imp.split('''.'''		)[0] for imp in imports if not imp.startswith('''.'''		)]

       # Unique-ify and test we got them all
       _lowerCamelCase		:							List[Any]            =					list(set(lowerCamelCase_		)		)
       _lowerCamelCase		:							str            =					[]
       for imp in imports:
              try:
                     importlib.import_module(lowerCamelCase_		)
              except ImportError:
                     missing_packages.append(lowerCamelCase_		)

       if len(lowerCamelCase_		) > 0:
              raise ImportError(
                  '''This modeling file requires the following packages that were not found in your environment: '''
                  F'''{", ".join(lowerCamelCase_		)}. Run `pip install {" ".join(lowerCamelCase_		)}`'''		)

       return get_relative_imports(lowerCamelCase_		)






def 			snake_case_    ( A_   :						int,							A_   :						List[Any]		):


       '''simple docstring'''





       _lowerCamelCase		:							Optional[int]            =					module_path.replace(os.path.sep,							'''.'''		)
       _lowerCamelCase		:							str            =					importlib.import_module(lowerCamelCase_		)

       if class_name is None:
              return find_pipeline_class(lowerCamelCase_		)
       return getattr(lowerCamelCase_,							lowerCamelCase_		)






def 			snake_case_    ( A_   :						Dict		):


       '''simple docstring'''





       from ..pipelines import DiffusionPipeline

       _lowerCamelCase		:							str            =					dict(inspect.getmembers(lowerCamelCase_,							inspect.isclass		)		)

       _lowerCamelCase		:							List[Any]            =					None
       for cls_name, cls in cls_members.items():
              if (
                  cls_name != DiffusionPipeline.__name__
                  and issubclass(cls,							lowerCamelCase_		)
                  and cls.__module__.split('''.'''		)[0] != "diffusers"
              ):
                     if pipeline_class is not None:
                            raise ValueError(
                                F'''Multiple classes that inherit from {DiffusionPipeline.__name__} have been found:'''
                                F''' {pipeline_class.__name__}, and {cls_name}. Please make sure to define only one in'''
                                F''' {loaded_module}.'''		)
                     _lowerCamelCase		:							Any            =					cls

       return pipeline_class






def 			snake_case_    ( A_   :						Union[str, os.PathLike],							A_   :						str,							A_   :						Optional[Union[str, os.PathLike]] = None,							A_   :						bool = False,							A_   :						bool = False,							A_   :						Optional[Dict[str, str]] = None,							A_   :						Optional[Union[bool, str]] = None,							A_   :						Optional[str] = None,							A_   :						bool = False,							):


       '''simple docstring'''





       _lowerCamelCase		:							int            =					str(lowerCamelCase_		)

       _lowerCamelCase		:							Dict            =					os.path.join(lowerCamelCase_,							lowerCamelCase_		)

       if os.path.isfile(lowerCamelCase_		):
              _lowerCamelCase		:							List[str]            =					module_file_or_url
              _lowerCamelCase		:							int            =					"local"
       elif pretrained_model_name_or_path.count('''/'''		) == 0:
              _lowerCamelCase		:							Union[str, Any]            =					get_diffusers_versions()
              # cut ".dev0"
              _lowerCamelCase		:							Any            =					"v" + ".".join(__version__.split('''.'''		)[:3]		)

              # retrieve github version that matches
              if revision is None:
                     _lowerCamelCase		:							Tuple            =					latest_version if latest_version[1:] in available_versions else "main"
                     logger.info(F'''Defaulting to latest_version: {revision}.'''		)
              elif revision in available_versions:
                     _lowerCamelCase		:							List[str]            =					F'''v{revision}'''
              elif revision == "main":
                     _lowerCamelCase		:							int            =					revision
              else:
                     raise ValueError(
                         F'''`custom_revision`: {revision} does not exist. Please make sure to choose one of'''
                         F''' {", ".join(available_versions + ["main"]		)}.'''		)

              # community pipeline on GitHub
              _lowerCamelCase		:							Optional[int]            =					COMMUNITY_PIPELINES_URL.format(revision=lowerCamelCase_,							pipeline=lowerCamelCase_		)
              try:
                     _lowerCamelCase		:							Any            =					cached_download(
                         lowerCamelCase_,							cache_dir=lowerCamelCase_,							force_download=lowerCamelCase_,							proxies=lowerCamelCase_,							resume_download=lowerCamelCase_,							local_files_only=lowerCamelCase_,							use_auth_token=lowerCamelCase_,							)
                     _lowerCamelCase		:							Union[str, Any]            =					"git"
                     _lowerCamelCase		:							Union[str, Any]            =					pretrained_model_name_or_path + ".py"
              except EnvironmentError:
                     logger.error(F'''Could not locate the {module_file} inside {pretrained_model_name_or_path}.'''		)
                     raise
       else:
              try:
                     # Load from URL or cache if already cached
                     _lowerCamelCase		:							List[Any]            =					hf_hub_download(
                         lowerCamelCase_,							lowerCamelCase_,							cache_dir=lowerCamelCase_,							force_download=lowerCamelCase_,							proxies=lowerCamelCase_,							resume_download=lowerCamelCase_,							local_files_only=lowerCamelCase_,							use_auth_token=lowerCamelCase_,							)
                     _lowerCamelCase		:							Union[str, Any]            =					os.path.join('''local''',							'''--'''.join(pretrained_model_name_or_path.split('''/'''		)		)		)
              except EnvironmentError:
                     logger.error(F'''Could not locate the {module_file} inside {pretrained_model_name_or_path}.'''		)
                     raise

    # Check we have all the requirements in our environment
       _lowerCamelCase		:							Optional[int]            =					check_imports(lowerCamelCase_		)

       # Now we move the module inside our cached dynamic modules.
       _lowerCamelCase		:							Union[str, Any]            =					DIFFUSERS_DYNAMIC_MODULE_NAME + os.path.sep + submodule
       create_dynamic_module(lowerCamelCase_		)
       _lowerCamelCase		:							Dict            =					Path(lowerCamelCase_		) / full_submodule
       if submodule == "local" or submodule == "git":
              # We always copy local files (we could hash the file to see if there was a change, and give them the name of
              # that hash, to only copy when there is a modification but it seems overkill for now).
              # The only reason we do the copy is to avoid putting too many folders in sys.path.
              shutil.copy(lowerCamelCase_,							submodule_path / module_file		)
              for module_needed in modules_needed:
                     _lowerCamelCase		:							Union[str, Any]            =					F'''{module_needed}.py'''
                     shutil.copy(os.path.join(lowerCamelCase_,							lowerCamelCase_		),							submodule_path / module_needed		)
       else:
              # Get the commit hash
              # TODO: we will get this info in the etag soon, so retrieve it from there and not here.
              if isinstance(lowerCamelCase_,							lowerCamelCase_		):
                     _lowerCamelCase		:							Dict            =					use_auth_token
              elif use_auth_token is True:
                     _lowerCamelCase		:							Union[str, Any]            =					HfFolder.get_token()
              else:
                     _lowerCamelCase		:							Union[str, Any]            =					None

              _lowerCamelCase		:							Union[str, Any]            =					model_info(lowerCamelCase_,							revision=lowerCamelCase_,							token=lowerCamelCase_		).sha

              # The module file will end up being placed in a subfolder with the git hash of the repo. This way we get the
              # benefit of versioning.
              _lowerCamelCase		:							Optional[Any]            =					submodule_path / commit_hash
              _lowerCamelCase		:							Optional[int]            =					full_submodule + os.path.sep + commit_hash
              create_dynamic_module(lowerCamelCase_		)

              if not (submodule_path / module_file).exists():
                     shutil.copy(lowerCamelCase_,							submodule_path / module_file		)
              # Make sure we also have every file with relative
              for module_needed in modules_needed:
                     if not (submodule_path / module_needed).exists():
                            get_cached_module_file(
                                lowerCamelCase_,							F'''{module_needed}.py''',							cache_dir=lowerCamelCase_,							force_download=lowerCamelCase_,							resume_download=lowerCamelCase_,							proxies=lowerCamelCase_,							use_auth_token=lowerCamelCase_,							revision=lowerCamelCase_,							local_files_only=lowerCamelCase_,							)
       return os.path.join(lowerCamelCase_,							lowerCamelCase_		)







def 			snake_case_    ( A_   :						Union[str, os.PathLike],							A_   :						str,							A_   :						Optional[str] = None,							A_   :						Optional[Union[str, os.PathLike]] = None,							A_   :						bool = False,							A_   :						bool = False,							A_   :						Optional[Dict[str, str]] = None,							A_   :						Optional[Union[bool, str]] = None,							A_   :						Optional[str] = None,							A_   :						bool = False,							**A_   :						Dict,							):


       '''simple docstring'''





       _lowerCamelCase		:							Tuple            =					get_cached_module_file(
           lowerCamelCase_,							lowerCamelCase_,							cache_dir=lowerCamelCase_,							force_download=lowerCamelCase_,							resume_download=lowerCamelCase_,							proxies=lowerCamelCase_,							use_auth_token=lowerCamelCase_,							revision=lowerCamelCase_,							local_files_only=lowerCamelCase_,							)
       return get_class_in_module(lowerCamelCase_,							final_module.replace('''.py''',							''''''		)		)







"""simple docstring"""







import itertools
import json
import os
import unittest

from transformers import AddedToken, RobertaTokenizer, RobertaTokenizerFast
from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class       _a  ( SCREAMING_SNAKE_CASE__     ,	unittest.TestCase):
			__magic_name__     					=     RobertaTokenizer
			__magic_name__     					=     RobertaTokenizerFast
			__magic_name__     					=     True
			__magic_name__     					=     {"""cls_token""": """<s>"""}



			def 				__lowercase					(			self							:				Any		)							->					int:
									super().setUp()

									# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
									snake_case   :			int						    = [
									    "l",
									    "o",
									    "w",
									    "e",
									    "r",
									    "s",
									    "t",
									    "i",
									    "d",
									    "n",
									    "\u0120",
									    "\u0120l",
									    "\u0120n",
									    "\u0120lo",
									    "\u0120low",
									    "er",
									    "\u0120lowest",
									    "\u0120newer",
									    "\u0120wider",
									    "<unk>",
									]
									snake_case   :			Optional[int]						    = dict(zip(_lowercase   ,	range(len(_lowercase		)		)		)		)
									snake_case   :			int						    = ["#version: 0.2", "\u0120 l", "\u0120l o", "\u0120lo w", "e r", ""]
									snake_case   :			Union[str, Any]						    = {"unk_token": "<unk>"}

									snake_case   :			Optional[Any]						    = os.path.join(self.tmpdirname   ,	VOCAB_FILES_NAMES["vocab_file"]		)
									snake_case   :			str						    = os.path.join(self.tmpdirname   ,	VOCAB_FILES_NAMES["merges_file"]		)
									with open(self.vocab_file   ,	"w"   ,	encoding="utf-8"		) as fp:
															fp.write(json.dumps(_lowercase		) + "\n"		)
									with open(self.merges_file   ,	"w"   ,	encoding="utf-8"		) as fp:
															fp.write("\n".join(_lowercase		)		)



			def 				__lowercase					(			self							:				Optional[Any]   ,	**_lowercase							:				Union[str, Any]		)							->					Dict:
									kwargs.update(self.special_tokens_map		)
									return self.tokenizer_class.from_pretrained(self.tmpdirname   ,	**_lowercase		)



			def 				__lowercase					(			self							:				List[str]   ,	**_lowercase							:				Union[str, Any]		)							->					str:
									kwargs.update(self.special_tokens_map		)
									return RobertaTokenizerFast.from_pretrained(self.tmpdirname   ,	**_lowercase		)



			def 				__lowercase					(			self							:				Union[str, Any]   ,	_lowercase							:				str		)							->					Optional[Any]:
									snake_case   :			Any						    = "lower newer"
									snake_case   :			Union[str, Any]						    = "lower newer"
									return input_text, output_text



			def 				__lowercase					(			self							:				Optional[int]		)							->					Any:
									snake_case   :			Any						    = self.tokenizer_class(self.vocab_file   ,	self.merges_file   ,	**self.special_tokens_map		)
									snake_case   :			Dict						    = "lower newer"
									snake_case   :			Dict						    = ["l", "o", "w", "er", "\u0120", "n", "e", "w", "er"]
									snake_case   :			Any						    = tokenizer.tokenize(_lowercase		)  # , add_prefix_space=True)
									self.assertListEqual(_lowercase   ,	_lowercase		)

									snake_case   :			List[str]						    = tokens + [tokenizer.unk_token]
									snake_case   :			List[Any]						    = [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
									self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowercase		)   ,	_lowercase		)



			def 				__lowercase					(			self							:				int		)							->					str:
									snake_case   :			List[str]						    = self.get_tokenizer()

									self.assertListEqual(tokenizer.encode("Hello world!"   ,	add_special_tokens=_lowercase		)   ,	[0, 31414, 232, 328, 2]		)
									self.assertListEqual(
									    tokenizer.encode("Hello world! cécé herlolip 418"   ,	add_special_tokens=_lowercase		)   ,	[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]   ,	)



			@slow
			def 				__lowercase					(			self							:				Dict		)							->					Optional[int]:
									snake_case   :			Tuple						    = self.tokenizer_class.from_pretrained("roberta-base"		)

									snake_case   :			Tuple						    = tokenizer.encode("sequence builders"   ,	add_special_tokens=_lowercase		)
									snake_case   :			Optional[int]						    = tokenizer.encode("multi-sequence build"   ,	add_special_tokens=_lowercase		)

									snake_case   :			Optional[Any]						    = tokenizer.encode(
									    "sequence builders"   ,	add_special_tokens=_lowercase   ,	add_prefix_space=_lowercase		)
									snake_case   :			Optional[int]						    = tokenizer.encode(
									    "sequence builders"   ,	"multi-sequence build"   ,	add_special_tokens=_lowercase   ,	add_prefix_space=_lowercase		)

									snake_case   :			Optional[Any]						    = tokenizer.build_inputs_with_special_tokens(_lowercase		)
									snake_case   :			Any						    = tokenizer.build_inputs_with_special_tokens(_lowercase   ,	_lowercase		)

									assert encoded_sentence == encoded_text_from_decode
									assert encoded_pair == encoded_pair_from_decode



			def 				__lowercase					(			self							:				int		)							->					Any:
									snake_case   :			Any						    = self.get_tokenizer()

									snake_case   :			Optional[Any]						    = "Encode this sequence."
									snake_case   :			List[Any]						    = tokenizer.byte_encoder[" ".encode("utf-8"		)[0]]

									# Testing encoder arguments
									snake_case   :			Any						    = tokenizer.encode(_lowercase   ,	add_special_tokens=_lowercase   ,	add_prefix_space=_lowercase		)
									snake_case   :			Any						    = tokenizer.convert_ids_to_tokens(encoded[0]		)[0]
									self.assertNotEqual(_lowercase   ,	_lowercase		)

									snake_case   :			Dict						    = tokenizer.encode(_lowercase   ,	add_special_tokens=_lowercase   ,	add_prefix_space=_lowercase		)
									snake_case   :			Any						    = tokenizer.convert_ids_to_tokens(encoded[0]		)[0]
									self.assertEqual(_lowercase   ,	_lowercase		)

									tokenizer.add_special_tokens({"bos_token": "<s>"}		)
									snake_case   :			Union[str, Any]						    = tokenizer.encode(_lowercase   ,	add_special_tokens=_lowercase		)
									snake_case   :			List[str]						    = tokenizer.convert_ids_to_tokens(encoded[1]		)[0]
									self.assertNotEqual(_lowercase   ,	_lowercase		)

									# Testing spaces after special tokens
									snake_case   :			Optional[int]						    = "<mask>"
									tokenizer.add_special_tokens(
									    {"mask_token": AddedToken(_lowercase   ,	lstrip=_lowercase   ,	rstrip=_lowercase		)}		)  # mask token has a left space
									snake_case   :			Optional[int]						    = tokenizer.convert_tokens_to_ids(_lowercase		)

									snake_case   :			Tuple						    = "Encode <mask> sequence"
									snake_case   :			Union[str, Any]						    = "Encode <mask>sequence"

									snake_case   :			Union[str, Any]						    = tokenizer.encode(_lowercase		)
									snake_case   :			Optional[int]						    = encoded.index(_lowercase		)
									snake_case   :			int						    = tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]		)[0]
									self.assertEqual(_lowercase   ,	_lowercase		)

									snake_case   :			int						    = tokenizer.encode(_lowercase		)
									snake_case   :			Optional[int]						    = encoded.index(_lowercase		)
									snake_case   :			List[Any]						    = tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]		)[0]
									self.assertNotEqual(_lowercase   ,	_lowercase		)



			def 				__lowercase					(			self							:				Dict		)							->					Union[str, Any]:
									pass



			def 				__lowercase					(			self							:				List[str]		)							->					str:
									for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
															with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''		):
																					snake_case   :			List[Any]						    = self.rust_tokenizer_class.from_pretrained(_lowercase   ,	**_lowercase		)
																					snake_case   :			Optional[int]						    = self.tokenizer_class.from_pretrained(_lowercase   ,	**_lowercase		)
																					snake_case   :			Optional[int]						    = "A, <mask> AllenNLP sentence."
																					snake_case   :			Tuple						    = tokenizer_r.encode_plus(_lowercase   ,	add_special_tokens=_lowercase   ,	return_token_type_ids=_lowercase		)
																					snake_case   :			Optional[Any]						    = tokenizer_p.encode_plus(_lowercase   ,	add_special_tokens=_lowercase   ,	return_token_type_ids=_lowercase		)

																					# token_type_ids should put 0 everywhere
																					self.assertEqual(sum(tokens_r["token_type_ids"]		)   ,	sum(tokens_p["token_type_ids"]		)		)

																					# attention_mask should put 1 everywhere, so sum over length should be 1
																					self.assertEqual(
																					    sum(tokens_r["attention_mask"]		) / len(tokens_r["attention_mask"]		)   ,	sum(tokens_p["attention_mask"]		) / len(tokens_p["attention_mask"]		)   ,	)

																					snake_case   :			List[str]						    = tokenizer_r.convert_ids_to_tokens(tokens_r["input_ids"]		)
																					snake_case   :			List[Any]						    = tokenizer_p.convert_ids_to_tokens(tokens_p["input_ids"]		)

																					# Rust correctly handles the space before the mask while python doesnt
																					self.assertSequenceEqual(tokens_p["input_ids"]   ,	[0, 250, 6, 50264, 3823, 487, 21992, 3645, 4, 2]		)
																					self.assertSequenceEqual(tokens_r["input_ids"]   ,	[0, 250, 6, 50264, 3823, 487, 21992, 3645, 4, 2]		)

																					self.assertSequenceEqual(
																					    _lowercase   ,	["<s>", "A", ",", "<mask>", "ĠAllen", "N", "LP", "Ġsentence", ".", "</s>"]		)
																					self.assertSequenceEqual(
																					    _lowercase   ,	["<s>", "A", ",", "<mask>", "ĠAllen", "N", "LP", "Ġsentence", ".", "</s>"]		)



			def 				__lowercase					(			self							:				Tuple		)							->					List[Any]:
									for trim_offsets, add_prefix_space in itertools.product([True, False]   ,	repeat=2		):
															snake_case   :			List[Any]						    = self.rust_tokenizer_class.from_pretrained(
															    self.tmpdirname   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)

															snake_case   :			Optional[int]						    = json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()		)
															snake_case   :			Union[str, Any]						    = json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()		)

															self.assertEqual(pre_tokenizer_state["add_prefix_space"]   ,	_lowercase		)

															self.assertEqual(post_processor_state["add_prefix_space"]   ,	_lowercase		)
															self.assertEqual(post_processor_state["trim_offsets"]   ,	_lowercase		)



			def 				__lowercase					(			self							:				int		)							->					List[str]:
									# Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space` and
									# `trim_offsets`
									for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
															with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''		):
																					snake_case   :			List[Any]						    = "hello"  # `hello` is a token in the vocabulary of `pretrained_name`
																					snake_case   :			List[str]						    = F'''{text_of_1_token} {text_of_1_token}'''

																					snake_case   :			Optional[Any]						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			Union[str, Any]						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(0, len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(len(_lowercase		) + 1, len(_lowercase		) + 1 + len(_lowercase		))   ,	)

																					snake_case   :			List[Any]						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			Tuple						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(0, len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(len(_lowercase		) + 1, len(_lowercase		) + 1 + len(_lowercase		))   ,	)

																					snake_case   :			Dict						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			int						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(0, len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(len(_lowercase		), len(_lowercase		) + 1 + len(_lowercase		))   ,	)

																					snake_case   :			Optional[int]						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			Optional[int]						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(0, len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(len(_lowercase		), len(_lowercase		) + 1 + len(_lowercase		))   ,	)

																					snake_case   :			Dict						    = F''' {text}'''

																					# tokenizer_r = self.rust_tokenizer_class.from_pretrained(
																					#     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
																					# )
																					# encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
																					# self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
																					# self.assertEqual(
																					#     encoding.offset_mapping[1],
																					#     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
																					# )

																					snake_case   :			List[str]						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			List[str]						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(1, 1 + len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(1 + len(_lowercase		) + 1, 1 + len(_lowercase		) + 1 + len(_lowercase		))   ,	)

																					snake_case   :			Union[str, Any]						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			Optional[int]						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(0, 1 + len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(1 + len(_lowercase		), 1 + len(_lowercase		) + 1 + len(_lowercase		))   ,	)

																					snake_case   :			Optional[Any]						    = self.rust_tokenizer_class.from_pretrained(
																					    _lowercase   ,	use_fast=_lowercase   ,	add_prefix_space=_lowercase   ,	trim_offsets=_lowercase		)
																					snake_case   :			Union[str, Any]						    = tokenizer_r(_lowercase   ,	return_offsets_mapping=_lowercase   ,	add_special_tokens=_lowercase		)
																					self.assertEqual(encoding.offset_mapping[0]   ,	(0, 1 + len(_lowercase		))		)
																					self.assertEqual(
																					    encoding.offset_mapping[1]   ,	(1 + len(_lowercase		), 1 + len(_lowercase		) + 1 + len(_lowercase		))   ,	)



