



import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionInstructPixaPixPipeline,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.utils import floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()





class 					__lowerCAmelCase (     lowerCamelCase__       ,						lowerCamelCase__       ,						lowerCamelCase__       ,						unittest.TestCase       ):
				__lowerCamelCase =				StableDiffusionInstructPixaPixPipeline
				__lowerCamelCase =				TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''height''', '''width''', '''cross_attention_kwargs'''}
				__lowerCamelCase =				TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
				__lowerCamelCase =				IMAGE_TO_IMAGE_IMAGE_PARAMS
				__lowerCamelCase =				IMAGE_TO_IMAGE_IMAGE_PARAMS




				def 							snake_case   (							self		):



									"""simple docstring"""





									torch.manual_seed(0		)
									_lowerCAmelCase						=    UNetaDConditionModel(
									    block_out_channels=(32, 64)						,				layers_per_block=2						,				sample_size=32						,				in_channels=8						,				out_channels=4						,				down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")						,				up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")						,				cross_attention_dim=32						,				)
									_lowerCAmelCase						=    PNDMScheduler(skip_prk_steps=_snake_case		)
									torch.manual_seed(0		)
									_lowerCAmelCase						=    AutoencoderKL(
									    block_out_channels=[32, 64]						,				in_channels=3						,				out_channels=3						,				down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]						,				up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]						,				latent_channels=4						,				)
									torch.manual_seed(0		)
									_lowerCAmelCase						=    CLIPTextConfig(
									    bos_token_id=0						,				eos_token_id=2						,				hidden_size=32						,				intermediate_size=37						,				layer_norm_eps=1e-05						,				num_attention_heads=4						,				num_hidden_layers=5						,				pad_token_id=1						,				vocab_size=1000						,				)
									_lowerCAmelCase						=    CLIPTextModel(_snake_case		)
									_lowerCAmelCase						=    CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""		)

									_lowerCAmelCase						=    {
									    """unet""": unet,
									    """scheduler""": scheduler,
									    """vae""": vae,
									    """text_encoder""": text_encoder,
									    """tokenizer""": tokenizer,
									    """safety_checker""": None,
									    """feature_extractor""": None,
									}
									return components




				def 							snake_case   (							self						,				_snake_case						,				_snake_case=0		):



									"""simple docstring"""





									_lowerCAmelCase						=    floats_tensor((1, 3, 32, 32)						,				rng=random.Random(_snake_case		)		).to(_snake_case		)
									_lowerCAmelCase						=    image.cpu().permute(0						,				2						,				3						,				1		)[0]
									_lowerCAmelCase						=    Image.fromarray(np.uinta(_snake_case		)		).convert("""RGB"""		)
									if str(_snake_case		).startswith("""mps"""		):
														_lowerCAmelCase						=    torch.manual_seed(_snake_case		)
									else:
														_lowerCAmelCase						=    torch.Generator(device=_snake_case		).manual_seed(_snake_case		)
									_lowerCAmelCase						=    {
									    """prompt""": """A painting of a squirrel eating a burger""",
									    """image""": image,
									    """generator""": generator,
									    """num_inference_steps""": 2,
									    """guidance_scale""": 6.0,
									    """image_guidance_scale""": 1,
									    """output_type""": """numpy""",
									}
									return inputs




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    """cpu"""  # ensure determinism for the device-dependent torch.Generator
									_lowerCAmelCase						=    self.get_dummy_components()
									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline(**_snake_case		)
									_lowerCAmelCase						=    sd_pipe.to(_snake_case		)
									sd_pipe.set_progress_bar_config(disable=_snake_case		)

									_lowerCAmelCase						=    self.get_dummy_inputs(_snake_case		)
									_lowerCAmelCase						=    sd_pipe(**_snake_case		).images
									_lowerCAmelCase						=    image[0, -3:, -3:, -1]
									assert image.shape == (1, 32, 32, 3)
									_lowerCAmelCase						=    np.array([0.7526, 0.3750, 0.4547, 0.6117, 0.5866, 0.5016, 0.4327, 0.5642, 0.4815]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    """cpu"""  # ensure determinism for the device-dependent torch.Generator
									_lowerCAmelCase						=    self.get_dummy_components()
									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline(**_snake_case		)
									_lowerCAmelCase						=    sd_pipe.to(_snake_case		)
									sd_pipe.set_progress_bar_config(disable=_snake_case		)

									_lowerCAmelCase						=    self.get_dummy_inputs(_snake_case		)
									_lowerCAmelCase						=    """french fries"""
									_lowerCAmelCase						=    sd_pipe(**_snake_case						,				negative_prompt=_snake_case		)
									_lowerCAmelCase						=    output.images
									_lowerCAmelCase						=    image[0, -3:, -3:, -1]

									assert image.shape == (1, 32, 32, 3)
									_lowerCAmelCase						=    np.array([0.7511, 0.3642, 0.4553, 0.6236, 0.5797, 0.5013, 0.4343, 0.5611, 0.4831]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    """cpu"""  # ensure determinism for the device-dependent torch.Generator
									_lowerCAmelCase						=    self.get_dummy_components()
									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline(**_snake_case		)
									_lowerCAmelCase						=    sd_pipe.to(_snake_case		)
									sd_pipe.set_progress_bar_config(disable=_snake_case		)

									_lowerCAmelCase						=    self.get_dummy_inputs(_snake_case		)
									_lowerCAmelCase						=    [inputs["""prompt"""]] * 2

									_lowerCAmelCase						=    np.array(inputs["""image"""]		).astype(np.floataa		) / 255.0
									_lowerCAmelCase						=    torch.from_numpy(_snake_case		).unsqueeze(0		).to(_snake_case		)
									_lowerCAmelCase						=    image / 2 + 0.5
									_lowerCAmelCase						=    image.permute(0						,				3						,				1						,				2		)
									_lowerCAmelCase						=    image.repeat(2						,				1						,				1						,				1		)

									_lowerCAmelCase						=    sd_pipe(**_snake_case		).images
									_lowerCAmelCase						=    image[-1, -3:, -3:, -1]

									assert image.shape == (2, 32, 32, 3)
									_lowerCAmelCase						=    np.array([0.5812, 0.5748, 0.5222, 0.5908, 0.5695, 0.7174, 0.6804, 0.5523, 0.5579]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    """cpu"""  # ensure determinism for the device-dependent torch.Generator
									_lowerCAmelCase						=    self.get_dummy_components()
									_lowerCAmelCase						=    EulerAncestralDiscreteScheduler(
									    beta_start=0.0_0085						,				beta_end=0.012						,				beta_schedule="""scaled_linear"""		)
									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline(**_snake_case		)
									_lowerCAmelCase						=    sd_pipe.to(_snake_case		)
									sd_pipe.set_progress_bar_config(disable=_snake_case		)

									_lowerCAmelCase						=    self.get_dummy_inputs(_snake_case		)
									_lowerCAmelCase						=    sd_pipe(**_snake_case		).images
									_lowerCAmelCase						=    image[0, -3:, -3:, -1]

									_lowerCAmelCase						=    [round(_snake_case						,				4		) for x in image_slice.flatten().tolist()]
									print(""",""".join([str(_snake_case		) for x in slice]		)		)

									assert image.shape == (1, 32, 32, 3)
									_lowerCAmelCase						=    np.array([0.7417, 0.3842, 0.4732, 0.5776, 0.5891, 0.5139, 0.4052, 0.5673, 0.4986]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									super().test_inference_batch_single_identical(expected_max_diff=3e-3		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.get_dummy_components()
									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline(**_snake_case		)
									_lowerCAmelCase						=    VaeImageProcessor(do_resize=_snake_case						,				do_normalize=_snake_case		)
									_lowerCAmelCase						=    pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)

									_lowerCAmelCase						=    pipe(**self.get_dummy_inputs_by_type(_snake_case						,				input_image_type="""pt"""		)		)[0]

									_lowerCAmelCase						=    components["""vae"""]
									_lowerCAmelCase						=    self.get_dummy_inputs_by_type(_snake_case						,				input_image_type="""pt"""		)

									for image_param in self.image_latents_params:
														if image_param in inputs.keys():
																			_lowerCAmelCase						=    vae.encode(inputs[image_param]		).latent_dist.mode()

									_lowerCAmelCase						=    pipe(**_snake_case		)[0]

									_lowerCAmelCase						=    np.abs(out - out_latents_inputs		).max()
									self.assertLess(_snake_case						,				1e-4						,				"""passing latents as image input generate different result from passing image"""		)





@slow
@require_torch_gpu
class 					__lowerCAmelCase (     unittest.TestCase       ):




				def 							snake_case   (							self		):



									"""simple docstring"""





									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()




				def 							snake_case   (							self						,				_snake_case=0		):



									"""simple docstring"""





									_lowerCAmelCase						=    torch.manual_seed(_snake_case		)
									_lowerCAmelCase						=    load_image(
									    """https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_pix2pix/example.jpg"""		)
									_lowerCAmelCase						=    {
									    """prompt""": """turn him into a cyborg""",
									    """image""": image,
									    """generator""": generator,
									    """num_inference_steps""": 3,
									    """guidance_scale""": 7.5,
									    """image_guidance_scale""": 1.0,
									    """output_type""": """numpy""",
									}
									return inputs




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline.from_pretrained(
									    """timbrooks/instruct-pix2pix"""						,				safety_checker=_snake_case		)
									pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)
									pipe.enable_attention_slicing()

									_lowerCAmelCase						=    self.get_inputs()
									_lowerCAmelCase						=    pipe(**_snake_case		).images
									_lowerCAmelCase						=    image[0, -3:, -3:, -1].flatten()

									assert image.shape == (1, 512, 512, 3)
									_lowerCAmelCase						=    np.array([0.5902, 0.6015, 0.6027, 0.5983, 0.6092, 0.6061, 0.5765, 0.5785, 0.5555]		)

									assert np.abs(expected_slice - image_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline.from_pretrained(
									    """timbrooks/instruct-pix2pix"""						,				safety_checker=_snake_case		)
									_lowerCAmelCase						=    LMSDiscreteScheduler.from_config(pipe.scheduler.config		)
									pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)
									pipe.enable_attention_slicing()

									_lowerCAmelCase						=    self.get_inputs()
									_lowerCAmelCase						=    pipe(**_snake_case		).images
									_lowerCAmelCase						=    image[0, -3:, -3:, -1].flatten()

									assert image.shape == (1, 512, 512, 3)
									_lowerCAmelCase						=    np.array([0.6578, 0.6817, 0.6972, 0.6761, 0.6856, 0.6916, 0.6428, 0.6516, 0.6301]		)

									assert np.abs(expected_slice - image_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline.from_pretrained(
									    """timbrooks/instruct-pix2pix"""						,				safety_checker=_snake_case		)
									_lowerCAmelCase						=    DDIMScheduler.from_config(pipe.scheduler.config		)
									pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)
									pipe.enable_attention_slicing()

									_lowerCAmelCase						=    self.get_inputs()
									_lowerCAmelCase						=    pipe(**_snake_case		).images
									_lowerCAmelCase						=    image[0, -3:, -3:, -1].flatten()

									assert image.shape == (1, 512, 512, 3)
									_lowerCAmelCase						=    np.array([0.3828, 0.3834, 0.3818, 0.3792, 0.3865, 0.3752, 0.3792, 0.3847, 0.3753]		)

									assert np.abs(expected_slice - image_slice		).max() < 1e-3




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    0

									def callback_fn(_snake_case						,				_snake_case						,				_snake_case		) -> None:
														_lowerCAmelCase						=    True
														nonlocal number_of_steps
														number_of_steps += 1
														if step == 1:
																			_lowerCAmelCase						=    latents.detach().cpu().numpy()
																			assert latents.shape == (1, 4, 64, 64)
																			_lowerCAmelCase						=    latents[0, -3:, -3:, -1]
																			_lowerCAmelCase						=    np.array([-0.2463, -0.4644, -0.9756, 1.5176, 1.4414, 0.7866, 0.9897, 0.8521, 0.7983]		)

																			assert np.abs(latents_slice.flatten() - expected_slice		).max() < 5e-2
														elif step == 2:
																			_lowerCAmelCase						=    latents.detach().cpu().numpy()
																			assert latents.shape == (1, 4, 64, 64)
																			_lowerCAmelCase						=    latents[0, -3:, -3:, -1]
																			_lowerCAmelCase						=    np.array([-0.2644, -0.4626, -0.9653, 1.5176, 1.4551, 0.7686, 0.9805, 0.8452, 0.8115]		)

																			assert np.abs(latents_slice.flatten() - expected_slice		).max() < 5e-2

									_lowerCAmelCase						=    False

									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline.from_pretrained(
									    """timbrooks/instruct-pix2pix"""						,				safety_checker=_snake_case						,				torch_dtype=torch.floataa		)
									_lowerCAmelCase						=    pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)
									pipe.enable_attention_slicing()

									_lowerCAmelCase						=    self.get_inputs()
									pipe(**_snake_case						,				callback=_snake_case						,				callback_steps=1		)
									assert callback_fn.has_been_called
									assert number_of_steps == 3




				def 							snake_case   (							self		):



									"""simple docstring"""





									torch.cuda.empty_cache()
									torch.cuda.reset_max_memory_allocated()
									torch.cuda.reset_peak_memory_stats()

									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline.from_pretrained(
									    """timbrooks/instruct-pix2pix"""						,				safety_checker=_snake_case						,				torch_dtype=torch.floataa		)
									_lowerCAmelCase						=    pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)
									pipe.enable_attention_slicing(1		)
									pipe.enable_sequential_cpu_offload()

									_lowerCAmelCase						=    self.get_inputs()
									_lowerCAmelCase						=    pipe(**_snake_case		)

									_lowerCAmelCase						=    torch.cuda.max_memory_allocated()
									# make sure that less than 2.2 GB is allocated
									assert mem_bytes < 2.2 * 10**9




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.get_inputs()
									# resize to resolution that is divisible by 8 but not 16 or 32
									_lowerCAmelCase						=    inputs["""image"""].resize((504, 504)		)

									_lowerCAmelCase						=    """timbrooks/instruct-pix2pix"""
									_lowerCAmelCase						=    StableDiffusionInstructPixaPixPipeline.from_pretrained(
									    _snake_case						,				safety_checker=_snake_case						,				)
									pipe.to(_snake_case		)
									pipe.set_progress_bar_config(disable=_snake_case		)
									pipe.enable_attention_slicing()

									_lowerCAmelCase						=    pipe(**_snake_case		)
									_lowerCAmelCase						=    output.images[0]

									_lowerCAmelCase						=    image[255:258, 383:386, -1]

									assert image.shape == (504, 504, 3)
									_lowerCAmelCase						=    np.array([0.2726, 0.2529, 0.2664, 0.2655, 0.2641, 0.2642, 0.2591, 0.2649, 0.2590]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 5e-3





import unittest

from transformers import SPIECE_UNDERLINE, XLNetTokenizer, XLNetTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


lowercase__		:List[Any]   =    get_tests_dir("fixtures/test_sentencepiece.model")







@require_sentencepiece
@require_tokenizers
class 				lowercase		(					SCREAMING_SNAKE_CASE__       ,  unittest.TestCase		):
							lowercase_       :       str       					=XLNetTokenizer
							lowercase_       :       Dict       					=XLNetTokenizerFast
							lowercase_       :       str       					=True
							lowercase_       :       str       					=True




							def  A__      (				self):
												super().setUp()

												# We have a SentencePiece fixture for testing
												lowercase							=						XLNetTokenizer(A__   ,keep_accents=A__)
												tokenizer.sanitize_special_tokens()
												tokenizer.save_pretrained(self.tmpdirname)




							def  A__      (				self):
												lowercase							=						'''<s>'''
												lowercase							=						1

												self.assertEqual(self.get_tokenizer()._convert_token_to_id(A__)   ,A__)
												self.assertEqual(self.get_tokenizer()._convert_id_to_token(A__)   ,A__)




							def  A__      (				self):
												lowercase							=						list(self.get_tokenizer().get_vocab().keys())

												self.assertEqual(vocab_keys[0]   ,'''<unk>''')
												self.assertEqual(vocab_keys[1]   ,'''<s>''')
												self.assertEqual(vocab_keys[-1]   ,'''<eod>''')
												self.assertEqual(len(A__)   ,1_0_0_6)




							def  A__      (				self):
												self.assertEqual(self.get_tokenizer().vocab_size   ,1_0_0_0)




							def  A__      (				self):
												lowercase							=						XLNetTokenizer(A__   ,keep_accents=A__)

												lowercase							=						tokenizer.tokenize('''This is a test''')
												self.assertListEqual(A__   ,['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est'''])

												self.assertListEqual(tokenizer.convert_tokens_to_ids(A__)   ,[2_8_5, 4_6, 1_0, 1_7_0, 3_8_2])

												lowercase							=						tokenizer.tokenize('''I was born in 92000, and this is falsé.''')
												self.assertListEqual(
												    A__   ,[
												        SPIECE_UNDERLINE + '''I''',
												        SPIECE_UNDERLINE + '''was''',
												        SPIECE_UNDERLINE + '''b''',
												        '''or''',
												        '''n''',
												        SPIECE_UNDERLINE + '''in''',
												        SPIECE_UNDERLINE + '''''',
												        '''9''',
												        '''2''',
												        '''0''',
												        '''0''',
												        '''0''',
												        ''',''',
												        SPIECE_UNDERLINE + '''and''',
												        SPIECE_UNDERLINE + '''this''',
												        SPIECE_UNDERLINE + '''is''',
												        SPIECE_UNDERLINE + '''f''',
												        '''al''',
												        '''s''',
												        '''é''',
												        '''.''',
												    ]   ,)
												lowercase							=						tokenizer.convert_tokens_to_ids(A__)
												self.assertListEqual(A__   ,[8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 0, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 0, 4])

												lowercase							=						tokenizer.convert_ids_to_tokens(A__)
												self.assertListEqual(
												    A__   ,[
												        SPIECE_UNDERLINE + '''I''',
												        SPIECE_UNDERLINE + '''was''',
												        SPIECE_UNDERLINE + '''b''',
												        '''or''',
												        '''n''',
												        SPIECE_UNDERLINE + '''in''',
												        SPIECE_UNDERLINE + '''''',
												        '''<unk>''',
												        '''2''',
												        '''0''',
												        '''0''',
												        '''0''',
												        ''',''',
												        SPIECE_UNDERLINE + '''and''',
												        SPIECE_UNDERLINE + '''this''',
												        SPIECE_UNDERLINE + '''is''',
												        SPIECE_UNDERLINE + '''f''',
												        '''al''',
												        '''s''',
												        '''<unk>''',
												        '''.''',
												    ]   ,)




							def  A__      (				self):
												lowercase							=						XLNetTokenizer(A__   ,do_lower_case=A__)
												lowercase							=						tokenizer.tokenize('''I was born in 92000, and this is falsé.''')
												self.assertListEqual(
												    A__   ,[
												        SPIECE_UNDERLINE + '''''',
												        '''i''',
												        SPIECE_UNDERLINE + '''was''',
												        SPIECE_UNDERLINE + '''b''',
												        '''or''',
												        '''n''',
												        SPIECE_UNDERLINE + '''in''',
												        SPIECE_UNDERLINE + '''''',
												        '''9''',
												        '''2''',
												        '''0''',
												        '''0''',
												        '''0''',
												        ''',''',
												        SPIECE_UNDERLINE + '''and''',
												        SPIECE_UNDERLINE + '''this''',
												        SPIECE_UNDERLINE + '''is''',
												        SPIECE_UNDERLINE + '''f''',
												        '''al''',
												        '''se''',
												        '''.''',
												    ]   ,)
												self.assertListEqual(tokenizer.tokenize('''H\u00E9llo''')   ,['''▁he''', '''ll''', '''o'''])




							def  A__      (				self):
												lowercase							=						XLNetTokenizer(A__   ,do_lower_case=A__)
												lowercase							=						tokenizer.tokenize('''I was born in 92000, and this is falsé.''')
												self.assertListEqual(
												    A__   ,[
												        SPIECE_UNDERLINE + '''I''',
												        SPIECE_UNDERLINE + '''was''',
												        SPIECE_UNDERLINE + '''b''',
												        '''or''',
												        '''n''',
												        SPIECE_UNDERLINE + '''in''',
												        SPIECE_UNDERLINE + '''''',
												        '''9''',
												        '''2''',
												        '''0''',
												        '''0''',
												        '''0''',
												        ''',''',
												        SPIECE_UNDERLINE + '''and''',
												        SPIECE_UNDERLINE + '''this''',
												        SPIECE_UNDERLINE + '''is''',
												        SPIECE_UNDERLINE + '''f''',
												        '''al''',
												        '''se''',
												        '''.''',
												    ]   ,)




							@slow
							def  A__      (				self):
												lowercase							=						XLNetTokenizer.from_pretrained('''xlnet-base-cased''')

												lowercase							=						tokenizer.encode('''sequence builders'''   ,add_special_tokens=A__)
												lowercase							=						tokenizer.encode('''multi-sequence build'''   ,add_special_tokens=A__)

												lowercase							=						tokenizer.build_inputs_with_special_tokens(A__)
												lowercase							=						tokenizer.build_inputs_with_special_tokens(A__   ,A__)

												assert encoded_sentence == text + [4, 3]
												assert encoded_pair == text + [4] + text_a + [4, 3]





							@slow
							def  A__      (				self):
												# fmt: off
												lowercase							=						{'''input_ids''': [[1_7, 2_1_4_4_2, 2_7_0, 1_7, 1_0, 1_4_6_4_5, 3_1_8, 3_4, 1_7, 4_5_4_6, 3_1_4_5, 7_8_7, 1_3, 7_7_5_2, 2_2_0_1_8, 2_3, 2_1, 1_7, 4_5_4_6, 3_1_4_5, 7_8_7, 1_3, 3_3_5_2, 1_4_4_3_1, 1_3, 5_5_0_0, 1_1, 1_1_7_6, 5_8_0, 1_3, 1_6_8_1_9, 4_7_9_7, 2_3, 1_7, 1_0, 1_7_1_3_5, 6_5_8, 1_9, 4_5_7, 7_9_3_2, 1_3, 1_8_4, 1_9, 3_1_5_4, 1_7_1_3_5, 6_4_6_8, 1_9, 1_4_0_4, 1_2_2_6_9, 1_9, 4_2_2_9, 5_3_5_6, 1_6_2_6_4, 4_6, 1_9, 1_7, 2_0_5_4_5, 1_0_3_9_5, 9, 9, 9, 1_1, 2_8, 6_4_2_1, 9_5_3_1, 2_0_7_2_9, 1_7, 1_0, 3_5_3,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}  # noqa: E501
												# fmt: on

												self.tokenizer_integration_test_util(
												    expected_encoding=A__   ,model_name='''xlnet-base-cased'''   ,revision='''c841166438c31ec7ca9a106dee7bb312b73ae511'''   ,)




