


from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload






class _lowerCamelCase:
       def __init__(					self,      lowerCamelCase = None)       ->   None:




           """simple docstring"""

           if components is None:
               _lowercase       :							Tuple      		=		[]
           _lowercase       :							Any      		=		list(lowerCamelCase)
       def __len__(					self)       ->   int:




           """simple docstring"""

           return len(self.__components)
       def __str__(					self)       ->   str:




           """simple docstring"""

           return "(" + ",".join(map(lowerCamelCase,      self.__components)) + ")"
       def __add__(					self,      lowerCamelCase)       ->   Vector:




           """simple docstring"""

           _lowercase       :							str      		=		len(self)
           if size == len(lowerCamelCase):
               _lowercase       :							Any      		=		[self.__components[i] + other.component(lowerCamelCase) for i in range(lowerCamelCase)]
               return Vector(lowerCamelCase)
           else:
               raise Exception('must have the same size')
       def __sub__(					self,      lowerCamelCase)       ->   Vector:




           """simple docstring"""

           _lowercase       :							Optional[Any]      		=		len(self)
           if size == len(lowerCamelCase):
               _lowercase       :							Optional[int]      		=		[self.__components[i] - other.component(lowerCamelCase) for i in range(lowerCamelCase)]
               return Vector(lowerCamelCase)
           else:  # error case
               raise Exception('must have the same size')
       @overload
       def __mul__(					self,      lowerCamelCase)       ->   Vector:




           """simple docstring"""

           ...
       @overload
       def __mul__(					self,      lowerCamelCase)       ->   float:




           """simple docstring"""

           ...
       def __mul__(					self,      lowerCamelCase)       ->   float | Vector:




           """simple docstring"""

           if isinstance(lowerCamelCase,      (float, int)):
               _lowercase       :							Dict      		=		[c * other for c in self.__components]
               return Vector(lowerCamelCase)
           elif isinstance(lowerCamelCase,      lowerCamelCase) and len(self) == len(lowerCamelCase):
               _lowercase       :							Any      		=		len(self)
               _lowercase       :							Any      		=		[self.__components[i] * other.component(lowerCamelCase) for i in range(lowerCamelCase)]
               return sum(lowerCamelCase)
           else:  # error case
               raise Exception('invalid operand!')
       def 			UpperCamelCase     (					self)       ->   Vector:




           """simple docstring"""

           return Vector(self.__components)
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   float:




           """simple docstring"""

           if isinstance(lowerCamelCase,      lowerCamelCase) and -len(self.__components) <= i < len(self.__components):
               return self.__components[i]
           else:
               raise Exception('index out of range')
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase)       ->   None:




           """simple docstring"""

           assert -len(self.__components) <= pos < len(self.__components)
           _lowercase       :							Optional[Any]      		=		value
       def 			UpperCamelCase     (					self)       ->   float:




           """simple docstring"""

           if len(self.__components) == 0:
               raise Exception('Vector is empty')
           _lowercase       :							Dict      		=		[c**2 for c in self.__components]
           return math.sqrt(sum(lowerCamelCase))




       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase = False)       ->   float:




           """simple docstring"""

           _lowercase       :							Optional[Any]      		=		self * other
           _lowercase       :							str      		=		self.euclidean_length() * other.euclidean_length()
           if deg:
               return math.degrees(math.acos(num / den))
           else:
               return math.acos(num / den)



def 				UpperCamelCase_(      lowerCamelCase_ )    ->						Vector:
    assert isinstance(lowerCamelCase_							, lowerCamelCase_ )
    return Vector([0] * dimension )



def 				UpperCamelCase_(      lowerCamelCase_							, lowerCamelCase_ )    ->						Vector:
    assert isinstance(lowerCamelCase_							, lowerCamelCase_ ) and (isinstance(lowerCamelCase_							, lowerCamelCase_ ))
    _lowercase       :							str      		=		[0] * dimension
    _lowercase       :							Dict      		=		1
    return Vector(lowerCamelCase_ )



def 				UpperCamelCase_(      lowerCamelCase_							, lowerCamelCase_							, lowerCamelCase_ )    ->						Vector:
    assert (
        isinstance(lowerCamelCase_							, lowerCamelCase_ )
        and isinstance(lowerCamelCase_							, lowerCamelCase_ )
        and (isinstance(lowerCamelCase_							, (int, float) ))
    )
    return x * scalar + y



