






import os

import torch

from ..logging import get_logger
from .constants import FSDP_PYTORCH_VERSION, MODEL_NAME, OPTIMIZER_NAME
from .versions import is_torch_version


if is_torch_version('''>=''', FSDP_PYTORCH_VERSION):
	import torch.distributed.checkpoint as dist_cp
	from torch.distributed.checkpoint.default_planner import DefaultLoadPlanner, DefaultSavePlanner
	from torch.distributed.checkpoint.optimizer import load_sharded_optimizer_state_dict
	from torch.distributed.fsdp.fully_sharded_data_parallel import FullyShardedDataParallel as FSDP
	from torch.distributed.fsdp.fully_sharded_data_parallel import StateDictType


lowerCamelCase : Any						   =		get_logger(__name__)
def       snake_case_		(     lowerCAmelCase_       :						Optional[Any]       ,       lowerCAmelCase_       :						Optional[Any]       ,       lowerCAmelCase_       :						Optional[Any]       ,       lowerCAmelCase_       :						Optional[Any]       ,       lowerCAmelCase_       :						Optional[int]=0      ):
							os.makedirs(UpperCamelCase__       ,       exist_ok=UpperCamelCase__      )
							with FSDP.state_dict_type(
							    UpperCamelCase__       ,       fsdp_plugin.state_dict_type       ,       fsdp_plugin.state_dict_config       ,       fsdp_plugin.optim_state_dict_config      ):
														__lowercase      :							Dict				=     model.state_dict()
														if fsdp_plugin.state_dict_type == StateDictType.FULL_STATE_DICT:
																					__lowercase      :							Union[str, Any]				=     F"{MODEL_NAME}.bin" if model_index == 0 else F"{MODEL_NAME}_{model_index}.bin"
																					__lowercase      :							str				=     os.path.join(UpperCamelCase__       ,       UpperCamelCase__      )
																					if accelerator.process_index == 0:
																												logger.info(F"Saving model to {output_model_file}"      )
																												torch.save(UpperCamelCase__       ,       UpperCamelCase__      )
																												logger.info(F"Model saved to {output_model_file}"      )
														elif fsdp_plugin.state_dict_type == StateDictType.LOCAL_STATE_DICT:
																					__lowercase      :							int				=     (
																					    F"{MODEL_NAME}_rank{accelerator.process_index}.bin"
																					    if model_index == 0
																					    else F"{MODEL_NAME}_{model_index}_rank{accelerator.process_index}.bin"
																					)
																					__lowercase      :							Any				=     os.path.join(UpperCamelCase__       ,       UpperCamelCase__      )
																					logger.info(F"Saving model to {output_model_file}"      )
																					torch.save(UpperCamelCase__       ,       UpperCamelCase__      )
																					logger.info(F"Model saved to {output_model_file}"      )
														elif fsdp_plugin.state_dict_type == StateDictType.SHARDED_STATE_DICT:
																					__lowercase      :							List[str]				=     os.path.join(UpperCamelCase__       ,       F"{MODEL_NAME}_{model_index}"      )
																					os.makedirs(UpperCamelCase__       ,       exist_ok=UpperCamelCase__      )
																					logger.info(F"Saving model to {ckpt_dir}"      )
																					__lowercase      :							List[str]				=     {"""model""": state_dict}

																					dist_cp.save_state_dict(
																					    state_dict=UpperCamelCase__       ,       storage_writer=dist_cp.FileSystemWriter(UpperCamelCase__      )       ,       planner=DefaultSavePlanner()       ,       )
																					logger.info(F"Model saved to {ckpt_dir}"      )
