
"""simple docstring"""


import os
from dataclasses import dataclass, field
from io import BytesIO
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Optional, Union

import numpy as np
import pyarrow as pa

from .. import config
from ..download.streaming_download_manager import xopen, xsplitext
from ..table import array_cast
from ..utils.py_utils import no_op_if_value_is_null, string_to_dict


if TYPE_CHECKING:
							from .features import FeatureType


lowerCAmelCase								=						False, False, False

@dataclass
class     A_	:



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_	      =   None
							SCREAMING_SNAKE_CASE_	      =   True
							SCREAMING_SNAKE_CASE_	      =   True
							SCREAMING_SNAKE_CASE_	      =   None
							# Automatically constructed
							SCREAMING_SNAKE_CASE_	      =   "dict"
							SCREAMING_SNAKE_CASE_	      =   pa.struct({"""bytes""": pa.binary(), """path""": pa.string()}   )
							SCREAMING_SNAKE_CASE_	      =   field(default="""Audio"""      ,					init=_a      ,					repr=_a   )





							def __call__(  self  :Dict       ):





										"""simple docstring"""

										return self.pa_type





							def       UpperCAmelCase__							(  self  :Union[str, Any]     ,							lowerCamelCase_  :Union[str, Any]       ):





										"""simple docstring"""

										try:
													import soundfile as sf  # soundfile is a dependency of librosa, needed to decode audio files.
										except ImportError as err:
													raise ImportError('To support encoding audio data, please install \'soundfile\'.'       ) from err
										if isinstance(lowerCamelCase_     ,							lowerCamelCase_       ):
													return {"bytes": None, "path": value}
										elif isinstance(lowerCamelCase_     ,							lowerCamelCase_       ):
													return {"bytes": value, "path": None}
										elif "array" in value:
													# convert the audio array to wav bytes
													lowerCamelCase__	:     Optional[Any]              =BytesIO()
													sf.write(lowerCamelCase_     ,							value['array']     ,							value['sampling_rate']     ,							format='wav'       )
													return {"bytes": buffer.getvalue(), "path": None}
										elif value.get('path'       ) is not None and os.path.isfile(value['path']       ):
													# we set "bytes": None to not duplicate the data if they're already available locally
													if value["path"].endswith('pcm'       ):
																# "PCM" only has raw audio bytes
																if value.get('sampling_rate'       ) is None:
																			# At least, If you want to convert "PCM-byte" to "WAV-byte", you have to know sampling rate
																			raise KeyError('To use PCM files, please specify a \'sampling_rate\' in Audio object'       )
																if value.get('bytes'       ):
																			# If we already had PCM-byte, we don`t have to make "read file, make bytes" (just use it!)
																			lowerCamelCase__	:     List[Any]              =np.frombuffer(value['bytes']     ,							dtype=np.intaa       ).astype(np.floataa       ) / 32_767
																else:
																			lowerCamelCase__	:     Dict              =np.memmap(value['path']     ,							dtype='h'     ,							mode='r'       ).astype(np.floataa       ) / 32_767

																lowerCamelCase__	:     List[str]              =BytesIO(bytes()       )
																sf.write(lowerCamelCase_     ,							lowerCamelCase_     ,							value['sampling_rate']     ,							format='wav'       )
																return {"bytes": buffer.getvalue(), "path": None}
													else:
																return {"bytes": None, "path": value.get('path'       )}
										elif value.get('bytes'       ) is not None or value.get('path'       ) is not None:
													# store the audio bytes, and path is used to infer the audio format using the file extension
													return {"bytes": value.get('bytes'       ), "path": value.get('path'       )}
										else:
													raise ValueError(
													    f"""An audio sample should have one of \'path\' or \'bytes\' but they are missing or None in {value}."""       )





							def       UpperCAmelCase__							(  self  :int     ,							lowerCamelCase_  :int     ,							lowerCamelCase_  :Any = None       ):





										"""simple docstring"""

										if not self.decode:
													raise RuntimeError('Decoding is disabled for this feature. Please use Audio(decode=True) instead.'       )

										lowerCamelCase__	:     List[Any]              =(value['path'], BytesIO(value['bytes']       )) if value['bytes'] is not None else (value['path'], None)
										if path is None and file is None:
													raise ValueError(f"""An audio sample should have one of \'path\' or \'bytes\' but both are None in {value}."""       )

										try:
													import librosa
													import soundfile as sf
										except ImportError as err:
													raise ImportError('To support decoding audio files, please install \'librosa\' and \'soundfile\'.'       ) from err

										lowerCamelCase__	:     Optional[Any]              =xsplitext(lowerCamelCase_       )[1][1:].lower() if path is not None else None
										if not config.IS_OPUS_SUPPORTED and audio_format == "opus":
													raise RuntimeError(
													    'Decoding \'opus\' files requires system library \'libsndfile\'>=1.0.31, '
													    'You can try to update `soundfile` python library: `pip install "soundfile>=0.12.1"`. '       )
										elif not config.IS_MP3_SUPPORTED and audio_format == "mp3":
													raise RuntimeError(
													    'Decoding \'mp3\' files requires system library \'libsndfile\'>=1.1.0, '
													    'You can try to update `soundfile` python library: `pip install "soundfile>=0.12.1"`. '       )

										if file is None:
													lowerCamelCase__	:     int              =token_per_repo_id or {}
													lowerCamelCase__	:     Optional[int]              =path.split('::'       )[-1]
													try:
																lowerCamelCase__	:     Any              =string_to_dict(lowerCamelCase_     ,							config.HUB_DATASETS_URL       )['repo_id']
																lowerCamelCase__	:     Optional[Any]              =token_per_repo_id[repo_id]
													except (ValueError, KeyError):
																lowerCamelCase__	:     int              =None

													with xopen(lowerCamelCase_     ,							'rb'     ,							use_auth_token=lowerCamelCase_       ) as f:
																lowerCamelCase__	:     int              =sf.read(lowerCamelCase_       )

										else:
													lowerCamelCase__	:     Union[str, Any]              =sf.read(lowerCamelCase_       )

										lowerCamelCase__	:     Any              =array.T
										if self.mono:
													lowerCamelCase__	:     List[str]              =librosa.to_mono(lowerCamelCase_       )
										if self.sampling_rate and self.sampling_rate != sampling_rate:
													lowerCamelCase__	:     Tuple              =librosa.resample(lowerCamelCase_     ,							orig_sr=lowerCamelCase_     ,							target_sr=self.sampling_rate       )
													lowerCamelCase__	:     List[str]              =self.sampling_rate

										return {"path": path, "array": array, "sampling_rate": sampling_rate}





							def       UpperCAmelCase__							(  self  :Any       ):





										"""simple docstring"""

										from .features import Value

										if self.decode:
													raise ValueError('Cannot flatten a decoded Audio feature.'       )
										return {
										    "bytes": Value('binary'       ),
										    "path": Value('string'       ),
										}





							def       UpperCAmelCase__							(  self  :List[Any]     ,							lowerCamelCase_  :Tuple       ):





										"""simple docstring"""

										if pa.types.is_string(storage.type       ):
													lowerCamelCase__	:     List[Any]              =pa.array([None] * len(lowerCamelCase_       )     ,							type=pa.binary()       )
													lowerCamelCase__	:     Union[str, Any]              =pa.StructArray.from_arrays([bytes_array, storage]     ,							['bytes', 'path']     ,							mask=storage.is_null()       )
										elif pa.types.is_binary(storage.type       ):
													lowerCamelCase__	:     Tuple              =pa.array([None] * len(lowerCamelCase_       )     ,							type=pa.string()       )
													lowerCamelCase__	:     Dict              =pa.StructArray.from_arrays([storage, path_array]     ,							['bytes', 'path']     ,							mask=storage.is_null()       )
										elif pa.types.is_struct(storage.type       ) and storage.type.get_all_field_indices('array'       ):
													lowerCamelCase__	:     int              =pa.array([Audio().encode_example(lowerCamelCase_       ) if x is not None else None for x in storage.to_pylist()]       )
										elif pa.types.is_struct(storage.type       ):
													if storage.type.get_field_index('bytes'       ) >= 0:
																lowerCamelCase__	:     Optional[int]              =storage.field('bytes'       )
													else:
																lowerCamelCase__	:     str              =pa.array([None] * len(lowerCamelCase_       )     ,							type=pa.binary()       )
													if storage.type.get_field_index('path'       ) >= 0:
																lowerCamelCase__	:     Union[str, Any]              =storage.field('path'       )
													else:
																lowerCamelCase__	:     List[Any]              =pa.array([None] * len(lowerCamelCase_       )     ,							type=pa.string()       )
													lowerCamelCase__	:     Any              =pa.StructArray.from_arrays([bytes_array, path_array]     ,							['bytes', 'path']     ,							mask=storage.is_null()       )
										return array_cast(lowerCamelCase_     ,							self.pa_type       )





							def       UpperCAmelCase__							(  self  :Any     ,							lowerCamelCase_  :int       ):





										"""simple docstring"""

										@no_op_if_value_is_null
										def path_to_bytes(lowerCamelCase_  :int       ):
													with xopen(lowerCamelCase_     ,							'rb'       ) as f:
																lowerCamelCase__	:     int              =f.read()
													return bytes_

										lowerCamelCase__	:     Optional[Any]              =pa.array(
										    [
										        (path_to_bytes(x['path']       ) if x['bytes'] is None else x['bytes']) if x is not None else None
										        for x in storage.to_pylist()
										    ]     ,							type=pa.binary()     ,							)
										lowerCamelCase__	:     int              =pa.array(
										    [os.path.basename(lowerCamelCase_       ) if path is not None else None for path in storage.field('path'       ).to_pylist()]     ,							type=pa.string()     ,							)
										lowerCamelCase__	:     Dict              =pa.StructArray.from_arrays([bytes_array, path_array]     ,							['bytes', 'path']     ,							mask=bytes_array.is_null()       )
										return array_cast(lowerCamelCase_     ,							self.pa_type       )



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