def 				UpperCamelCase_(      lowerCamelCase_							, lowerCamelCase_							, lowerCamelCase_ )    ->						Vector:
    random.seed(lowerCamelCase_ )
    _lowercase       :							str      		=		[random.randint(lowerCamelCase_							, lowerCamelCase_ ) for _ in range(lowerCamelCase_ )]
    return Vector(lowerCamelCase_ )






class _lowerCamelCase:
       def __init__(					self,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase)       ->   None:




           """simple docstring"""

           _lowercase       :							Dict      		=		matrix
           _lowercase       :							Optional[int]      		=		w
           _lowercase       :							Optional[int]      		=		h
       def __str__(					self)       ->   str:




           """simple docstring"""

           _lowercase       :							Any      		=		''
           for i in range(self.__height):
               ans += "|"
               for j in range(self.__width):
                   if j < self.__width - 1:
                       ans += str(self.__matrix[i][j]) + ","
                   else:
                       ans += str(self.__matrix[i][j]) + "|\n"
           return ans
       def __add__(					self,      lowerCamelCase)       ->   Matrix:




           """simple docstring"""

           if self.__width == other.width() and self.__height == other.height():
               _lowercase       :							int      		=		[]
               for i in range(self.__height):
                   _lowercase       :							Dict      		=		[
                       self.__matrix[i][j] + other.component(lowerCamelCase,      lowerCamelCase)
                       for j in range(self.__width)
                   ]
                   matrix.append(lowerCamelCase)
               return Matrix(lowerCamelCase,      self.__width,      self.__height)
           else:
               raise Exception('matrix must have the same dimension!')
       def __sub__(					self,      lowerCamelCase)       ->   Matrix:




           """simple docstring"""

           if self.__width == other.width() and self.__height == other.height():
               _lowercase       :							Tuple      		=		[]
               for i in range(self.__height):
                   _lowercase       :							Union[str, Any]      		=		[
                       self.__matrix[i][j] - other.component(lowerCamelCase,      lowerCamelCase)
                       for j in range(self.__width)
                   ]
                   matrix.append(lowerCamelCase)
               return Matrix(lowerCamelCase,      self.__width,      self.__height)
           else:
               raise Exception('matrices must have the same dimension!')
       @overload
       def __mul__(					self,      lowerCamelCase)       ->   Matrix:




           """simple docstring"""

           ...
       @overload
       def __mul__(					self,      lowerCamelCase)       ->   Vector:




           """simple docstring"""

           ...
       def __mul__(					self,      lowerCamelCase)       ->   Vector | Matrix:




           """simple docstring"""

           if isinstance(lowerCamelCase,      lowerCamelCase):  # matrix-vector
               if len(lowerCamelCase) == self.__width:
                   _lowercase       :							int      		=		zero_vector(self.__height)
                   for i in range(self.__height):
                       _lowercase       :							Dict      		=		[
                           self.__matrix[i][j] * other.component(lowerCamelCase)
                           for j in range(self.__width)
                       ]
                       ans.change_component(lowerCamelCase,      sum(lowerCamelCase))
                   return ans
               else:
                   raise Exception(
                       'vector must have the same size as the '
                       'number of columns of the matrix!')
           elif isinstance(lowerCamelCase,      (int, float)):  # matrix-scalar
               _lowercase       :							List[str]      		=		[
                   [self.__matrix[i][j] * other for j in range(self.__width)]
                   for i in range(self.__height)
               ]
               return Matrix(lowerCamelCase,      self.__width,      self.__height)
           return None
       def 			UpperCamelCase     (					self)       ->   int:




           """simple docstring"""

           return self.__height
       def 			UpperCamelCase     (					self)       ->   int:




           """simple docstring"""

           return self.__width
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase)       ->   float:




           """simple docstring"""

           if 0 <= x < self.__height and 0 <= y < self.__width:
               return self.__matrix[x][y]
           else:
               raise Exception('change_component: indices out of bounds')
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase)       ->   None:




           """simple docstring"""

           if 0 <= x < self.__height and 0 <= y < self.__width:
               _lowercase       :							Any      		=		value
           else:
               raise Exception('change_component: indices out of bounds')
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase)       ->   float:




           """simple docstring"""

           if self.__height != self.__width:
               raise Exception('Matrix is not square')
           _lowercase       :							Union[str, Any]      		=		self.__matrix[:x] + self.__matrix[x + 1 :]
           for i in range(len(lowerCamelCase)):
               _lowercase       :							Optional[int]      		=		minor[i][:y] + minor[i][y + 1 :]
           return Matrix(lowerCamelCase,      self.__width - 1,      self.__height - 1).determinant()
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase)       ->   float:




           """simple docstring"""

           if self.__height != self.__width:
               raise Exception('Matrix is not square')
           if 0 <= x < self.__height and 0 <= y < self.__width:
               return (-1) ** (x + y) * self.minor(lowerCamelCase,      lowerCamelCase)
           else:
               raise Exception('Indices out of bounds')




       def 			UpperCamelCase     (					self)       ->   float:




           """simple docstring"""

           if self.__height != self.__width:
               raise Exception('Matrix is not square')
           if self.__height < 1:
               raise Exception('Matrix has no element')
           elif self.__height == 1:
               return self.__matrix[0][0]
           elif self.__height == 2:
               return (
                   self.__matrix[0][0] * self.__matrix[1][1]
                   - self.__matrix[0][1] * self.__matrix[1][0]
               )
           else:
               _lowercase       :							List[Any]      		=		[
                   self.__matrix[0][y] * self.cofactor(0,      lowerCamelCase) for y in range(self.__width)
               ]
               return sum(lowerCamelCase)



