



'''simple docstring'''



import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin






@skip_mps
class 			_SCREAMING_SNAKE_CASE				(lowercase__,	lowercase__,	unittest.TestCase      ):
			A__								=  IFSuperResolutionPipeline
			A__								=  TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
			A__								=  TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
			A__								=  PipelineTesterMixin.required_optional_params - {'latents'}



			def 				lowerCAmelCase (     self		:						Optional[int]			)      ->      List[str]:
							"""simple docstring"""





							return self._get_superresolution_dummy_components()



			def 				lowerCAmelCase (     self		:						Dict    ,			__UpperCamelCase		:						Optional[int]    ,			__UpperCamelCase		:						List[str]=0			)      ->      List[str]:
							"""simple docstring"""





							if str(__UpperCamelCase			).startswith('''mps'''			):
											snake_case__      :   Optional[Any]      =    torch.manual_seed(__UpperCamelCase			)
							else:
											snake_case__      :   Any      =    torch.Generator(device=__UpperCamelCase			).manual_seed(__UpperCamelCase			)

							snake_case__      :   Dict      =    floats_tensor((1, 3, 32, 32)    ,			rng=random.Random(__UpperCamelCase			)			).to(__UpperCamelCase			)

							snake_case__      :   List[Any]      =    {
							    '''prompt''': '''A painting of a squirrel eating a burger''',
							    '''image''': 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 				lowerCAmelCase (     self		:						str			)      ->      Any:
							"""simple docstring"""





							self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3			)



			def 				lowerCAmelCase (     self		:						Optional[Any]			)      ->      Union[str, Any]:
							"""simple docstring"""





							self._test_save_load_optional_components()



			@unittest.skipIf(torch_device != '''cuda'''    ,			reason='''float16 requires CUDA'''			)
			def 				lowerCAmelCase (     self		:						str			)      ->      List[Any]:
							"""simple docstring"""





							super().test_save_load_floataa(expected_max_diff=1e-1			)



			def 				lowerCAmelCase (     self		:						Tuple			)      ->      Optional[Any]:
							"""simple docstring"""





							self._test_attention_slicing_forward_pass(expected_max_diff=1e-2			)



			def 				lowerCAmelCase (     self		:						str			)      ->      Optional[int]:
							"""simple docstring"""





							self._test_save_load_local()







			def 				lowerCAmelCase (     self		:						Union[str, Any]			)      ->      Tuple:
							"""simple docstring"""





							self._test_inference_batch_single_identical(
							    expected_max_diff=1e-2    ,			)






import json
import os
import unittest

from transformers import HerbertTokenizer, HerbertTokenizerFast
from transformers.models.herbert.tokenization_herbert import VOCAB_FILES_NAMES
from transformers.testing_utils import get_tests_dir, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class  _lowerCamelCase			(lowerCamelCase							,					unittest.TestCase					):
     lowercase__				  =			HerbertTokenizer
     lowercase__				  =			HerbertTokenizerFast
     lowercase__				  =			True

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

            # Use a simpler test file without japanese/chinese characters
            with open(f'''{get_tests_dir()}/fixtures/sample_text_no_unicode.txt'''							,       encoding='utf-8'    ) as f_data:
                   __snake_case						       =   f_data.read().replace('\n\n'							,       '\n'    ).strip()

            __snake_case						       =   [
                '<s>',
                '</s>',
                'l',
                'o',
                'w',
                'e',
                'r',
                's',
                't',
                'i',
                'd',
                'n',
                'w</w>',
                'r</w>',
                't</w>',
                'lo',
                'low',
                'er</w>',
                'low</w>',
                'lowest</w>',
                'newer</w>',
                'wider</w>',
                ',</w>',
                '<unk>',
            ]
            __snake_case						       =   dict(zip(SCREAMING_SNAKE_CASE_							,       range(len(SCREAMING_SNAKE_CASE_    )    )    )    )
            __snake_case						       =   ['l o 123', 'lo w 1456', 'e r</w> 1789', '']

            __snake_case						       =   os.path.join(self.tmpdirname							,       VOCAB_FILES_NAMES['vocab_file']    )
            __snake_case						       =   os.path.join(self.tmpdirname							,       VOCAB_FILES_NAMES['merges_file']    )
            with open(self.vocab_file							,       'w'    ) as fp:
                   fp.write(json.dumps(SCREAMING_SNAKE_CASE_    )    )
            with open(self.merges_file							,       'w'    ) as fp:
                   fp.write('\n'.join(SCREAMING_SNAKE_CASE_    )    )

     def 						__lowerCamelCase				(  self							,       SCREAMING_SNAKE_CASE_    ):
            __snake_case						       =   'lower newer'
            __snake_case						       =   'lower newer'
            return input_text, output_text

     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   self.tokenizer_class(vocab_file=self.vocab_file							,       merges_file=self.merges_file    )

            __snake_case						       =   'lower'
            __snake_case						       =   ['low', 'er</w>']
            __snake_case						       =   tokenizer.tokenize(SCREAMING_SNAKE_CASE_    )
            self.assertListEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

            __snake_case						       =   tokens + ['<unk>']
            __snake_case						       =   [16, 17, 23]
            self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_    )							,       SCREAMING_SNAKE_CASE_    )

     def 						__lowerCamelCase				(  self    ):
            if not self.test_rust_tokenizer:
                   return

            __snake_case						       =   self.get_tokenizer()
            __snake_case						       =   self.get_rust_tokenizer()

            __snake_case						       =   'lower,newer'

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

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

            __snake_case						       =   self.get_rust_tokenizer()
            __snake_case						       =   tokenizer.encode(SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   rust_tokenizer.encode(SCREAMING_SNAKE_CASE_    )
            self.assertListEqual(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_    )

     @slow
     def 						__lowerCamelCase				(  self    ):
            __snake_case						       =   self.tokenizer_class.from_pretrained('allegro/herbert-base-cased'    )

            __snake_case						       =   tokenizer.encode('konstruowanie sekwencji'							,       add_special_tokens=SCREAMING_SNAKE_CASE_    )
            __snake_case						       =   tokenizer.encode('konstruowanie wielu sekwencji'							,       add_special_tokens=SCREAMING_SNAKE_CASE_    )

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

            assert encoded_sentence == [0] + text + [2]
            assert encoded_pair == [0] + text + [2] + text_a + [2]