def       snake_case_		(     lowerCAmelCase_       :						List[Any]       ,       lowerCAmelCase_       :						Optional[int]       ,       lowerCAmelCase_       :						int       ,       lowerCAmelCase_       :						List[str]       ,       lowerCAmelCase_       :						List[str]=0      ):
							accelerator.wait_for_everyone()
							with FSDP.state_dict_type(
							    UpperCamelCase__       ,       fsdp_plugin.state_dict_type       ,       fsdp_plugin.state_dict_config       ,       fsdp_plugin.optim_state_dict_config      ):
														if fsdp_plugin.state_dict_type == StateDictType.FULL_STATE_DICT:
																					if type(UpperCamelCase__      ) != FSDP and accelerator.process_index != 0:
																												if not fsdp_plugin.sync_module_states:
																																			raise ValueError(
																																			    """Set the `sync_module_states` flag to `True` so that model states are synced across processes when """
																																			    """initializing FSDP object"""      )
																												return
																					__lowercase      :							List[str]				=     F"{MODEL_NAME}.bin" if model_index == 0 else F"{MODEL_NAME}_{model_index}.bin"
																					__lowercase      :							Tuple				=     os.path.join(UpperCamelCase__       ,       UpperCamelCase__      )
																					logger.info(F"Loading model from {input_model_file}"      )
																					__lowercase      :							Any				=     torch.load(UpperCamelCase__      )
																					logger.info(F"Model loaded from {input_model_file}"      )
														elif fsdp_plugin.state_dict_type == StateDictType.LOCAL_STATE_DICT:
																					__lowercase      :							str				=     (
																					    F"{MODEL_NAME}_rank{accelerator.process_index}.bin"
																					    if model_index == 0
																					    else F"{MODEL_NAME}_{model_index}_rank{accelerator.process_index}.bin"
																					)
																					__lowercase      :							int				=     os.path.join(UpperCamelCase__       ,       UpperCamelCase__      )
																					logger.info(F"Loading model from {input_model_file}"      )
																					__lowercase      :							Union[str, Any]				=     torch.load(UpperCamelCase__      )
																					logger.info(F"Model loaded from {input_model_file}"      )
														elif fsdp_plugin.state_dict_type == StateDictType.SHARDED_STATE_DICT:
																					__lowercase      :							Dict				=     (
																					    os.path.join(UpperCamelCase__       ,       F"{MODEL_NAME}_{model_index}"      )
																					    if F"{MODEL_NAME}" not in input_dir
																					    else input_dir
																					)
																					logger.info(F"Loading model from {ckpt_dir}"      )
																					__lowercase      :							Tuple				=     {"""model""": model.state_dict()}
																					dist_cp.load_state_dict(
																					    state_dict=UpperCamelCase__       ,       storage_reader=dist_cp.FileSystemReader(UpperCamelCase__      )       ,       planner=DefaultLoadPlanner()       ,       )
																					__lowercase      :							str				=     state_dict["""model"""]
																					logger.info(F"Model loaded from {ckpt_dir}"      )
														model.load_state_dict(UpperCamelCase__      )
def       snake_case_		(     lowerCAmelCase_       :						Dict       ,       lowerCAmelCase_       :						str       ,       lowerCAmelCase_       :						Optional[Any]       ,       lowerCAmelCase_       :						List[str]       ,       lowerCAmelCase_       :						int       ,       lowerCAmelCase_       :						Any=0      ):
							os.makedirs(UpperCamelCase__       ,       exist_ok=UpperCamelCase__      )
							with FSDP.state_dict_type(
							    UpperCamelCase__       ,       fsdp_plugin.state_dict_type       ,       fsdp_plugin.state_dict_config       ,       fsdp_plugin.optim_state_dict_config      ):
														__lowercase      :							Optional[int]				=     FSDP.optim_state_dict(UpperCamelCase__       ,       UpperCamelCase__      )
														if fsdp_plugin.state_dict_type == StateDictType.FULL_STATE_DICT:
																					if accelerator.process_index == 0:
																												__lowercase      :							Tuple				=     (
																												    F"{OPTIMIZER_NAME}.bin" if optimizer_index == 0 else F"{OPTIMIZER_NAME}_{optimizer_index}.bin"
																												)
																												__lowercase      :							List[str]				=     os.path.join(UpperCamelCase__       ,       UpperCamelCase__      )
																												logger.info(F"Saving Optimizer state to {output_optimizer_file}"      )
																												torch.save(UpperCamelCase__       ,       UpperCamelCase__      )
																												logger.info(F"Optimizer state saved in {output_optimizer_file}"      )
														else:
																					__lowercase      :							Dict				=     os.path.join(UpperCamelCase__       ,       F"{OPTIMIZER_NAME}_{optimizer_index}"      )
																					os.makedirs(UpperCamelCase__       ,       exist_ok=UpperCamelCase__      )
																					logger.info(F"Saving Optimizer state to {ckpt_dir}"      )
																					dist_cp.save_state_dict(
																					    state_dict={"""optimizer""": optim_state}       ,       storage_writer=dist_cp.FileSystemWriter(UpperCamelCase__      )       ,       planner=DefaultSavePlanner()       ,       )
																					logger.info(F"Optimizer state saved in {ckpt_dir}"      )



