


"""simple docstring"""







import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class 			UpperCamelCase_     (			UpperCamelCase      ,  unittest.TestCase):

	"""simple docstring"""





	snake_case__    :  Optional[int]    =      None
	snake_case__    :  Optional[int]    =      BloomTokenizerFast
	snake_case__    :  Tuple    =      BloomTokenizerFast
	snake_case__    :  Union[str, Any]    =      True
	snake_case__    :  Optional[int]    =      False
	snake_case__    :  List[str]    =      "tokenizer_file"
	snake_case__    :  List[str]    =      {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>"}




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     Optional[int]:
						super().setUp()
						__SCREAMING_SNAKE_CASE						       =    BloomTokenizerFast.from_pretrained("bigscience/tokenizer"       )
						tokenizer.save_pretrained(self.tmpdirname       )




	def   UpperCAmelCase_				(			self      :    int      ,      **UpperCAmelCase__      :    Union[str, Any]       )	->     str:
						kwargs.update(self.special_tokens_map       )
						return BloomTokenizerFast.from_pretrained(self.tmpdirname      ,      **UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     Any:
						__SCREAMING_SNAKE_CASE						       =    self.get_rust_tokenizer()

						__SCREAMING_SNAKE_CASE						       =    ["The quick brown fox</s>", "jumps over the lazy dog</s>"]
						__SCREAMING_SNAKE_CASE						       =    [[2_1_7_5, 2_3_7_1_4, 7_3_1_7_3, 1_4_4_2_5_2, 2], [7_7, 1_3_2_6_1_9, 3_4_7_8, 3_6_8, 1_0_9_5_8_6, 3_5_4_3_3, 2]]

						__SCREAMING_SNAKE_CASE						       =    tokenizer.batch_encode_plus(UpperCAmelCase__       )["input_ids"]
						self.assertListEqual(UpperCAmelCase__      ,      UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    tokenizer.batch_decode(UpperCAmelCase__       )
						self.assertListEqual(UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    List[Any]      ,      UpperCAmelCase__      :    Union[str, Any]=6       )	->     List[str]:
						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
											with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""       ):
																__SCREAMING_SNAKE_CASE						       =    self.rust_tokenizer_class.from_pretrained(UpperCAmelCase__      ,      **UpperCAmelCase__       )
																# tokenizer_r.pad_token = None # Hotfixing padding = None
																# Simple input
																__SCREAMING_SNAKE_CASE						       =    "This is a simple input"
																__SCREAMING_SNAKE_CASE						       =    ["This is a simple input 1", "This is a simple input 2"]
																__SCREAMING_SNAKE_CASE						       =    ("This is a simple input", "This is a pair")
																__SCREAMING_SNAKE_CASE						       =    [
																    ("This is a simple input 1", "This is a simple input 2"),
																    ("This is a simple pair 1", "This is a simple pair 2"),
																]

																# Simple input tests
																try:
																					tokenizer_r.encode(UpperCAmelCase__      ,      max_length=UpperCAmelCase__       )
																					tokenizer_r.encode_plus(UpperCAmelCase__      ,      max_length=UpperCAmelCase__       )

																					tokenizer_r.batch_encode_plus(UpperCAmelCase__      ,      max_length=UpperCAmelCase__       )
																					tokenizer_r.encode(UpperCAmelCase__      ,      max_length=UpperCAmelCase__       )
																					tokenizer_r.batch_encode_plus(UpperCAmelCase__      ,      max_length=UpperCAmelCase__       )
																except ValueError:
																					self.fail("Bloom Tokenizer should be able to deal with padding"       )

																__SCREAMING_SNAKE_CASE						       =    None  # Hotfixing padding = None
																self.assertRaises(UpperCAmelCase__      ,      tokenizer_r.encode      ,      UpperCAmelCase__      ,      max_length=UpperCAmelCase__      ,      padding="max_length"       )

																# Simple input
																self.assertRaises(UpperCAmelCase__      ,      tokenizer_r.encode_plus      ,      UpperCAmelCase__      ,      max_length=UpperCAmelCase__      ,      padding="max_length"       )

																# Simple input
																self.assertRaises(
																    UpperCAmelCase__      ,      tokenizer_r.batch_encode_plus      ,      UpperCAmelCase__      ,      max_length=UpperCAmelCase__      ,      padding="max_length"      ,      )

																# Pair input
																self.assertRaises(UpperCAmelCase__      ,      tokenizer_r.encode      ,      UpperCAmelCase__      ,      max_length=UpperCAmelCase__      ,      padding="max_length"       )

																# Pair input
																self.assertRaises(UpperCAmelCase__      ,      tokenizer_r.encode_plus      ,      UpperCAmelCase__      ,      max_length=UpperCAmelCase__      ,      padding="max_length"       )

																# Pair input
																self.assertRaises(
																    UpperCAmelCase__      ,      tokenizer_r.batch_encode_plus      ,      UpperCAmelCase__      ,      max_length=UpperCAmelCase__      ,      padding="max_length"      ,      )




	def   UpperCAmelCase_				(			self      :    str       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    self.get_rust_tokenizer()
						__SCREAMING_SNAKE_CASE						       =    load_dataset("xnli"      ,      "all_languages"      ,      split="test"      ,      streaming=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    next(iter(UpperCAmelCase__       )       )["premise"]  # pick up one data
						__SCREAMING_SNAKE_CASE						       =    list(sample_data.values()       )

						__SCREAMING_SNAKE_CASE						       =    list(map(tokenizer.encode      ,      UpperCAmelCase__       )       )
						__SCREAMING_SNAKE_CASE						       =    [tokenizer.decode(UpperCAmelCase__      ,      clean_up_tokenization_spaces=UpperCAmelCase__       ) for x in output_tokens]
						self.assertListEqual(UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     int:
						# The test has to be overriden because BLOOM uses ALiBi positional embeddings that does not have
						# any sequence length constraints. This test of the parent class will fail since it relies on the
						# maximum sequence length of the positoonal embeddings.
						self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map       )      ,      1       )
						self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()       )[0]       )      ,      1       )




