code: 
  
  
  import tempfile
  import unittest
  
  import numpy as np
  import torch
  
  from diffusers import DiffusionPipeline
  from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor
  
  
  
  class   __lowerCamelCase (unittest.TestCase	):
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   str,A_:   bool = False				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = 10
  
              if only_cross_attention:
                   __UpperCamelCase   = 12
              else:
                   # when only cross attention is not set, the cross attention dim must be the same as the query dim
                   __UpperCamelCase   = query_dim
  
              return {
                  "query_dim": query_dim,
                  "cross_attention_dim": cross_attention_dim,
                  "heads": 2,
                  "dim_head": 4,
                  "added_kv_proj_dim": 6,
                  "norm_num_groups": 1,
                  "only_cross_attention": only_cross_attention,
                  "processor": AttnAddedKVProcessor(),
              }
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Dict,A_:   Any,A_:   Any				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = 2
  
              __UpperCamelCase   = torch.rand(A_,A_,3,2				)
              __UpperCamelCase   = torch.rand(A_,4,A_				)
              __UpperCamelCase   = None
  
              return {
                  "hidden_states": hidden_states,
                  "encoder_hidden_states": encoder_hidden_states,
                  "attention_mask": attention_mask,
              }
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Optional[Any]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              torch.manual_seed(0				)
  
              __UpperCamelCase   = self.get_constructor_arguments(only_cross_attention=A_				)
              __UpperCamelCase   = Attention(**A_				)
  
              self.assertTrue(attn.to_k is not None				)
              self.assertTrue(attn.to_v is not None				)
  
              __UpperCamelCase   = self.get_forward_arguments(
                  query_dim=constructor_args['query_dim'],added_kv_proj_dim=constructor_args['added_kv_proj_dim']				)
  
              __UpperCamelCase   = attn(**A_				)
  
              # only self attention
  
              torch.manual_seed(0				)
  
              __UpperCamelCase   = self.get_constructor_arguments(only_cross_attention=A_				)
              __UpperCamelCase   = Attention(**A_				)
  
              self.assertTrue(attn.to_k is None				)
              self.assertTrue(attn.to_v is None				)
  
              __UpperCamelCase   = self.get_forward_arguments(
                  query_dim=constructor_args['query_dim'],added_kv_proj_dim=constructor_args['added_kv_proj_dim']				)
  
              __UpperCamelCase   = attn(**A_				)
  
              self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all()				)
  
  
  
  class   __lowerCamelCase (unittest.TestCase	):
  
  
  
  
  
  
  
         def 		snake_case_  ( self:   Optional[int]				):
  
  
  
  
  
  
              '''simple docstring'''
  
  
  
  
              __UpperCamelCase   = DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe',safety_checker=A_				)
  
              __UpperCamelCase   = pipe(
                  'foo',num_inference_steps=2,generator=torch.Generator('cpu'				).manual_seed(0				),output_type='np',).images
  
              # the initial conversion succeeds
              __UpperCamelCase   = DiffusionPipeline.from_pretrained(
                  'hf-internal-testing/tiny-stable-diffusion-pipe',device_map='sequential',safety_checker=A_				)
  
              __UpperCamelCase   = pipe(
                  'foo',num_inference_steps=2,generator=torch.Generator('cpu'				).manual_seed(0				),output_type='np',).images
  
              with tempfile.TemporaryDirectory() as tmpdir:
                   # save the converted model
                   pipe.save_pretrained(A_				)
  
                   # can also load the converted weights
                   __UpperCamelCase   = DiffusionPipeline.from_pretrained(A_,device_map='sequential',safety_checker=A_				)
  
              __UpperCamelCase   = pipe(
                  'foo',num_inference_steps=2,generator=torch.Generator('cpu'				).manual_seed(0				),output_type='np',).images
  
              self.assertTrue(np.allclose(A_,A_,atol=1E-5				)				)
              self.assertTrue(np.allclose(A_,A_,atol=1E-5				)				)
  
  
  
