






from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import (
    BaseOutput,
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_onnx_available,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)

@dataclass
class 		_snake_case	(	A__       ):
			_lowercase		:     Union[List[PIL.Image.Image], np.ndarray]
			_lowercase		:     Optional[List[bool]]


try:
				if not (is_transformers_available() and is_torch_available()):
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
				from .pipeline_cycle_diffusion import CycleDiffusionPipeline
				from .pipeline_stable_diffusion import StableDiffusionPipeline
				from .pipeline_stable_diffusion_attend_and_excite import StableDiffusionAttendAndExcitePipeline
				from .pipeline_stable_diffusion_imgaimg import StableDiffusionImgaImgPipeline
				from .pipeline_stable_diffusion_inpaint import StableDiffusionInpaintPipeline
				from .pipeline_stable_diffusion_inpaint_legacy import StableDiffusionInpaintPipelineLegacy
				from .pipeline_stable_diffusion_instruct_pixapix import StableDiffusionInstructPixaPixPipeline
				from .pipeline_stable_diffusion_latent_upscale import StableDiffusionLatentUpscalePipeline
				from .pipeline_stable_diffusion_ldmad import StableDiffusionLDMaDPipeline
				from .pipeline_stable_diffusion_model_editing import StableDiffusionModelEditingPipeline
				from .pipeline_stable_diffusion_panorama import StableDiffusionPanoramaPipeline
				from .pipeline_stable_diffusion_paradigms import StableDiffusionParadigmsPipeline
				from .pipeline_stable_diffusion_sag import StableDiffusionSAGPipeline
				from .pipeline_stable_diffusion_upscale import StableDiffusionUpscalePipeline
				from .pipeline_stable_unclip import StableUnCLIPPipeline
				from .pipeline_stable_unclip_imgaimg import StableUnCLIPImgaImgPipeline
				from .safety_checker import StableDiffusionSafetyChecker
				from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer

try:
				if not (is_transformers_available() and is_torch_available() and is_transformers_version('>=', '4.25.0')):
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				from ...utils.dummy_torch_and_transformers_objects import StableDiffusionImageVariationPipeline
else:
				from .pipeline_stable_diffusion_image_variation import StableDiffusionImageVariationPipeline


try:
				if not (is_transformers_available() and is_torch_available() and is_transformers_version('>=', '4.26.0')):
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				from ...utils.dummy_torch_and_transformers_objects import (
				    StableDiffusionDepthaImgPipeline,
				    StableDiffusionDiffEditPipeline,
				    StableDiffusionPixaPixZeroPipeline,
				)
else:
				from .pipeline_stable_diffusion_depthaimg import StableDiffusionDepthaImgPipeline
				from .pipeline_stable_diffusion_diffedit import StableDiffusionDiffEditPipeline
				from .pipeline_stable_diffusion_pixapix_zero import StableDiffusionPixaPixZeroPipeline


try:
				if not (
				    is_torch_available()
				    and is_transformers_available()
				    and is_k_diffusion_available()
				    and is_k_diffusion_version('>=', '0.0.12')
				):
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				from ...utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
				from .pipeline_stable_diffusion_k_diffusion import StableDiffusionKDiffusionPipeline

try:
				if not (is_transformers_available() and is_onnx_available()):
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				from ...utils.dummy_onnx_objects import *  # noqa F403
else:
				from .pipeline_onnx_stable_diffusion import OnnxStableDiffusionPipeline, StableDiffusionOnnxPipeline
				from .pipeline_onnx_stable_diffusion_imgaimg import OnnxStableDiffusionImgaImgPipeline
				from .pipeline_onnx_stable_diffusion_inpaint import OnnxStableDiffusionInpaintPipeline
				from .pipeline_onnx_stable_diffusion_inpaint_legacy import OnnxStableDiffusionInpaintPipelineLegacy
				from .pipeline_onnx_stable_diffusion_upscale import OnnxStableDiffusionUpscalePipeline

if is_transformers_available() and is_flax_available():
				import flax

				@flax.struct.dataclass
				class 		_snake_case	(	A__       ):
							_lowercase		:     np.ndarray
							_lowercase		:     List[bool]



				from ...schedulers.scheduling_pndm_flax import PNDMSchedulerState
				from .pipeline_flax_stable_diffusion import FlaxStableDiffusionPipeline
				from .pipeline_flax_stable_diffusion_imgaimg import FlaxStableDiffusionImgaImgPipeline
				from .pipeline_flax_stable_diffusion_inpaint import FlaxStableDiffusionInpaintPipeline
				from .safety_checker_flax import FlaxStableDiffusionSafetyChecker







import dataclasses
import json
import warnings
from dataclasses import dataclass, field
from time import time
from typing import List

