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: 
  
  
  from __future__ import annotations
  
  
  
  
  
  
  def 		_A		(		_lowercase   )				->   int | float:
  
  
       """simple docstring"""
  
  
       if len(_lowercase   ) == 0:
            raise ValueError('find_max() arg is an empty sequence'   )
       __UpperCamelCase   = nums[0]
       for x in nums:
            if x > max_num:
                 __UpperCamelCase   = x
       return max_num
  
  
  if __name__ == "__main__":
      import doctest
  
      doctest.testmod(verbose=True)
  
  
  