

"""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


_UpperCamelCase		     =    False






class 			__a					(						unittest.TestCase       ):





       """simple docstring"""


       pass






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





       """simple docstring"""


       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

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






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[int] 			=				VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"   )
        # remove text_unet
        pipe.remove_unused_weights()
        pipe.to(snake_case   )
        pipe.set_progress_bar_config(disable=snake_case   )

        lowerCAmelCase__   :				Tuple 			=				"A painting of a squirrel eating a burger "
        lowerCAmelCase__   :				List[Any] 			=				torch.manual_seed(0   )
        lowerCAmelCase__   :				int 			=				pipe(
            prompt=snake_case			,					generator=snake_case			,					guidance_scale=7.5			,					num_inference_steps=2			,					output_type="numpy"   ).images

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

        lowerCAmelCase__   :				Optional[int] 			=				generator.manual_seed(0   )
        lowerCAmelCase__   :				Tuple 			=				pipe(
            prompt=snake_case			,					generator=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 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        lowerCAmelCase__   :				int 			=				VersatileDiffusionTextToImagePipeline.from_pretrained(
            "shi-labs/versatile-diffusion"			,					torch_dtype=torch.floataa   )
        pipe.to(snake_case   )
        pipe.set_progress_bar_config(disable=snake_case   )

        lowerCAmelCase__   :				Tuple 			=				"A painting of a squirrel eating a burger "
        lowerCAmelCase__   :				int 			=				torch.manual_seed(0   )
        lowerCAmelCase__   :				Optional[Any] 			=				pipe(
            prompt=snake_case			,					generator=snake_case			,					guidance_scale=7.5			,					num_inference_steps=50			,					output_type="numpy"   ).images

        lowerCAmelCase__   :				int 			=				image[0, 253:256, 253:256, -1]

        assert image.shape == (1, 512, 512, 3)
        lowerCAmelCase__   :				List[Any] 			=				np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778]   )

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









"""simple docstring"""

def       SCREAMING_SNAKE_CASE							( lowercase__					,					lowercase__   )			->						list:
 lowerCAmelCase__   :				List[str] 			=				len(lowercase__   )
 lowerCAmelCase__   :				Dict 			=				[]
 for i in range(len(lowercase__   ) - pat_len + 1   ):
  lowerCAmelCase__   :				Union[str, Any] 			=				True
  for j in range(lowercase__   ):
   if s[i + j] != pattern[j]:
    lowerCAmelCase__   :				int 			=				False
    break
  if match_found:
   position.append(lowercase__   )
 return position


if __name__ == "__main__":
    assert naive_pattern_search("""ABCDEFG""", """DE""") == [3]
    print(naive_pattern_search("""ABAAABCDBBABCDDEBCABC""", """ABC"""))