def       snake_case_		(     lowerCAmelCase_       :						Tuple       ,       lowerCAmelCase_       :						Dict       ,       lowerCAmelCase_       :						str       ,       lowerCAmelCase_       :						int       ,       lowerCAmelCase_       :						Tuple       ,       lowerCAmelCase_       :						List[Any]=0      ):
							accelerator.wait_for_everyone()
							with FSDP.state_dict_type(
							    UpperCamelCase__       ,       fsdp_plugin.state_dict_type       ,       fsdp_plugin.state_dict_config       ,       fsdp_plugin.optim_state_dict_config      ):
														if fsdp_plugin.state_dict_type == StateDictType.FULL_STATE_DICT:
																					__lowercase      :							Dict				=     None
																					# below check should work but currently it isn't working (mostly opytorch issue),
																					# in the meantime disabling it at the cost of excess memory usage
																					# if accelerator.process_index == 0 or not fsdp_plugin.optim_state_dict_config.rank0_only:
																					__lowercase      :							int				=     (
																					    F"{OPTIMIZER_NAME}.bin" if optimizer_index == 0 else F"{OPTIMIZER_NAME}_{optimizer_index}.bin"
																					)
																					__lowercase      :							List[str]				=     os.path.join(UpperCamelCase__       ,       UpperCamelCase__      )
																					logger.info(F"Loading Optimizer state from {input_optimizer_file}"      )
																					__lowercase      :							Any				=     torch.load(UpperCamelCase__      )
																					logger.info(F"Optimizer state loaded from {input_optimizer_file}"      )
														else:
																					__lowercase      :							Optional[int]				=     (
																					    os.path.join(UpperCamelCase__       ,       F"{OPTIMIZER_NAME}_{optimizer_index}"      )
																					    if F"{OPTIMIZER_NAME}" not in input_dir
																					    else input_dir
																					)
																					logger.info(F"Loading Optimizer from {ckpt_dir}"      )
																					__lowercase      :							Any				=     load_sharded_optimizer_state_dict(
																					    model_state_dict=model.state_dict()       ,       optimizer_key="""optimizer"""       ,       storage_reader=dist_cp.FileSystemReader(UpperCamelCase__      )       ,       )
																					__lowercase      :							int				=     optim_state["""optimizer"""]
																					logger.info(F"Optimizer loaded from {ckpt_dir}"      )
														__lowercase      :							List[Any]				=     FSDP.optim_state_dict_to_load(UpperCamelCase__       ,       UpperCamelCase__       ,       UpperCamelCase__      )
														optimizer.load_state_dict(UpperCamelCase__      )







import itertools
import json
import os
import unittest