from ..utils import logging


lowercase			:				List[str]   =     logging.get_logger(__name__)






def        snake_case__		(    lowerCamelCase_=None     ,				lowerCamelCase_=None		):
							return field(default_factory=lambda: default     ,				metadata=lowerCamelCase_		)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		List[str]								=	list_field(
							    default=[]		,       metadata={
							        '''help''': (
							            '''Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version'''
							            ''' of all available models'''
							        )
							    }		,       )

							UpperCAmelCase_						:		List[int]								=	list_field(
							    default=[8]		,       metadata={'''help''': '''List of batch sizes for which memory and time performance will be evaluated'''}				)

							UpperCAmelCase_						:		List[int]								=	list_field(
							    default=[8, 32, 1_28, 5_12]		,       metadata={'''help''': '''List of sequence lengths for which memory and time performance will be evaluated'''}		,       )

							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Whether to benchmark inference of model. Inference can be disabled via --no-inference.'''}		,       )
							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Whether to run on available cuda devices. Cuda can be disabled via --no-cuda.'''}		,       )
							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Whether to run on available tpu devices. TPU can be disabled via --no-tpu.'''}				)
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Use FP16 to accelerate inference.'''}				)
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Benchmark training of model'''}				)
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Verbose memory tracing'''}				)
							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Whether to perform speed measurements. Speed measurements can be disabled via --no-speed.'''}		,       )
							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={
							        '''help''': '''Whether to perform memory measurements. Memory measurements can be disabled via --no-memory'''
							    }		,       )
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Trace memory line by line'''}				)
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Save result to a CSV file'''}				)
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Save all print statements in a log file'''}				)
							UpperCAmelCase_						:		bool								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''Whether to print environment information'''}				)
							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={
							        '''help''': (
							            '''Whether to use multiprocessing for memory and speed measurement. It is highly recommended to use'''
							            ''' multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled'''
							            ''' for debugging / testing and on TPU.'''
							        )
							    }		,       )
							UpperCAmelCase_						:		str								=	field(
							    default=F'inference_time_{round(time()				)}.csv'		,       metadata={'''help''': '''CSV filename used if saving time results to csv.'''}		,       )
							UpperCAmelCase_						:		str								=	field(
							    default=F'inference_memory_{round(time()				)}.csv'		,       metadata={'''help''': '''CSV filename used if saving memory results to csv.'''}		,       )
							UpperCAmelCase_						:		str								=	field(
							    default=F'train_time_{round(time()				)}.csv'		,       metadata={'''help''': '''CSV filename used if saving time results to csv for training.'''}		,       )
							UpperCAmelCase_						:		str								=	field(
							    default=F'train_memory_{round(time()				)}.csv'		,       metadata={'''help''': '''CSV filename used if saving memory results to csv for training.'''}		,       )
							UpperCAmelCase_						:		str								=	field(
							    default=F'env_info_{round(time()				)}.csv'		,       metadata={'''help''': '''CSV filename used if saving environment information.'''}		,       )
							UpperCAmelCase_						:		str								=	field(
							    default=F'log_{round(time()				)}.csv'		,       metadata={'''help''': '''Log filename used if print statements are saved in log.'''}		,       )
							UpperCAmelCase_						:		int								=	field(default=3		,       metadata={'''help''': '''Times an experiment will be run.'''}				)
							UpperCAmelCase_						:		bool								=	field(
							    default=_SCREAMING_SNAKE_CASE		,       metadata={
							        '''help''': (
							            '''Instead of loading the model as defined in `config.architectures` if exists, just load the pretrain'''
							            ''' model weights.'''
							        )
							    }		,       )




							def       snake_case			(					self						)		->       Union[str, Any]:
														warnings.warn(
														    f'The class {self.__class__} is deprecated. Hugging Face Benchmarking utils'
														    ''' are deprecated in general and it is advised to use external Benchmarking libraries '''
														    ''' to benchmark Transformer models.'''    ,						__UpperCAmelCase    ,						)




							def       snake_case			(					self						)		->       Union[str, Any]:
														return json.dumps(dataclasses.asdict(self						)    ,						indent=2						)




							@property
							def       snake_case			(					self						)		->       List[str]:
														if len(self.models						) <= 0:
																					raise ValueError(
																					    '''Please make sure you provide at least one model name / model identifier, *e.g.* `--models'''
																					    ''' bert-base-cased` or `args.models = [\'bert-base-cased\'].'''						)
														return self.models






							@property
							def       snake_case			(					self						)		->       int:
														if not self.multi_process:
																					return False
														elif self.is_tpu:
																					logger.info('''Multiprocessing is currently not possible on TPU.'''						)
																					return False
														else:
																					return True






