




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


__a							     =					False

class     __a(	unittest.TestCase  ):






    """simple docstring"""





    pass


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






    """simple docstring"""





    def 				a__ ( self    )					->						Optional[int]:
         # clean up the VRAM after each test
         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()





    def 				a__ ( self    )					->						Dict:
         UpperCAmelCase_     :				Optional[Any]  =     VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion'''    )
         # remove text_unet
         pipe.remove_unused_weights()
         pipe.to(_SCREAMING_SNAKE_CASE    )
         pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				str  =     '''A painting of a squirrel eating a burger '''
         UpperCAmelCase_     :				Optional[Any]  =     torch.manual_seed(0    )
         UpperCAmelCase_     :				Dict  =     pipe(
             prompt=_SCREAMING_SNAKE_CASE  ,generator=_SCREAMING_SNAKE_CASE  ,guidance_scale=7.5  ,num_inference_steps=2  ,output_type='''numpy'''    ).images

         with tempfile.TemporaryDirectory() as tmpdirname:
              pipe.save_pretrained(_SCREAMING_SNAKE_CASE    )
              UpperCAmelCase_     :				str  =     VersatileDiffusionTextToImagePipeline.from_pretrained(_SCREAMING_SNAKE_CASE    )
         pipe.to(_SCREAMING_SNAKE_CASE    )
         pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				Any  =     generator.manual_seed(0    )
         UpperCAmelCase_     :				List[Any]  =     pipe(
             prompt=_SCREAMING_SNAKE_CASE  ,generator=_SCREAMING_SNAKE_CASE  ,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 				a__ ( self    )					->						List[Any]:
         UpperCAmelCase_     :				str  =     VersatileDiffusionTextToImagePipeline.from_pretrained(
             '''shi-labs/versatile-diffusion'''  ,torch_dtype=torch.floataa    )
         pipe.to(_SCREAMING_SNAKE_CASE    )
         pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				str  =     '''A painting of a squirrel eating a burger '''
         UpperCAmelCase_     :				str  =     torch.manual_seed(0    )
         UpperCAmelCase_     :				str  =     pipe(
             prompt=_SCREAMING_SNAKE_CASE  ,generator=_SCREAMING_SNAKE_CASE  ,guidance_scale=7.5  ,num_inference_steps=50  ,output_type='''numpy'''    ).images

         UpperCAmelCase_     :				str  =     image[0, 253:256, 253:256, -1]

         assert image.shape == (1, 512, 512, 3)
         UpperCAmelCase_     :				Optional[Any]  =     np.array([0.33_67, 0.31_69, 0.26_56, 0.38_70, 0.47_90, 0.37_96, 0.40_09, 0.48_78, 0.47_78]    )

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





def lowerCamelCase__  (     _lowercase					,		_lowercase ):

     '''simple docstring'''


     while a != 0:
          UpperCAmelCase_,       UpperCAmelCase_     :				Optional[int]  =     b % a, a
     return b







def lowerCamelCase__  (     _lowercase					,		_lowercase ):

     '''simple docstring'''


     if gcd(_lowercase					,		_lowercase ) != 1:
          UpperCAmelCase_     :				int  =     f'''mod inverse of {a!r} and {m!r} does not exist'''
          raise ValueError(_lowercase )
     UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_     :				Union[str, Any]  =     1, 0, a
     UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_     :				Dict  =     0, 1, m
     while va != 0:
          UpperCAmelCase_     :				List[Any]  =     ua // va
          UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_     :				Any  =     (ua - q * va), (ua - q * va), (ua - q * va), va, va, va
     return ua % m