

'''simple docstring'''





import unittest

from transformers import AlbertTokenizer, AlbertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


A_	= get_tests_dir("fixtures/spiece.model")


@require_sentencepiece
@require_tokenizers
class  UpperCAmelCase (							UpperCAmelCase__  , unittest.TestCase    ):

		'''simple docstring'''






		SCREAMING_SNAKE_CASE_           =					AlbertTokenizer
		SCREAMING_SNAKE_CASE_           =					AlbertTokenizerFast
		SCREAMING_SNAKE_CASE_           =					True
		SCREAMING_SNAKE_CASE_           =					True
		SCREAMING_SNAKE_CASE_           =					True
		def 			UpperCamelCase(					self		)  ->     Optional[Any]:






							'''simple docstring'''



							super().setUp()

							# We have a SentencePiece fixture for testing
							lowerCamelCase_  				=      AlbertTokenizer(SCREAMING_SNAKE_CASE_		)
							tokenizer.save_pretrained(self.tmpdirname		)
		def 			UpperCamelCase(					self   ,			SCREAMING_SNAKE_CASE_		)  ->     Tuple:






							'''simple docstring'''



							lowerCamelCase_  				=      'this is a test'
							lowerCamelCase_  				=      'this is a test'
							return input_text, output_text
		def 			UpperCamelCase(					self		)  ->     Optional[int]:






							'''simple docstring'''



							lowerCamelCase_  				=      '<pad>'
							lowerCamelCase_  				=      0

							self.assertEqual(self.get_tokenizer()._convert_token_to_id(SCREAMING_SNAKE_CASE_		)   ,			SCREAMING_SNAKE_CASE_		)
							self.assertEqual(self.get_tokenizer()._convert_id_to_token(SCREAMING_SNAKE_CASE_		)   ,			SCREAMING_SNAKE_CASE_		)
		def 			UpperCamelCase(					self		)  ->     List[Any]:






							'''simple docstring'''



							lowerCamelCase_  				=      list(self.get_tokenizer().get_vocab().keys()		)

							self.assertEqual(vocab_keys[0]   ,			'<pad>'		)
							self.assertEqual(vocab_keys[1]   ,			'<unk>'		)
							self.assertEqual(vocab_keys[-1]   ,			'▁eloquent'		)
							self.assertEqual(len(SCREAMING_SNAKE_CASE_		)   ,			30000		)
		def 			UpperCamelCase(					self		)  ->     List[Any]:






							'''simple docstring'''



							self.assertEqual(self.get_tokenizer().vocab_size   ,			30000		)
		def 			UpperCamelCase(					self		)  ->     Union[str, Any]:






							'''simple docstring'''



							if not self.test_rust_tokenizer:
												return

							lowerCamelCase_  				=      self.get_tokenizer()
							lowerCamelCase_  				=      self.get_rust_tokenizer()

							lowerCamelCase_  				=      'I was born in 92000, and this is falsé.'

							lowerCamelCase_  				=      tokenizer.tokenize(SCREAMING_SNAKE_CASE_		)
							lowerCamelCase_  				=      rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE_		)
							self.assertListEqual(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_		)

							lowerCamelCase_  				=      tokenizer.encode(SCREAMING_SNAKE_CASE_   ,			add_special_tokens=SCREAMING_SNAKE_CASE_		)
							lowerCamelCase_  				=      rust_tokenizer.encode(SCREAMING_SNAKE_CASE_   ,			add_special_tokens=SCREAMING_SNAKE_CASE_		)
							self.assertListEqual(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_		)

							lowerCamelCase_  				=      self.get_rust_tokenizer()
							lowerCamelCase_  				=      tokenizer.encode(SCREAMING_SNAKE_CASE_		)
							lowerCamelCase_  				=      rust_tokenizer.encode(SCREAMING_SNAKE_CASE_		)
							self.assertListEqual(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_		)
		def 			UpperCamelCase(					self		)  ->     List[Any]:






							'''simple docstring'''



							lowerCamelCase_  				=      AlbertTokenizer(SCREAMING_SNAKE_CASE_   ,			keep_accents=SCREAMING_SNAKE_CASE_		)

							lowerCamelCase_  				=      tokenizer.tokenize('This is a test'		)
							self.assertListEqual(SCREAMING_SNAKE_CASE_   ,			['▁this', '▁is', '▁a', '▁test']		)

							self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_		)   ,			[48, 25, 21, 1289]		)

							lowerCamelCase_  				=      tokenizer.tokenize('I was born in 92000, and this is falsé.'		)
							self.assertListEqual(
							    SCREAMING_SNAKE_CASE_   ,			['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', 'é', '.']		)
							lowerCamelCase_  				=      tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_		)
							self.assertListEqual(SCREAMING_SNAKE_CASE_   ,			[31, 23, 386, 19, 561, 3050, 15, 17, 48, 25, 8256, 18, 1, 9]		)

							lowerCamelCase_  				=      tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE_		)
							self.assertListEqual(
							    SCREAMING_SNAKE_CASE_   ,			['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.']   ,			)
		def 			UpperCamelCase(					self		)  ->     str:






							'''simple docstring'''



							lowerCamelCase_  				=      AlbertTokenizer(SCREAMING_SNAKE_CASE_		)

							lowerCamelCase_  				=      tokenizer.encode('sequence builders'		)
							lowerCamelCase_  				=      tokenizer.encode('multi-sequence build'		)

							lowerCamelCase_  				=      tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE_		)
							lowerCamelCase_  				=      tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE_   ,			SCREAMING_SNAKE_CASE_		)

							assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
							assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
							    tokenizer.sep_token_id
							]






		@slow
		def 			UpperCamelCase(					self		)  ->     Optional[int]:






							'''simple docstring'''



							lowerCamelCase_  				=      {'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'input_ids': [[2, 21970, 13, 5, 6092, 167, 28, 7103, 2153, 673, 8, 7028, 12051, 18, 17, 7103, 2153, 673, 8, 3515, 18684, 8, 4461, 6, 1927, 297, 8, 12060, 2607, 18, 13, 5, 4461, 15, 10538, 38, 8, 135, 15, 822, 58, 15, 993, 10363, 15, 1460, 8005, 4461, 15, 993, 255, 2328, 9, 9, 9, 6, 26, 1112, 816, 3260, 13, 5, 103, 2377, 6, 17, 1112, 816, 2782, 13, 5, 103, 10641, 6, 29, 84, 2512, 2430, 782, 18684, 2761, 19, 808, 2430, 2556, 17, 855, 1480, 9477, 4091, 128, 11712, 15, 7103, 2153, 673, 17, 24883, 9990, 9, 3], [2, 11502, 25, 1006, 20, 782, 8, 11809, 855, 1732, 19393, 18667, 37, 367, 21018, 69, 1854, 34, 11860, 19124, 27, 156, 225, 17, 193, 4141, 19, 65, 9124, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 14, 2231, 886, 2385, 17659, 84, 14, 16792, 1952, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'token_type_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
							# fmt: on

							self.tokenizer_integration_test_util(
							    expected_encoding=SCREAMING_SNAKE_CASE_   ,			model_name='albert-base-v2'   ,			revision='6b6560eaf5ff2e250b00c50f380c5389a9c2d82e'   ,			)










import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()




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


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



									"""simple docstring"""



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


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   StableDiffusionKDiffusionPipeline.from_pretrained("""CompVis/stable-diffusion-v1-4"""		)
									SCREAMING_SNAKE_CASE__								=   sd_pipe.to(__A		)
									sd_pipe.set_progress_bar_config(disable=__A		)

									sd_pipe.set_scheduler("""sample_euler"""		)

									SCREAMING_SNAKE_CASE__								=   """A painting of a squirrel eating a burger"""
									SCREAMING_SNAKE_CASE__								=   torch.manual_seed(0		)
									SCREAMING_SNAKE_CASE__								=   sd_pipe([prompt]				,					generator=__A				,					guidance_scale=9.0				,					num_inference_steps=20				,					output_type="""np"""		)

									SCREAMING_SNAKE_CASE__								=   output.images

									SCREAMING_SNAKE_CASE__								=   image[0, -3:, -3:, -1]

									assert image.shape == (1, 512, 512, 3)
									SCREAMING_SNAKE_CASE__								=   np.array([0.0_4_4_7, 0.0_4_9_2, 0.0_4_6_8, 0.0_4_0_8, 0.0_3_8_3, 0.0_4_0_8, 0.0_3_5_4, 0.0_3_8_0, 0.0_3_3_9]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 1E-2


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""		)
									SCREAMING_SNAKE_CASE__								=   sd_pipe.to(__A		)
									sd_pipe.set_progress_bar_config(disable=__A		)

									sd_pipe.set_scheduler("""sample_euler"""		)

									SCREAMING_SNAKE_CASE__								=   """A painting of a squirrel eating a burger"""
									SCREAMING_SNAKE_CASE__								=   torch.manual_seed(0		)
									SCREAMING_SNAKE_CASE__								=   sd_pipe([prompt]				,					generator=__A				,					guidance_scale=9.0				,					num_inference_steps=20				,					output_type="""np"""		)

									SCREAMING_SNAKE_CASE__								=   output.images

									SCREAMING_SNAKE_CASE__								=   image[0, -3:, -3:, -1]

									assert image.shape == (1, 512, 512, 3)
									SCREAMING_SNAKE_CASE__								=   np.array([0.1_2_3_7, 0.1_3_2_0, 0.1_4_3_8, 0.1_3_5_9, 0.1_3_9_0, 0.1_1_3_2, 0.1_2_7_7, 0.1_1_7_5, 0.1_1_1_2]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 5E-1


							def   _snake_case	(				self     :Tuple		) -> Optional[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""		)
									SCREAMING_SNAKE_CASE__								=   sd_pipe.to(__A		)
									sd_pipe.set_progress_bar_config(disable=__A		)

									sd_pipe.set_scheduler("""sample_dpmpp_2m"""		)

									SCREAMING_SNAKE_CASE__								=   """A painting of a squirrel eating a burger"""
									SCREAMING_SNAKE_CASE__								=   torch.manual_seed(0		)
									SCREAMING_SNAKE_CASE__								=   sd_pipe(
									    [prompt]				,					generator=__A				,					guidance_scale=7.5				,					num_inference_steps=15				,					output_type="""np"""				,					use_karras_sigmas=__A				,					)

									SCREAMING_SNAKE_CASE__								=   output.images

									SCREAMING_SNAKE_CASE__								=   image[0, -3:, -3:, -1]

									assert image.shape == (1, 512, 512, 3)
									SCREAMING_SNAKE_CASE__								=   np.array(
									    [0.1_1_3_8_1_6_8_9, 0.1_2_1_1_2_9_2_1, 0.1_3_8_9_4_5_7, 0.1_2_5_4_9_6_0_6, 0.1_2_4_4_9_6_4, 0.1_0_8_3_1_5_1_7, 0.1_1_5_6_2_8_6_6, 0.1_0_8_6_7_8_1_6, 0.1_0_4_9_9_0_4_8]		)

									assert np.abs(image_slice.flatten() - expected_slice		).max() < 1E-2