def 				UpperCamelCase_(      lowerCamelCase_ )    ->						Matrix:
    _lowercase       :							list[list[float]]      		=		[[0] * n for _ in range(lowerCamelCase_ )]
    return Matrix(lowerCamelCase_							, lowerCamelCase_							, lowerCamelCase_ )



def 				UpperCamelCase_(      lowerCamelCase_							, lowerCamelCase_							, lowerCamelCase_							, lowerCamelCase_ )    ->						Matrix:
    random.seed(lowerCamelCase_ )
    _lowercase       :							list[list[float]]      		=		[
        [random.randint(lowerCamelCase_							, lowerCamelCase_ ) for _ in range(lowerCamelCase_ )] for _ in range(lowerCamelCase_ )
    ]
    return Matrix(lowerCamelCase_							, lowerCamelCase_							, lowerCamelCase_ )






import gc
import unittest

import numpy as np
import torch
from torch.backends.cuda import sdp_kernel

from diffusers import (
    CMStochasticIterativeScheduler,
    ConsistencyModelPipeline,
    UNetaDModel,
)
from diffusers.utils import randn_tensor, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_a, require_torch_gpu

from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()






class _lowerCamelCase(						_a, unittest.TestCase   ):
       lowercase_ :	Union[str, Any]     =			ConsistencyModelPipeline
       lowercase_ :	Tuple     =			UNCONDITIONAL_IMAGE_GENERATION_PARAMS
       lowercase_ :	List[str]     =			UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS

       # Override required_optional_params to remove num_images_per_prompt
       lowercase_ :	List[str]     =			frozenset(
           [
               """num_inference_steps""",
               """generator""",
               """latents""",
               """output_type""",
               """return_dict""",
               """callback""",
               """callback_steps""",
           ]   )
       @property
       def 			UpperCamelCase     (					self)       ->   Tuple:




           """simple docstring"""

           _lowercase       :							Tuple      		=		UNetaDModel.from_pretrained(
               'diffusers/consistency-models-test',      subfolder='test_unet',      )
           return unet
       @property
       def 			UpperCamelCase     (					self)       ->   List[Any]:




           """simple docstring"""

           _lowercase       :							Tuple      		=		UNetaDModel.from_pretrained(
               'diffusers/consistency-models-test',      subfolder='test_unet_class_cond',      )
           return unet
       def 			UpperCamelCase     (					self,      lowerCamelCase=False)       ->   Dict:




           """simple docstring"""

           if class_cond:
               _lowercase       :							Union[str, Any]      		=		self.dummy_cond_unet
           else:
               _lowercase       :							Union[str, Any]      		=		self.dummy_uncond_unet

           # Default to CM multistep sampler
           _lowercase       :							List[str]      		=		CMStochasticIterativeScheduler(
               num_train_timesteps=40,      sigma_min=0.0_0_2,      sigma_max=8_0.0,      )

           _lowercase       :							Optional[Any]      		=		{
               'unet': unet,
               'scheduler': scheduler,
           }

           return components
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase=0)       ->   Tuple:




           """simple docstring"""

           if str(lowerCamelCase).startswith('mps'):
               _lowercase       :							str      		=		torch.manual_seed(lowerCamelCase)
           else:
               _lowercase       :							int      		=		torch.Generator(device=lowerCamelCase).manual_seed(lowerCamelCase)

           _lowercase       :							Tuple      		=		{
               'batch_size': 1,
               'num_inference_steps': None,
               'timesteps': [22, 0],
               'generator': generator,
               'output_type': 'np',
           }

           return inputs
       def 			UpperCamelCase     (					self)       ->   Any:




           """simple docstring"""

           _lowercase       :							Optional[int]      		=		'cpu'  # ensure determinism for the device-dependent torch.Generator
           _lowercase       :							Optional[int]      		=		self.get_dummy_components()
           _lowercase       :							str      		=		ConsistencyModelPipeline(**lowerCamelCase)
           _lowercase       :							Dict      		=		pipe.to(lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							Tuple      		=		self.get_dummy_inputs(lowerCamelCase)
           _lowercase       :							Optional[int]      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 32, 32, 3)

           _lowercase       :							int      		=		image[0, -3:, -3:, -1]
           _lowercase       :							Dict      		=		np.array([0.3_5_7_2, 0.6_2_7_3, 0.4_0_3_1, 0.3_9_6_1, 0.4_3_2_1, 0.5_7_3_0, 0.5_2_6_6, 0.4_7_8_0, 0.5_0_0_4])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3
       def 			UpperCamelCase     (					self)       ->   Any:




           """simple docstring"""

           _lowercase       :							Union[str, Any]      		=		'cpu'  # ensure determinism for the device-dependent torch.Generator
           _lowercase       :							Dict      		=		self.get_dummy_components(class_cond=lowerCamelCase)
           _lowercase       :							Any      		=		ConsistencyModelPipeline(**lowerCamelCase)
           _lowercase       :							str      		=		pipe.to(lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							Any      		=		self.get_dummy_inputs(lowerCamelCase)
           _lowercase       :							Any      		=		0
           _lowercase       :							List[str]      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 32, 32, 3)

           _lowercase       :							Any      		=		image[0, -3:, -3:, -1]
           _lowercase       :							Union[str, Any]      		=		np.array([0.3_5_7_2, 0.6_2_7_3, 0.4_0_3_1, 0.3_9_6_1, 0.4_3_2_1, 0.5_7_3_0, 0.5_2_6_6, 0.4_7_8_0, 0.5_0_0_4])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3
       def 			UpperCamelCase     (					self)       ->   Tuple:




           """simple docstring"""

           _lowercase       :							Optional[int]      		=		'cpu'  # ensure determinism for the device-dependent torch.Generator
           _lowercase       :							Any      		=		self.get_dummy_components()
           _lowercase       :							Optional[Any]      		=		ConsistencyModelPipeline(**lowerCamelCase)
           _lowercase       :							List[str]      		=		pipe.to(lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							Optional[Any]      		=		self.get_dummy_inputs(lowerCamelCase)
           _lowercase       :							Union[str, Any]      		=		1
           _lowercase       :							Tuple      		=		None
           _lowercase       :							Tuple      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 32, 32, 3)

           _lowercase       :							str      		=		image[0, -3:, -3:, -1]
           _lowercase       :							List[str]      		=		np.array([0.5_0_0_4, 0.5_0_0_4, 0.4_9_9_4, 0.5_0_0_8, 0.4_9_7_6, 0.5_0_1_8, 0.4_9_9_0, 0.4_9_8_2, 0.4_9_8_7])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3




       def 			UpperCamelCase     (					self)       ->   str:




           """simple docstring"""

           _lowercase       :							Union[str, Any]      		=		'cpu'  # ensure determinism for the device-dependent torch.Generator
           _lowercase       :							Dict      		=		self.get_dummy_components(class_cond=lowerCamelCase)
           _lowercase       :							Dict      		=		ConsistencyModelPipeline(**lowerCamelCase)
           _lowercase       :							Optional[Any]      		=		pipe.to(lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							Tuple      		=		self.get_dummy_inputs(lowerCamelCase)
           _lowercase       :							Tuple      		=		1
           _lowercase       :							int      		=		None
           _lowercase       :							Tuple      		=		0
           _lowercase       :							Dict      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 32, 32, 3)

           _lowercase       :							List[str]      		=		image[0, -3:, -3:, -1]
           _lowercase       :							Any      		=		np.array([0.5_0_0_4, 0.5_0_0_4, 0.4_9_9_4, 0.5_0_0_8, 0.4_9_7_6, 0.5_0_1_8, 0.4_9_9_0, 0.4_9_8_2, 0.4_9_8_7])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3






