




import inspect
from typing import Callable, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import DiffusionPipeline
from diffusers.models import AutoencoderKL, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler
from diffusers.utils import logging


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


class    lowerCamelCase    (		_lowerCamelCase						):






			'''simple docstring'''





			def __init__( self			:   Tuple       ,						lowerCamelCase_			:   AutoencoderKL       ,						lowerCamelCase_			:   CLIPTextModel       ,						lowerCamelCase_			:   CLIPTokenizer       ,						lowerCamelCase_			:   UNetaDConditionModel       ,						lowerCamelCase_			:   Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]       ,						lowerCamelCase_			:   StableDiffusionSafetyChecker       ,						lowerCamelCase_			:   CLIPImageProcessor       ,						)						->   List[str]:
								super().__init__()
								self.register_modules(
								    vae=lowerCamelCase_       ,						text_encoder=lowerCamelCase_       ,						tokenizer=lowerCamelCase_       ,						unet=lowerCamelCase_       ,						scheduler=lowerCamelCase_       ,						safety_checker=lowerCamelCase_       ,						feature_extractor=lowerCamelCase_       ,						)

			def 							UpperCAmelCase__       ( self			:   List[str]       ,						lowerCamelCase_			:   Optional[Union[str, int]] = "auto"  )						->   List[Any]:
								if slice_size == "auto":
													# half the attention head size is usually a good trade-off between
													# speed and memory
													__magic_name__							:	Any    							=							self.unet.config.attention_head_dim // 2
								self.unet.set_attention_slice(lowerCamelCase_  )

			def 							UpperCAmelCase__       ( self			:   str  )						->   Tuple:
								self.enable_attention_slicing(lowerCamelCase_  )


			@torch.no_grad()
			def __call__( self			:   Optional[Any]       ,						lowerCamelCase_			:   Union[str, List[str]]       ,						lowerCamelCase_			:   int = 512       ,						lowerCamelCase_			:   int = 512       ,						lowerCamelCase_			:   int = 50       ,						lowerCamelCase_			:   float = 7.5       ,						lowerCamelCase_			:   Optional[Union[str, List[str]]] = None       ,						lowerCamelCase_			:   Optional[int] = 1       ,						lowerCamelCase_			:   float = 0.0       ,						lowerCamelCase_			:   Optional[torch.Generator] = None       ,						lowerCamelCase_			:   Optional[torch.FloatTensor] = None       ,						lowerCamelCase_			:   Optional[str] = "pil"       ,						lowerCamelCase_			:   bool = True       ,						lowerCamelCase_			:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,						lowerCamelCase_			:   int = 1       ,						lowerCamelCase_			:   Optional[torch.FloatTensor] = None       ,						**lowerCamelCase_			:   List[Any]       ,						)						->   Dict:

								if isinstance(lowerCamelCase_       ,						lowerCamelCase_  ):
													__magic_name__							:	str    							=							1
								elif isinstance(lowerCamelCase_       ,						lowerCamelCase_  ):
													__magic_name__							:	Optional[Any]    							=							len(lowerCamelCase_  )
								else:
													raise ValueError(F'''`prompt` has to be of type `str` or `list` but is {type(lowerCamelCase_  )}'''  )

								if height % 8 != 0 or width % 8 != 0:
													raise ValueError(F'''`height` and `width` have to be divisible by 8 but are {height} and {width}.'''  )

								if (callback_steps is None) or (
								    callback_steps is not None and (not isinstance(lowerCamelCase_       ,						lowerCamelCase_  ) or callback_steps <= 0)
								):
													raise ValueError(
													    F'''`callback_steps` has to be a positive integer but is {callback_steps} of type'''
													    F''' {type(lowerCamelCase_  )}.'''  )

								# get prompt text embeddings
								__magic_name__							:	Optional[int]    							=							self.tokenizer(
								    lowerCamelCase_       ,						padding='''max_length'''       ,						max_length=self.tokenizer.model_max_length       ,						return_tensors='''pt'''       ,						)
								__magic_name__							:	Tuple    							=							text_inputs.input_ids

								if text_input_ids.shape[-1] > self.tokenizer.model_max_length:
													__magic_name__							:	List[str]    							=							self.tokenizer.batch_decode(text_input_ids[:, self.tokenizer.model_max_length :]  )
													logger.warning(
													    '''The following part of your input was truncated because CLIP can only handle sequences up to'''
													    F''' {self.tokenizer.model_max_length} tokens: {removed_text}'''  )
													__magic_name__							:	List[str]    							=							text_input_ids[:, : self.tokenizer.model_max_length]

								if text_embeddings is None:
													__magic_name__							:	Tuple    							=							self.text_encoder(text_input_ids.to(self.device  )  )[0]

								# duplicate text embeddings for each generation per prompt, using mps friendly method
								__magic_name__							,    __magic_name__							,    __magic_name__							:	Tuple    							=							text_embeddings.shape
								__magic_name__							:	int    							=							text_embeddings.repeat(1       ,						lowerCamelCase_       ,						1  )
								__magic_name__							:	int    							=							text_embeddings.view(bs_embed * num_images_per_prompt       ,						lowerCamelCase_       ,						-1  )

								# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
								# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
								# corresponds to doing no classifier free guidance.
								__magic_name__							:	List[Any]    							=							guidance_scale > 1.0
								# get unconditional embeddings for classifier free guidance
								if do_classifier_free_guidance:
													__magic_name__							:	List[str]
													if negative_prompt is None:
																		__magic_name__							:	List[str]    							=							['''''']
													elif type(lowerCamelCase_  ) is not type(lowerCamelCase_  ):
																		raise TypeError(
																		    F'''`negative_prompt` should be the same type to `prompt`, but got {type(lowerCamelCase_  )} !='''
																		    F''' {type(lowerCamelCase_  )}.'''  )
													elif isinstance(lowerCamelCase_       ,						lowerCamelCase_  ):
																		__magic_name__							:	List[Any]    							=							[negative_prompt]
													elif batch_size != len(lowerCamelCase_  ):
																		raise ValueError(
																		    F'''`negative_prompt`: {negative_prompt} has batch size {len(lowerCamelCase_  )}, but `prompt`:'''
																		    F''' {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches'''
																		    ''' the batch size of `prompt`.'''  )
													else:
																		__magic_name__							:	Optional[int]    							=							negative_prompt

													__magic_name__							:	Tuple    							=							text_input_ids.shape[-1]
													__magic_name__							:	List[str]    							=							self.tokenizer(
													    lowerCamelCase_       ,						padding='''max_length'''       ,						max_length=lowerCamelCase_       ,						truncation=lowerCamelCase_       ,						return_tensors='''pt'''       ,						)
													__magic_name__							:	Optional[Any]    							=							self.text_encoder(uncond_input.input_ids.to(self.device  )  )[0]

													# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
													__magic_name__							:	Optional[Any]    							=							uncond_embeddings.shape[1]
													__magic_name__							:	List[Any]    							=							uncond_embeddings.repeat(lowerCamelCase_       ,						lowerCamelCase_       ,						1  )
													__magic_name__							:	Tuple    							=							uncond_embeddings.view(batch_size * num_images_per_prompt       ,						lowerCamelCase_       ,						-1  )

													# For classifier free guidance, we need to do two forward passes.
													# Here we concatenate the unconditional and text embeddings into a single batch
													# to avoid doing two forward passes
													__magic_name__							:	int    							=							torch.cat([uncond_embeddings, text_embeddings]  )

								# get the initial random noise unless the user supplied it

								# Unlike in other pipelines, latents need to be generated in the target device
								# for 1-to-1 results reproducibility with the CompVis implementation.
								# However this currently doesn't work in `mps`.
								__magic_name__							:	Optional[Any]    							=							(batch_size * num_images_per_prompt, self.unet.config.in_channels, height // 8, width // 8)
								__magic_name__							:	Optional[Any]    							=							(batch_size * num_images_per_prompt, self.unet.config.in_channels, 64, 64)
								__magic_name__							:	List[str]    							=							text_embeddings.dtype
								if latents is None:
													if self.device.type == "mps":
																		# randn does not exist on mps
																		__magic_name__							:	List[Any]    							=							torch.randn(
																		    lowerCamelCase_       ,						generator=lowerCamelCase_       ,						device='''cpu'''       ,						dtype=lowerCamelCase_  ).to(self.device  )
																		__magic_name__							:	List[Any]    							=							torch.randn(lowerCamelCase_       ,						generator=lowerCamelCase_       ,						device='''cpu'''       ,						dtype=lowerCamelCase_  ).to(
																		    self.device  )
													else:
																		__magic_name__							:	Dict    							=							torch.randn(
																		    lowerCamelCase_       ,						generator=lowerCamelCase_       ,						device=self.device       ,						dtype=lowerCamelCase_  )
																		__magic_name__							:	Union[str, Any]    							=							torch.randn(lowerCamelCase_       ,						generator=lowerCamelCase_       ,						device=self.device       ,						dtype=lowerCamelCase_  )
								else:
													if latents_reference.shape != latents_shape:
																		raise ValueError(F'''Unexpected latents shape, got {latents.shape}, expected {latents_shape}'''  )
													__magic_name__							:	List[str]    							=							latents_reference.to(self.device  )
													__magic_name__							:	Optional[Any]    							=							latents.to(self.device  )

								# This is the key part of the pipeline where we
								# try to ensure that the generated images w/ the same seed
								# but different sizes actually result in similar images
								__magic_name__							:	List[str]    							=							(latents_shape[3] - latents_shape_reference[3]) // 2
								__magic_name__							:	Tuple    							=							(latents_shape[2] - latents_shape_reference[2]) // 2
								__magic_name__							:	Any    							=							latents_shape_reference[3] if dx >= 0 else latents_shape_reference[3] + 2 * dx
								__magic_name__							:	Dict    							=							latents_shape_reference[2] if dy >= 0 else latents_shape_reference[2] + 2 * dy
								__magic_name__							:	Union[str, Any]    							=							0 if dx < 0 else dx
								__magic_name__							:	List[str]    							=							0 if dy < 0 else dy
								__magic_name__							:	Union[str, Any]    							=							max(-dx       ,						0  )
								__magic_name__							:	Optional[int]    							=							max(-dy       ,						0  )
								# import pdb
								# pdb.set_trace()
								__magic_name__							:	List[str]    							=							latents_reference[:, :, dy : dy + h, dx : dx + w]

								# set timesteps
								self.scheduler.set_timesteps(lowerCamelCase_  )

								# Some schedulers like PNDM have timesteps as arrays
								# It's more optimized to move all timesteps to correct device beforehand
								__magic_name__							:	Dict    							=							self.scheduler.timesteps.to(self.device  )

								# scale the initial noise by the standard deviation required by the scheduler
								__magic_name__							:	Dict    							=							latents * self.scheduler.init_noise_sigma

								# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
								# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.
								# eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502
								# and should be between [0, 1]
								__magic_name__							:	Optional[int]    							=							'''eta''' in set(inspect.signature(self.scheduler.step  ).parameters.keys()  )
								__magic_name__							:	Any    							=							{}
								if accepts_eta:
													__magic_name__							:	str    							=							eta

								for i, t in enumerate(self.progress_bar(lowerCamelCase_  )  ):
													# expand the latents if we are doing classifier free guidance
													__magic_name__							:	Tuple    							=							torch.cat([latents] * 2  ) if do_classifier_free_guidance else latents
													__magic_name__							:	Union[str, Any]    							=							self.scheduler.scale_model_input(lowerCamelCase_       ,						lowerCamelCase_  )

													# predict the noise residual
													__magic_name__							:	Union[str, Any]    							=							self.unet(lowerCamelCase_       ,						lowerCamelCase_       ,						encoder_hidden_states=lowerCamelCase_  ).sample

													# perform guidance
													if do_classifier_free_guidance:
																		__magic_name__							,    __magic_name__							:	List[str]    							=							noise_pred.chunk(2  )
																		__magic_name__							:	Any    							=							noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)

													# compute the previous noisy sample x_t -> x_t-1
													__magic_name__							:	List[Any]    							=							self.scheduler.step(lowerCamelCase_       ,						lowerCamelCase_       ,						lowerCamelCase_       ,						**lowerCamelCase_  ).prev_sample

													# call the callback, if provided
													if callback is not None and i % callback_steps == 0:
																		callback(lowerCamelCase_       ,						lowerCamelCase_       ,						lowerCamelCase_  )

								__magic_name__							:	List[str]    							=							1 / 0.1_8_2_1_5 * latents
								__magic_name__							:	List[str]    							=							self.vae.decode(lowerCamelCase_  ).sample

								__magic_name__							:	Union[str, Any]    							=							(image / 2 + 0.5).clamp(0       ,						1  )

								# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
								__magic_name__							:	Any    							=							image.cpu().permute(0       ,						2       ,						3       ,						1  ).float().numpy()

								if self.safety_checker is not None:
													__magic_name__							:	Dict    							=							self.feature_extractor(self.numpy_to_pil(lowerCamelCase_  )       ,						return_tensors='''pt'''  ).to(
													    self.device  )
													__magic_name__							,    __magic_name__							:	List[Any]    							=							self.safety_checker(
													    images=lowerCamelCase_       ,						clip_input=safety_checker_input.pixel_values.to(text_embeddings.dtype  )  )
								else:
													__magic_name__							:	Any    							=							None

								if output_type == "pil":
													__magic_name__							:	List[Any]    							=							self.numpy_to_pil(lowerCamelCase_  )

								if not return_dict:
													return (image, has_nsfw_concept)

								return StableDiffusionPipelineOutput(images=lowerCamelCase_       ,						nsfw_content_detected=lowerCamelCase_  )