from transformers import AddedToken, LongformerTokenizer, LongformerTokenizerFast
from transformers.models.longformer.tokenization_longformer import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class 		lowerCAmelCase     ( __a      ,       unittest.TestCase			):

					'''simple docstring'''

					_A						:			str									=      LongformerTokenizer
					_A						:			int									=      True
					_A						:			Optional[int]									=      LongformerTokenizerFast
					_A						:			int									=      True



					def       lowerCAmelCase				(  self				:	Any							)			->  List[str]:


												"""simple docstring"""

												super().setUp()

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

												__lowercase      :							Dict				=     os.path.join(self.tmpdirname		,     VOCAB_FILES_NAMES["""vocab_file"""]							)
												__lowercase      :							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(__a							) + """\n"""							)
												with open(self.merges_file		,     """w"""		,     encoding="""utf-8"""							) as fp:
																			fp.write("""\n""".join(__a							)							)



					def       lowerCAmelCase				(  self				:	Optional[int]		,     **__a				:	Optional[Any]							)			->  str:


												"""simple docstring"""

												kwargs.update(self.special_tokens_map							)
												return self.tokenizer_class.from_pretrained(self.tmpdirname		,     **__a							)



					def       lowerCAmelCase				(  self				:	Tuple		,     **__a				:	Tuple							)			->  str:


												"""simple docstring"""

												kwargs.update(self.special_tokens_map							)
												return self.rust_tokenizer_class.from_pretrained(self.tmpdirname		,     **__a							)



					def       lowerCAmelCase				(  self				:	str		,     __a				:	Optional[int]							)			->  Union[str, Any]:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     """lower newer"""
												__lowercase      :							int				=     """lower newer"""
												return input_text, output_text



					def       lowerCAmelCase				(  self				:	List[Any]							)			->  Optional[int]:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     self.tokenizer_class(self.vocab_file		,     self.merges_file		,     **self.special_tokens_map							)
												__lowercase      :							Dict				=     """lower newer"""
												__lowercase      :							Optional[Any]				=     ["""l""", """o""", """w""", """er""", """\u0120""", """n""", """e""", """w""", """er"""]
												__lowercase      :							str				=     tokenizer.tokenize(__a							)  # , add_prefix_space=True)
												self.assertListEqual(__a		,     __a							)

												__lowercase      :							int				=     tokens + [tokenizer.unk_token]
												__lowercase      :							str				=     [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
												self.assertListEqual(tokenizer.convert_tokens_to_ids(__a							)		,     __a							)



					def       lowerCAmelCase				(  self				:	Optional[Any]							)			->  List[Any]:


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     self.get_tokenizer()

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



					@slow
					def       lowerCAmelCase				(  self				:	Tuple							)			->  str:


												"""simple docstring"""

												__lowercase      :							Any				=     self.tokenizer_class.from_pretrained("""allenai/longformer-base-4096"""							)

												__lowercase      :							Optional[Any]				=     tokenizer.encode("""sequence builders"""		,     add_special_tokens=__a							)
												__lowercase      :							List[str]				=     tokenizer.encode("""multi-sequence build"""		,     add_special_tokens=__a							)

												__lowercase      :							Optional[Any]				=     tokenizer.encode(
												    """sequence builders"""		,     add_special_tokens=__a		,     add_prefix_space=__a							)
												__lowercase      :							Union[str, Any]				=     tokenizer.encode(
												    """sequence builders"""		,     """multi-sequence build"""		,     add_special_tokens=__a		,     add_prefix_space=__a							)

												__lowercase      :							List[Any]				=     tokenizer.build_inputs_with_special_tokens(__a							)
												__lowercase      :							Any				=     tokenizer.build_inputs_with_special_tokens(__a		,     __a							)

												assert encoded_sentence == encoded_text_from_decode
												assert encoded_pair == encoded_pair_from_decode



					def       lowerCAmelCase				(  self				:	Dict							)			->  Tuple:


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     self.get_tokenizer()

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

												# Testing encoder arguments
												__lowercase      :							Dict				=     tokenizer.encode(__a		,     add_special_tokens=__a		,     add_prefix_space=__a							)
												__lowercase      :							Tuple				=     tokenizer.convert_ids_to_tokens(encoded[0]							)[0]
												self.assertNotEqual(__a		,     __a							)

												__lowercase      :							List[str]				=     tokenizer.encode(__a		,     add_special_tokens=__a		,     add_prefix_space=__a							)
												__lowercase      :							Any				=     tokenizer.convert_ids_to_tokens(encoded[0]							)[0]
												self.assertEqual(__a		,     __a							)

												tokenizer.add_special_tokens({"""bos_token""": """<s>"""}							)
												__lowercase      :							str				=     tokenizer.encode(__a		,     add_special_tokens=__a							)
												__lowercase      :							Dict				=     tokenizer.convert_ids_to_tokens(encoded[1]							)[0]
												self.assertNotEqual(__a		,     __a							)

												# Testing spaces after special tokens
												__lowercase      :							List[Any]				=     """<mask>"""
												tokenizer.add_special_tokens(
												    {"""mask_token""": AddedToken(__a		,     lstrip=__a		,     rstrip=__a							)}							)  # mask token has a left space
												__lowercase      :							Dict				=     tokenizer.convert_tokens_to_ids(__a							)

												__lowercase      :							List[str]				=     """Encode <mask> sequence"""
												__lowercase      :							List[str]				=     """Encode <mask>sequence"""

												__lowercase      :							Union[str, Any]				=     tokenizer.encode(__a							)
												__lowercase      :							Dict				=     encoded.index(__a							)
												__lowercase      :							List[Any]				=     tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]							)[0]
												self.assertEqual(__a		,     __a							)

												__lowercase      :							int				=     tokenizer.encode(__a							)
												__lowercase      :							Union[str, Any]				=     encoded.index(__a							)
												__lowercase      :							List[Any]				=     tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]							)[0]
												self.assertNotEqual(__a		,     __a							)



					def       lowerCAmelCase				(  self				:	int							)			->  str:


												"""simple docstring"""

												pass



					def       lowerCAmelCase				(  self				:	int							)			->  Dict:


												"""simple docstring"""

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

																										# 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"""]							)		,     )

																										__lowercase      :							Dict				=     tokenizer_r.convert_ids_to_tokens(tokens_r["""input_ids"""]							)
																										__lowercase      :							str				=     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(
																										    __a		,     ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]							)
																										self.assertSequenceEqual(
																										    __a		,     ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]							)



					def       lowerCAmelCase				(  self				:	List[Any]							)			->  Dict:


												"""simple docstring"""

												for trim_offsets, add_prefix_space in itertools.product([True, False]		,     repeat=2							):
																			__lowercase      :							Dict				=     self.rust_tokenizer_class.from_pretrained(
																			    self.tmpdirname		,     use_fast=__a		,     add_prefix_space=__a		,     trim_offsets=__a							)

																			__lowercase      :							Optional[int]				=     json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()							)
																			__lowercase      :							Any				=     json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()							)

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

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



					def       lowerCAmelCase				(  self				:	int							)			->  Tuple:


												"""simple docstring"""

												for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																			with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"							):
																										__lowercase      :							List[str]				=     """hello"""  # `hello` is a token in the vocabulary of `pretrained_name`
																										__lowercase      :							int				=     F"{text_of_1_token} {text_of_1_token}"

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

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

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

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

																										__lowercase      :							Any				=     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)),
																										# )

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

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

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