style_context: 
  
  
  import warnings
  from collections.abc import Callable
  from typing import Any
  
  import numpy
  from matplotlib import pyplot
  
  __snake_case             =	0.25 + 0.0j
  __snake_case             =	-0.4 + 0.6j
  __snake_case             =	-0.1 + 0.6_51j
  __snake_case             =	-2.0
  __snake_case             =	5_6
  __snake_case             =	2.0
  __snake_case             =	6_6_6
  
  
  
  
  
  
  def 		_A		(		_lowercase				,     _lowercase   )				->   numpy.ndarray:
  
  
       """simple docstring"""
  
  
       return numpy.exp(_lowercase   ) + c_parameter
  
  
  
  
  
  
  def 		_A		(		_lowercase				,     _lowercase   )				->   numpy.ndarray:
  
  
       """simple docstring"""
  
  
       return z_values * z_values + c_parameter
  
  
  
  
  
  
  def 		_A		(		_lowercase				,     _lowercase   )				->   numpy.ndarray:
  
  
       """simple docstring"""
  
  
       __UpperCamelCase   = numpy.linspace(-window_size				,     _lowercase				,     _lowercase   )
       __UpperCamelCase   = x.reshape((nb_pixels, 1)   )
       __UpperCamelCase   = numpy.linspace(-window_size				,     _lowercase				,     _lowercase   )
       __UpperCamelCase   = y.reshape((1, nb_pixels)   )
       return x + 1.0J * y
  
  
  
  
  
  
  def 		_A		(		_lowercase				,     _lowercase				,     _lowercase				,     _lowercase				,     _lowercase = None				,     )				->   numpy.ndarray:
  
  
       """simple docstring"""
  
  
       __UpperCamelCase   = z_a.astype('complex64'   )
       for _ in range(_lowercase   ):
            __UpperCamelCase   = eval_function(_lowercase				,     _lowercase   )
            if infinity is not None:
                 numpy.nan_to_num(_lowercase				,     copy=_lowercase				,     nan=_lowercase   )
                 __UpperCamelCase   = infinity
       return z_n
  
  
  
  
  
  
  def 		_A		(		_lowercase				,     _lowercase				,     _lowercase				,     _lowercase				,     )				->   None:
  
  
       """simple docstring"""
  
  
       __UpperCamelCase   = (abs(_lowercase   )).transpose()
       __UpperCamelCase   = abs_z_final[::-1, :]
       pyplot.matshow(abs_z_final < escape_radius   )
       pyplot.title(f'''Julia set of ${function_label}$, $c={function_params}$'''   )
       pyplot.show()
  
  
  
  
  
  
  def 		_A		(		)				->   None:
  
  
       """simple docstring"""
  
  
       warnings.filterwarnings(
           'ignore'				,     category=_lowercase				,     message='overflow encountered in multiply'   )
       warnings.filterwarnings(
           'ignore'				,     category=_lowercase				,     message='invalid value encountered in multiply'				,     )
       warnings.filterwarnings(
           'ignore'				,     category=_lowercase				,     message='overflow encountered in absolute'   )
       warnings.filterwarnings(
           'ignore'				,     category=_lowercase				,     message='overflow encountered in exp'   )
  
  
  if __name__ == "__main__":
      __snake_case             =	prepare_grid(window_size, nb_pixels)
  
      ignore_overflow_warnings()  # See file header for explanations
  
      __snake_case             =	2_4
      __snake_case             =	2 * abs(c_cauliflower) + 1
      __snake_case             =	iterate_function(
          eval_quadratic_polynomial,
          c_cauliflower,
          nb_iterations,
          z_a,
          infinity=1.1 * escape_radius,
      )
      show_results('''z^2+c''', c_cauliflower, escape_radius, z_final)
  
      __snake_case             =	6_4
      __snake_case             =	2 * abs(c_polynomial_a) + 1
      __snake_case             =	iterate_function(
          eval_quadratic_polynomial,
          c_polynomial_a,
          nb_iterations,
          z_a,
          infinity=1.1 * escape_radius,
      )
      show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)
  
      __snake_case             =	1_6_1
      __snake_case             =	2 * abs(c_polynomial_a) + 1
      __snake_case             =	iterate_function(
          eval_quadratic_polynomial,
          c_polynomial_a,
          nb_iterations,
          z_a,
          infinity=1.1 * escape_radius,
      )
      show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)
  
      __snake_case             =	1_2
      __snake_case             =	10_000.0
      __snake_case             =	iterate_function(
          eval_exponential,
          c_exponential,
          nb_iterations,
          z_a + 2,
          infinity=1.0e10,
      )
      show_results('''e^z+c''', c_exponential, escape_radius, z_final)
  
  
  