





import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


SCREAMING_SNAKE_CASE_						       =	False

class 		UpperCamelCase__			(				unittest.TestCase       ):



     '''simple docstring'''

     pass

@nightly
@require_torch_gpu
class 		UpperCamelCase__			(				unittest.TestCase       ):



     '''simple docstring'''

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




           '''simple docstring'''


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






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						VersatileDiffusionTextToImagePipeline.from_pretrained("""shi-labs/versatile-diffusion"""	)
           # remove text_unet
           pipe.remove_unused_weights()
           pipe.to(lowerCamelCase__	)
           pipe.set_progress_bar_config(disable=lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						"""A painting of a squirrel eating a burger """
           SCREAMING_SNAKE_CASE		=						torch.manual_seed(0	)
           SCREAMING_SNAKE_CASE		=						pipe(
               prompt=lowerCamelCase__						,generator=lowerCamelCase__						,guidance_scale=7.5						,num_inference_steps=2						,output_type="""numpy"""	).images

           with tempfile.TemporaryDirectory() as tmpdirname:
                 pipe.save_pretrained(lowerCamelCase__	)
                 SCREAMING_SNAKE_CASE		=						VersatileDiffusionTextToImagePipeline.from_pretrained(lowerCamelCase__	)
           pipe.to(lowerCamelCase__	)
           pipe.set_progress_bar_config(disable=lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						generator.manual_seed(0	)
           SCREAMING_SNAKE_CASE		=						pipe(
               prompt=lowerCamelCase__						,generator=lowerCamelCase__						,guidance_scale=7.5						,num_inference_steps=2						,output_type="""numpy"""	).images

           assert np.abs(image - new_image	).sum() < 1e-5, "Models don't have the same forward pass"






     def     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						VersatileDiffusionTextToImagePipeline.from_pretrained(
               """shi-labs/versatile-diffusion"""						,torch_dtype=torch.floataa	)
           pipe.to(lowerCamelCase__	)
           pipe.set_progress_bar_config(disable=lowerCamelCase__	)

           SCREAMING_SNAKE_CASE		=						"""A painting of a squirrel eating a burger """
           SCREAMING_SNAKE_CASE		=						torch.manual_seed(0	)
           SCREAMING_SNAKE_CASE		=						pipe(
               prompt=lowerCamelCase__						,generator=lowerCamelCase__						,guidance_scale=7.5						,num_inference_steps=50						,output_type="""numpy"""	).images

           SCREAMING_SNAKE_CASE		=						image[0, 253:256, 253:256, -1]

           assert image.shape == (1, 512, 512, 3)
           SCREAMING_SNAKE_CASE		=						np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]	)

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









from itertools import permutations



def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       bool:


      '''simple docstring'''


      if num[3] % 2 != 0:
            return False

      if (num[2] + num[3] + num[4]) % 3 != 0:
            return False

      if num[5] % 5 != 0:
            return False

      SCREAMING_SNAKE_CASE		=						[7, 11, 13, 17]
      for i, test in enumerate(_SCREAMING_SNAKE_CASE     ):
            if (num[i + 4] * 1_00 + num[i + 5] * 10 + num[i + 6]) % test != 0:
                  return False
      return True



def        __lowercase       (				_SCREAMING_SNAKE_CASE = 10     )			->       int:


      '''simple docstring'''


      return sum(
          int("""""".join(map(_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )     )     )
          for num in permutations(range(_SCREAMING_SNAKE_CASE     )     )
          if is_substring_divisible(_SCREAMING_SNAKE_CASE     )     )


if __name__ == "__main__":
      print(F'''{solution() = }''')