"""simple docstring"""







import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin




@skip_mps
class 			UpperCamelCase_     (			UpperCamelCase      ,  UpperCamelCase      ,  unittest.TestCase):

	"""simple docstring"""





	snake_case__    :  str    =      IFInpaintingSuperResolutionPipeline
	snake_case__    :  Optional[Any]    =      TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
	snake_case__    :  Union[str, Any]    =      TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"original_image"})
	snake_case__    :  Dict    =      PipelineTesterMixin.required_optional_params - {"latents"}




	def   UpperCAmelCase_				(			self      :    List[Any]       )	->     Optional[int]:
						return self._get_superresolution_dummy_components()




	def   UpperCAmelCase_				(			self      :    List[str]      ,      UpperCAmelCase__      :    List[Any]      ,      UpperCAmelCase__      :    List[str]=0       )	->     List[str]:
						if str(UpperCAmelCase__       ).startswith("mps"       ):
											__SCREAMING_SNAKE_CASE						       =    torch.manual_seed(UpperCAmelCase__       )
						else:
											__SCREAMING_SNAKE_CASE						       =    torch.Generator(device=UpperCAmelCase__       ).manual_seed(UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    floats_tensor((1, 3, 1_6, 1_6)      ,      rng=random.Random(UpperCAmelCase__       )       ).to(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    floats_tensor((1, 3, 3_2, 3_2)      ,      rng=random.Random(UpperCAmelCase__       )       ).to(UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    floats_tensor((1, 3, 3_2, 3_2)      ,      rng=random.Random(UpperCAmelCase__       )       ).to(UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    {
						    "prompt": "A painting of a squirrel eating a burger",
						    "image": image,
						    "original_image": original_image,
						    "mask_image": mask_image,
						    "generator": generator,
						    "num_inference_steps": 2,
						    "output_type": "numpy",
						}

						return inputs




	@unittest.skipIf(
	    torch_device != "cuda" or not is_xformers_available()      ,      reason="XFormers attention is only available with CUDA and `xformers` installed"      ,      )
	def   UpperCAmelCase_				(			self      :    str       )	->     Dict:
						self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3       )




	def   UpperCAmelCase_				(			self      :    str       )	->     Tuple:
						self._test_save_load_optional_components()




	@unittest.skipIf(torch_device != "cuda"      ,      reason="float16 requires CUDA"       )
	def   UpperCAmelCase_				(			self      :    Tuple       )	->     Tuple:
						# Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
						super().test_save_load_floataa(expected_max_diff=1E-1       )




	def   UpperCAmelCase_				(			self      :    Optional[Any]       )	->     List[Any]:
						self._test_attention_slicing_forward_pass(expected_max_diff=1E-2       )




	def   UpperCAmelCase_				(			self      :    Any       )	->     Union[str, Any]:
						self._test_save_load_local()




	def   UpperCAmelCase_				(			self      :    Union[str, Any]       )	->     Optional[Any]:
						self._test_inference_batch_single_identical(
						    expected_max_diff=1E-2      ,      )