import json
import os
import shutil
import tempfile
import unittest

from transformers import BatchEncoding, CanineTokenizer
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.tokenization_utils import AddedToken
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


class    lowerCamelCase    (		_lowerCamelCase				,unittest.TestCase						):






			'''simple docstring'''





			UpperCamelCase__								=CanineTokenizer
			UpperCamelCase__								=False

			def 							UpperCAmelCase__       ( self			:   Tuple  )						->   List[str]:
								super().setUp()
								__magic_name__							:	Optional[int]    							=							CanineTokenizer()
								tokenizer.save_pretrained(self.tmpdirname  )

			@cached_property
			def 							UpperCAmelCase__       ( self			:   Optional[int]  )						->   Tuple:
								return CanineTokenizer.from_pretrained('''google/canine-s'''  )

			def 							UpperCAmelCase__       ( self			:   Dict       ,						**lowerCamelCase_			:   Optional[int]  )						->   CanineTokenizer:
								__magic_name__							:	int    							=							self.tokenizer_class.from_pretrained(self.tmpdirname       ,						**lowerCamelCase_  )
								__magic_name__							:	List[str]    							=							1024
								return tokenizer

			@require_torch
			def 							UpperCAmelCase__       ( self			:   int  )						->   int:
								__magic_name__							:	List[Any]    							=							self.canine_tokenizer
								__magic_name__							:	Any    							=							['''Life is like a box of chocolates.''', '''You never know what you\'re gonna get.''']
								# fmt: off
								__magic_name__							:	Optional[int]    							=							[57344, 76, 105, 102, 101, 32, 105, 115, 32, 108, 105, 107, 101, 32, 97, 32, 98, 111, 120, 32, 111, 102, 32, 99, 104, 111, 99, 111, 108, 97, 116, 101, 115, 46, 57345, 0, 0, 0, 0]
								# fmt: on
								__magic_name__							:	List[Any]    							=							tokenizer(lowerCamelCase_       ,						padding=lowerCamelCase_       ,						return_tensors='''pt'''  )
								self.assertIsInstance(lowerCamelCase_       ,						lowerCamelCase_  )

								__magic_name__							:	Tuple    							=							list(batch.input_ids.numpy()[0]  )

								self.assertListEqual(lowerCamelCase_       ,						lowerCamelCase_  )

								self.assertEqual((2, 39)       ,						batch.input_ids.shape  )
								self.assertEqual((2, 39)       ,						batch.attention_mask.shape  )

			@require_torch
			def 							UpperCAmelCase__       ( self			:   List[Any]  )						->   Optional[Any]:
								__magic_name__							:	Any    							=							self.canine_tokenizer
								__magic_name__							:	Dict    							=							['''Once there was a man.''', '''He wrote a test in HuggingFace Tranformers.''']
								__magic_name__							:	Dict    							=							tokenizer(lowerCamelCase_       ,						padding=lowerCamelCase_       ,						return_tensors='''pt'''  )
								# check if input_ids, attention_mask and token_type_ids are returned
								self.assertIn('''input_ids'''       ,						lowerCamelCase_  )
								self.assertIn('''attention_mask'''       ,						lowerCamelCase_  )
								self.assertIn('''token_type_ids'''       ,						lowerCamelCase_  )

			@require_torch
			def 							UpperCAmelCase__       ( self			:   int  )						->   Optional[int]:
								__magic_name__							:	int    							=							self.canine_tokenizer
								__magic_name__							:	Dict    							=							[
								    '''What\'s the weater?''',
								    '''It\'s about 25 degrees.''',
								]
								__magic_name__							:	List[Any]    							=							tokenizer(
								    text_target=lowerCamelCase_       ,						max_length=32       ,						padding='''max_length'''       ,						truncation=lowerCamelCase_       ,						return_tensors='''pt'''  )
								self.assertEqual(32       ,						targets['''input_ids'''].shape[1]  )

			def 							UpperCAmelCase__       ( self			:   Optional[Any]  )						->   Dict:
								# safety check on max_len default value so we are sure the test works
								__magic_name__							:	str    							=							self.get_tokenizers()
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		self.assertNotEqual(tokenizer.model_max_length       ,						42  )

        # Now let's start the test
								__magic_name__							:	Union[str, Any]    							=							self.get_tokenizers()
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		# Isolate this from the other tests because we save additional tokens/etc
																		__magic_name__							:	str    							=							tempfile.mkdtemp()

																		__magic_name__							:	Any    							=							''' He is very happy, UNwant\u00E9d,running'''
																		__magic_name__							:	str    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		tokenizer.save_pretrained(lowerCamelCase_  )

																		__magic_name__							:	str    							=							tokenizer.__class__.from_pretrained(lowerCamelCase_  )
																		__magic_name__							:	Tuple    							=							after_tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		self.assertListEqual(lowerCamelCase_       ,						lowerCamelCase_  )

																		shutil.rmtree(lowerCamelCase_  )

								__magic_name__							:	Any    							=							self.get_tokenizers(model_max_length=42  )
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		# Isolate this from the other tests because we save additional tokens/etc
																		__magic_name__							:	Any    							=							tempfile.mkdtemp()

																		__magic_name__							:	Any    							=							''' He is very happy, UNwant\u00E9d,running'''

																		__magic_name__							:	str    							=							tokenizer.additional_special_tokens

																		# We can add a new special token for Canine as follows:
																		__magic_name__							:	str    							=							chr(0XE007  )
																		additional_special_tokens.append(lowerCamelCase_  )
																		tokenizer.add_special_tokens({'''additional_special_tokens''': additional_special_tokens}  )
																		__magic_name__							:	Tuple    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		tokenizer.save_pretrained(lowerCamelCase_  )

																		__magic_name__							:	List[Any]    							=							tokenizer.__class__.from_pretrained(lowerCamelCase_  )
																		__magic_name__							:	Optional[int]    							=							after_tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		self.assertListEqual(lowerCamelCase_       ,						lowerCamelCase_  )
																		self.assertIn(lowerCamelCase_       ,						after_tokenizer.additional_special_tokens  )
																		self.assertEqual(after_tokenizer.model_max_length       ,						42  )

																		__magic_name__							:	List[Any]    							=							tokenizer.__class__.from_pretrained(lowerCamelCase_       ,						model_max_length=43  )
																		self.assertEqual(tokenizer.model_max_length       ,						43  )

																		shutil.rmtree(lowerCamelCase_  )

			def 							UpperCAmelCase__       ( self			:   int  )						->   Optional[int]:
								__magic_name__							:	Any    							=							self.get_tokenizers(do_lower_case=lowerCamelCase_  )
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		__magic_name__							,    __magic_name__							:	str    							=							self.get_clean_sequence(lowerCamelCase_  )

																		# a special token for Canine can be defined as follows:
																		__magic_name__							:	Optional[Any]    							=							0XE005
																		__magic_name__							:	Optional[Any]    							=							chr(lowerCamelCase_  )

																		tokenizer.add_special_tokens({'''cls_token''': special_token}  )
																		__magic_name__							:	Optional[int]    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		self.assertEqual(len(lowerCamelCase_  )       ,						1  )

																		__magic_name__							:	Union[str, Any]    							=							tokenizer.decode(ids + encoded_special_token       ,						clean_up_tokenization_spaces=lowerCamelCase_  )
																		__magic_name__							:	str    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )

																		__magic_name__							:	Optional[Any]    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		__magic_name__							:	Union[str, Any]    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		self.assertEqual(lowerCamelCase_       ,						input_encoded + special_token_id  )

																		__magic_name__							:	Any    							=							tokenizer.decode(lowerCamelCase_       ,						skip_special_tokens=lowerCamelCase_  )
																		self.assertTrue(special_token not in decoded  )

			def 							UpperCAmelCase__       ( self			:   Union[str, Any]  )						->   int:
								__magic_name__							:	str    							=							self.get_tokenizers(do_lower_case=lowerCamelCase_  )
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		__magic_name__							:	Tuple    							=							chr(0XE005  )
																		__magic_name__							:	Optional[int]    							=							chr(0XE006  )

																		# `add_tokens` method stores special tokens only in `tokenizer.unique_no_split_tokens`. (in tokenization_utils.py)
																		tokenizer.add_tokens([SPECIAL_TOKEN_1]       ,						special_tokens=lowerCamelCase_  )
																		# `add_special_tokens` method stores special tokens in `tokenizer.additional_special_tokens`,
																		# which also occur in `tokenizer.all_special_tokens`. (in tokenization_utils_base.py)
																		tokenizer.add_special_tokens({'''additional_special_tokens''': [SPECIAL_TOKEN_2]}  )

																		__magic_name__							:	List[str]    							=							tokenizer.tokenize(lowerCamelCase_  )
																		__magic_name__							:	Optional[int]    							=							tokenizer.tokenize(lowerCamelCase_  )

																		self.assertEqual(len(lowerCamelCase_  )       ,						1  )
																		self.assertEqual(len(lowerCamelCase_  )       ,						1  )
																		self.assertEqual(token_a[0]       ,						lowerCamelCase_  )
																		self.assertEqual(token_a[0]       ,						lowerCamelCase_  )

			@require_tokenizers
			def 							UpperCAmelCase__       ( self			:   str  )						->   List[str]:
								__magic_name__							:	List[Any]    							=							self.get_tokenizers(do_lower_case=lowerCamelCase_  )
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		# a special token for Canine can be defined as follows:
																		__magic_name__							:	str    							=							0XE006
																		__magic_name__							:	Optional[int]    							=							chr(lowerCamelCase_  )

																		__magic_name__							:	Optional[Any]    							=							AddedToken(lowerCamelCase_       ,						lstrip=lowerCamelCase_  )
																		tokenizer.add_special_tokens({'''additional_special_tokens''': [new_token]}  )

																		with tempfile.TemporaryDirectory() as tmp_dir_name:
																							tokenizer.save_pretrained(lowerCamelCase_  )
																							tokenizer.from_pretrained(lowerCamelCase_  )

			def 							UpperCAmelCase__       ( self			:   str  )						->   Optional[Any]:
								__magic_name__							:	Union[str, Any]    							=							[]
								if self.test_slow_tokenizer:
													tokenizer_list.append((self.tokenizer_class, self.get_tokenizer())  )

								if self.test_rust_tokenizer:
													tokenizer_list.append((self.rust_tokenizer_class, self.get_rust_tokenizer())  )

								for tokenizer_class, tokenizer_utils in tokenizer_list:
													with tempfile.TemporaryDirectory() as tmp_dir:
																		tokenizer_utils.save_pretrained(lowerCamelCase_  )

																		with open(os.path.join(lowerCamelCase_       ,						'''special_tokens_map.json'''  )       ,						encoding='''utf-8'''  ) as json_file:
																							__magic_name__							:	List[Any]    							=							json.load(lowerCamelCase_  )

																		with open(os.path.join(lowerCamelCase_       ,						'''tokenizer_config.json'''  )       ,						encoding='''utf-8'''  ) as json_file:
																							__magic_name__							:	int    							=							json.load(lowerCamelCase_  )

																		# a special token for Canine can be defined as follows:
																		__magic_name__							:	List[str]    							=							0XE006
																		__magic_name__							:	List[str]    							=							chr(lowerCamelCase_  )

																		__magic_name__							:	int    							=							[new_token_a]
																		__magic_name__							:	str    							=							[new_token_a]

																		with open(os.path.join(lowerCamelCase_       ,						'''special_tokens_map.json'''  )       ,						'''w'''       ,						encoding='''utf-8'''  ) as outfile:
																							json.dump(lowerCamelCase_       ,						lowerCamelCase_  )
																		with open(os.path.join(lowerCamelCase_       ,						'''tokenizer_config.json'''  )       ,						'''w'''       ,						encoding='''utf-8'''  ) as outfile:
																							json.dump(lowerCamelCase_       ,						lowerCamelCase_  )

																		# the following checks allow us to verify that our test works as expected, i.e. that the tokenizer takes
																		# into account the new value of additional_special_tokens given in the "tokenizer_config.json" and
																		# "special_tokens_map.json" files
																		__magic_name__							:	int    							=							tokenizer_class.from_pretrained(lowerCamelCase_       ,						extra_ids=0  )
																		self.assertIn(lowerCamelCase_       ,						tokenizer_without_change_in_init.additional_special_tokens  )
																		# self.assertIn("an_additional_special_token",tokenizer_without_change_in_init.get_vocab()) # ByT5Tokenization no vocab
																		self.assertEqual(
																		    [new_token_a]       ,						tokenizer_without_change_in_init.convert_ids_to_tokens(
																		        tokenizer_without_change_in_init.convert_tokens_to_ids([new_token_a]  )  )       ,						)

																		__magic_name__							:	Optional[int]    							=							0XE007
																		__magic_name__							:	List[str]    							=							chr(lowerCamelCase_  )
																		# Now we test that we can change the value of additional_special_tokens in the from_pretrained
																		__magic_name__							:	List[str]    							=							[AddedToken(lowerCamelCase_       ,						lstrip=lowerCamelCase_  )]
																		__magic_name__							:	str    							=							tokenizer_class.from_pretrained(
																		    lowerCamelCase_       ,						additional_special_tokens=lowerCamelCase_       ,						extra_ids=0  )

																		self.assertIn(lowerCamelCase_       ,						tokenizer.additional_special_tokens  )
																		# self.assertIn(new_token_2,tokenizer.get_vocab()) # ByT5Tokenization no vocab
																		self.assertEqual(
																		    [new_token_a]       ,						tokenizer.convert_ids_to_tokens(tokenizer.convert_tokens_to_ids([new_token_a]  )  )  )

			@require_tokenizers
			def 							UpperCAmelCase__       ( self			:   Any  )						->   List[str]:
								__magic_name__							:	Optional[int]    							=							self.get_tokenizers(do_lower_case=lowerCamelCase_  )
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		__magic_name__							:	Union[str, Any]    							=							'''hello world'''
																		if self.space_between_special_tokens:
																							__magic_name__							:	List[Any]    							=							'''[CLS] hello world [SEP]'''
																		else:
																							__magic_name__							:	List[str]    							=							input
																		__magic_name__							:	Dict    							=							tokenizer.encode(lowerCamelCase_       ,						add_special_tokens=lowerCamelCase_  )
																		__magic_name__							:	Union[str, Any]    							=							tokenizer.decode(lowerCamelCase_       ,						spaces_between_special_tokens=self.space_between_special_tokens  )
																		self.assertIn(lowerCamelCase_       ,						[output, output.lower()]  )

			def 							UpperCAmelCase__       ( self			:   List[str]  )						->   Optional[Any]:
								__magic_name__							:	Dict    							=							self.get_tokenizers()
								for tokenizer in tokenizers:
													with self.subTest(F'''{tokenizer.__class__.__name__}'''  ):
																		__magic_name__							:	str    							=							[
																		    '''bos_token''',
																		    '''eos_token''',
																		    '''unk_token''',
																		    '''sep_token''',
																		    '''pad_token''',
																		    '''cls_token''',
																		    '''mask_token''',
																		]

								__magic_name__							:	Any    							=							'''a'''
								__magic_name__							:	List[str]    							=							ord(lowerCamelCase_  )

								for attr in attributes_list:
													setattr(lowerCamelCase_       ,						attr + '''_id'''       ,						lowerCamelCase_  )
													self.assertEqual(getattr(lowerCamelCase_       ,						lowerCamelCase_  )       ,						lowerCamelCase_  )
													self.assertEqual(getattr(lowerCamelCase_       ,						attr + '''_id'''  )       ,						lowerCamelCase_  )

													setattr(lowerCamelCase_       ,						attr + '''_id'''       ,						lowerCamelCase_  )
													self.assertEqual(getattr(lowerCamelCase_       ,						lowerCamelCase_  )       ,						lowerCamelCase_  )
													self.assertEqual(getattr(lowerCamelCase_       ,						attr + '''_id'''  )       ,						lowerCamelCase_  )

								setattr(lowerCamelCase_       ,						'''additional_special_tokens_ids'''       ,						[]  )
								self.assertListEqual(getattr(lowerCamelCase_       ,						'''additional_special_tokens'''  )       ,						[]  )
								self.assertListEqual(getattr(lowerCamelCase_       ,						'''additional_special_tokens_ids'''  )       ,						[]  )

								__magic_name__							:	Any    							=							0XE006
								__magic_name__							:	str    							=							chr(lowerCamelCase_  )
								setattr(lowerCamelCase_       ,						'''additional_special_tokens_ids'''       ,						[additional_special_token_id]  )
								self.assertListEqual(getattr(lowerCamelCase_       ,						'''additional_special_tokens'''  )       ,						[additional_special_token]  )
								self.assertListEqual(getattr(lowerCamelCase_       ,						'''additional_special_tokens_ids'''  )       ,						[additional_special_token_id]  )

			def 							UpperCAmelCase__       ( self			:   List[Any]  )						->   Union[str, Any]:
								pass

			def 							UpperCAmelCase__       ( self			:   List[str]  )						->   Optional[int]:
								pass

			def 							UpperCAmelCase__       ( self			:   Tuple  )						->   Any:
								pass

			def 							UpperCAmelCase__       ( self			:   Union[str, Any]  )						->   Optional[Any]:
								pass

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

			def 							UpperCAmelCase__       ( self			:   Union[str, Any]  )						->   Optional[Any]:
								pass

			def 							UpperCAmelCase__       ( self			:   List[str]  )						->   Optional[Any]:
								pass


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



