

"""simple docstring"""




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_     :			Optional[Any]	  =			False


class 		_A       (			unittest.TestCase					):
      pass






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





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





      def 					_lowerCamelCase  (  self		)   ->					Any:
         lowerCamelCase__						=			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__		)

         lowerCamelCase__						=			"A painting of a squirrel eating a burger "
         lowerCamelCase__						=			torch.manual_seed(0		)
         lowerCamelCase__						=			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__		)
            lowerCamelCase__						=			VersatileDiffusionTextToImagePipeline.from_pretrained(SCREAMING_SNAKE_CASE__		)
         pipe.to(SCREAMING_SNAKE_CASE__		)
         pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__		)

         lowerCamelCase__						=			generator.manual_seed(0		)
         lowerCamelCase__						=			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 					_lowerCamelCase  (  self		)   ->					List[Any]:
         lowerCamelCase__						=			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__		)

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

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

         assert image.shape == (1, 512, 512, 3)
         lowerCamelCase__						=			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







"""simple docstring"""




from __future__ import annotations

from typing import Any



def 	UpperCAmelCase__   (				A__   )      ->      None:




   """simple docstring"""
   create_state_space_tree(A__	,    []	,    0   )



def 	UpperCAmelCase__   (				A__	,    A__	,    A__   )      ->      None:




   """simple docstring"""

   if index == len(A__   ):
      print(A__   )
      return

   create_state_space_tree(A__	,    A__	,    index + 1   )
   current_subsequence.append(sequence[index]   )
   create_state_space_tree(A__	,    A__	,    index + 1   )
   current_subsequence.pop()


if __name__ == "__main__":
     SCREAMING_SNAKE_CASE_     :			list[Any]	  =			[3, 1, 2, 4]
     generate_all_subsequences(seq)

     seq.clear()
     seq.extend(['''A''', '''B''', '''C'''])
     generate_all_subsequences(seq)