@slow
@require_torch_gpu
class _lowerCamelCase(						unittest.TestCase   ):
       def 			UpperCamelCase     (					self)       ->   Union[str, Any]:




           """simple docstring"""

           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()
       def 			UpperCamelCase     (					self,      lowerCamelCase=0,      lowerCamelCase=False,      lowerCamelCase="cpu",      lowerCamelCase=torch.floataa,      lowerCamelCase=(1, 3, 64, 64))       ->   Optional[Any]:




           """simple docstring"""

           _lowercase       :							List[Any]      		=		torch.manual_seed(lowerCamelCase)

           _lowercase       :							str      		=		{
               'num_inference_steps': None,
               'timesteps': [22, 0],
               'class_labels': 0,
               'generator': generator,
               'output_type': 'np',
           }

           if get_fixed_latents:
               _lowercase       :							Optional[Any]      		=		self.get_fixed_latents(seed=lowerCamelCase,      device=lowerCamelCase,      dtype=lowerCamelCase,      shape=lowerCamelCase)
               _lowercase       :							Tuple      		=		latents

           return inputs
       def 			UpperCamelCase     (					self,      lowerCamelCase=0,      lowerCamelCase="cpu",      lowerCamelCase=torch.floataa,      lowerCamelCase=(1, 3, 64, 64))       ->   Any:




           """simple docstring"""

           if type(lowerCamelCase) == str:
               _lowercase       :							Union[str, Any]      		=		torch.device(lowerCamelCase)
           _lowercase       :							int      		=		torch.Generator(device=lowerCamelCase).manual_seed(lowerCamelCase)
           _lowercase       :							List[str]      		=		randn_tensor(lowerCamelCase,      generator=lowerCamelCase,      device=lowerCamelCase,      dtype=lowerCamelCase)
           return latents
       def 			UpperCamelCase     (					self)       ->   str:




           """simple docstring"""

           _lowercase       :							Tuple      		=		UNetaDModel.from_pretrained('diffusers/consistency_models',      subfolder='diffusers_cd_imagenet64_l2')
           _lowercase       :							Optional[int]      		=		CMStochasticIterativeScheduler(
               num_train_timesteps=40,      sigma_min=0.0_0_2,      sigma_max=8_0.0,      )
           _lowercase       :							Any      		=		ConsistencyModelPipeline(unet=lowerCamelCase,      scheduler=lowerCamelCase)
           pipe.to(torch_device=lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							str      		=		self.get_inputs()
           _lowercase       :							Optional[int]      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 64, 64, 3)

           _lowercase       :							str      		=		image[0, -3:, -3:, -1]

           _lowercase       :							Optional[Any]      		=		np.array([0.0_8_8_8, 0.0_8_8_1, 0.0_6_6_6, 0.0_4_7_9, 0.0_2_9_2, 0.0_1_9_5, 0.0_2_0_1, 0.0_1_6_3, 0.0_2_5_4])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 2E-2
       def 			UpperCamelCase     (					self)       ->   str:




           """simple docstring"""

           _lowercase       :							List[str]      		=		UNetaDModel.from_pretrained('diffusers/consistency_models',      subfolder='diffusers_cd_imagenet64_l2')
           _lowercase       :							List[str]      		=		CMStochasticIterativeScheduler(
               num_train_timesteps=40,      sigma_min=0.0_0_2,      sigma_max=8_0.0,      )
           _lowercase       :							Union[str, Any]      		=		ConsistencyModelPipeline(unet=lowerCamelCase,      scheduler=lowerCamelCase)
           pipe.to(torch_device=lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							List[Any]      		=		self.get_inputs()
           _lowercase       :							int      		=		1
           _lowercase       :							Optional[Any]      		=		None
           _lowercase       :							str      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 64, 64, 3)

           _lowercase       :							List[Any]      		=		image[0, -3:, -3:, -1]

           _lowercase       :							List[str]      		=		np.array([0.0_3_4_0, 0.0_1_5_2, 0.0_0_6_3, 0.0_2_6_7, 0.0_2_2_1, 0.0_1_0_7, 0.0_4_1_6, 0.0_1_8_6, 0.0_2_1_7])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 2E-2
       @require_torch_a
       def 			UpperCamelCase     (					self)       ->   Union[str, Any]:




           """simple docstring"""

           _lowercase       :							str      		=		UNetaDModel.from_pretrained('diffusers/consistency_models',      subfolder='diffusers_cd_imagenet64_l2')
           _lowercase       :							Optional[int]      		=		CMStochasticIterativeScheduler(
               num_train_timesteps=40,      sigma_min=0.0_0_2,      sigma_max=8_0.0,      )
           _lowercase       :							Optional[int]      		=		ConsistencyModelPipeline(unet=lowerCamelCase,      scheduler=lowerCamelCase)
           pipe.to(torch_device=lowerCamelCase,      torch_dtype=torch.floataa)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							Any      		=		self.get_inputs(get_fixed_latents=lowerCamelCase,      device=lowerCamelCase)
           # Ensure usage of flash attention in torch 2.0
           with sdp_kernel(enable_flash=lowerCamelCase,      enable_math=lowerCamelCase,      enable_mem_efficient=lowerCamelCase):
               _lowercase       :							Dict      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 64, 64, 3)

           _lowercase       :							Any      		=		image[0, -3:, -3:, -1]

           _lowercase       :							Union[str, Any]      		=		np.array([0.1_8_7_5, 0.1_4_2_8, 0.1_2_8_9, 0.2_1_5_1, 0.2_0_9_2, 0.1_4_7_7, 0.1_8_7_7, 0.1_6_4_1, 0.1_3_5_3])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3




       @require_torch_a
       def 			UpperCamelCase     (					self)       ->   Union[str, Any]:




           """simple docstring"""

           _lowercase       :							Dict      		=		UNetaDModel.from_pretrained('diffusers/consistency_models',      subfolder='diffusers_cd_imagenet64_l2')
           _lowercase       :							Optional[Any]      		=		CMStochasticIterativeScheduler(
               num_train_timesteps=40,      sigma_min=0.0_0_2,      sigma_max=8_0.0,      )
           _lowercase       :							int      		=		ConsistencyModelPipeline(unet=lowerCamelCase,      scheduler=lowerCamelCase)
           pipe.to(torch_device=lowerCamelCase,      torch_dtype=torch.floataa)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase       :							List[Any]      		=		self.get_inputs(get_fixed_latents=lowerCamelCase,      device=lowerCamelCase)
           _lowercase       :							int      		=		1
           _lowercase       :							str      		=		None
           # Ensure usage of flash attention in torch 2.0
           with sdp_kernel(enable_flash=lowerCamelCase,      enable_math=lowerCamelCase,      enable_mem_efficient=lowerCamelCase):
               _lowercase       :							Union[str, Any]      		=		pipe(**lowerCamelCase).images
           assert image.shape == (1, 64, 64, 3)

           _lowercase       :							Any      		=		image[0, -3:, -3:, -1]

           _lowercase       :							int      		=		np.array([0.1_6_6_3, 0.1_9_4_8, 0.2_2_7_5, 0.1_6_8_0, 0.1_2_0_4, 0.1_2_4_5, 0.1_8_5_8, 0.1_3_3_8, 0.2_0_9_5])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3


