


snake_case_						:			int													=							'''0.18.2'''

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
							if not is_onnx_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_onnx_objects import *  # noqa F403
else:
							from .pipelines import OnnxRuntimeModel

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_pt_objects import *  # noqa F403
else:
							from .models import (
							    AutoencoderKL,
							    ControlNetModel,
							    ModelMixin,
							    PriorTransformer,
							    TaFilmDecoder,
							    TransformeraDModel,
							    UNetaDModel,
							    UNetaDConditionModel,
							    UNetaDModel,
							    UNetaDConditionModel,
							    VQModel,
							)
							from .optimization import (
							    get_constant_schedule,
							    get_constant_schedule_with_warmup,
							    get_cosine_schedule_with_warmup,
							    get_cosine_with_hard_restarts_schedule_with_warmup,
							    get_linear_schedule_with_warmup,
							    get_polynomial_decay_schedule_with_warmup,
							    get_scheduler,
							)
							from .pipelines import (
							    AudioPipelineOutput,
							    ConsistencyModelPipeline,
							    DanceDiffusionPipeline,
							    DDIMPipeline,
							    DDPMPipeline,
							    DiffusionPipeline,
							    DiTPipeline,
							    ImagePipelineOutput,
							    KarrasVePipeline,
							    LDMPipeline,
							    LDMSuperResolutionPipeline,
							    PNDMPipeline,
							    RePaintPipeline,
							    ScoreSdeVePipeline,
							)
							from .schedulers import (
							    CMStochasticIterativeScheduler,
							    DDIMInverseScheduler,
							    DDIMParallelScheduler,
							    DDIMScheduler,
							    DDPMParallelScheduler,
							    DDPMScheduler,
							    DEISMultistepScheduler,
							    DPMSolverMultistepInverseScheduler,
							    DPMSolverMultistepScheduler,
							    DPMSolverSinglestepScheduler,
							    EulerAncestralDiscreteScheduler,
							    EulerDiscreteScheduler,
							    HeunDiscreteScheduler,
							    IPNDMScheduler,
							    KarrasVeScheduler,
							    KDPMaAncestralDiscreteScheduler,
							    KDPMaDiscreteScheduler,
							    PNDMScheduler,
							    RePaintScheduler,
							    SchedulerMixin,
							    ScoreSdeVeScheduler,
							    UnCLIPScheduler,
							    UniPCMultistepScheduler,
							    VQDiffusionScheduler,
							)
							from .training_utils import EMAModel

try:
							if not (is_torch_available() and is_scipy_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
							from .schedulers import LMSDiscreteScheduler

try:
							if not (is_torch_available() and is_torchsde_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
							from .schedulers import DPMSolverSDEScheduler

try:
							if not (is_torch_available() and is_transformers_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
							from .pipelines import (
							    AltDiffusionImgaImgPipeline,
							    AltDiffusionPipeline,
							    AudioLDMPipeline,
							    CycleDiffusionPipeline,
							    IFImgaImgPipeline,
							    IFImgaImgSuperResolutionPipeline,
							    IFInpaintingPipeline,
							    IFInpaintingSuperResolutionPipeline,
							    IFPipeline,
							    IFSuperResolutionPipeline,
							    ImageTextPipelineOutput,
							    KandinskyImgaImgPipeline,
							    KandinskyInpaintPipeline,
							    KandinskyPipeline,
							    KandinskyPriorPipeline,
							    KandinskyVaaControlnetImgaImgPipeline,
							    KandinskyVaaControlnetPipeline,
							    KandinskyVaaImgaImgPipeline,
							    KandinskyVaaInpaintPipeline,
							    KandinskyVaaPipeline,
							    KandinskyVaaPriorEmbaEmbPipeline,
							    KandinskyVaaPriorPipeline,
							    LDMTextToImagePipeline,
							    PaintByExamplePipeline,
							    SemanticStableDiffusionPipeline,
							    ShapEImgaImgPipeline,
							    ShapEPipeline,
							    StableDiffusionAttendAndExcitePipeline,
							    StableDiffusionControlNetImgaImgPipeline,
							    StableDiffusionControlNetInpaintPipeline,
							    StableDiffusionControlNetPipeline,
							    StableDiffusionDepthaImgPipeline,
							    StableDiffusionDiffEditPipeline,
							    StableDiffusionImageVariationPipeline,
							    StableDiffusionImgaImgPipeline,
							    StableDiffusionInpaintPipeline,
							    StableDiffusionInpaintPipelineLegacy,
							    StableDiffusionInstructPixaPixPipeline,
							    StableDiffusionLatentUpscalePipeline,
							    StableDiffusionLDMaDPipeline,
							    StableDiffusionModelEditingPipeline,
							    StableDiffusionPanoramaPipeline,
							    StableDiffusionParadigmsPipeline,
							    StableDiffusionPipeline,
							    StableDiffusionPipelineSafe,
							    StableDiffusionPixaPixZeroPipeline,
							    StableDiffusionSAGPipeline,
							    StableDiffusionUpscalePipeline,
							    StableUnCLIPImgaImgPipeline,
							    StableUnCLIPPipeline,
							    TextToVideoSDPipeline,
							    TextToVideoZeroPipeline,
							    UnCLIPImageVariationPipeline,
							    UnCLIPPipeline,
							    UniDiffuserModel,
							    UniDiffuserPipeline,
							    UniDiffuserTextDecoder,
							    VersatileDiffusionDualGuidedPipeline,
							    VersatileDiffusionImageVariationPipeline,
							    VersatileDiffusionPipeline,
							    VersatileDiffusionTextToImagePipeline,
							    VideoToVideoSDPipeline,
							    VQDiffusionPipeline,
							)

try:
							if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
							from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
							if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
							from .pipelines import StableDiffusionKDiffusionPipeline

try:
							if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
							from .pipelines import (
							    OnnxStableDiffusionImgaImgPipeline,
							    OnnxStableDiffusionInpaintPipeline,
							    OnnxStableDiffusionInpaintPipelineLegacy,
							    OnnxStableDiffusionPipeline,
							    OnnxStableDiffusionUpscalePipeline,
							    StableDiffusionOnnxPipeline,
							)

try:
							if not (is_torch_available() and is_librosa_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
							from .pipelines import AudioDiffusionPipeline, Mel

try:
							if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
							from .pipelines import SpectrogramDiffusionPipeline

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_flax_objects import *  # noqa F403
else:
							from .models.controlnet_flax import FlaxControlNetModel
							from .models.modeling_flax_utils import FlaxModelMixin
							from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
							from .models.vae_flax import FlaxAutoencoderKL
							from .pipelines import FlaxDiffusionPipeline
							from .schedulers import (
							    FlaxDDIMScheduler,
							    FlaxDDPMScheduler,
							    FlaxDPMSolverMultistepScheduler,
							    FlaxKarrasVeScheduler,
							    FlaxLMSDiscreteScheduler,
							    FlaxPNDMScheduler,
							    FlaxSchedulerMixin,
							    FlaxScoreSdeVeScheduler,
							)


try:
							if not (is_flax_available() and is_transformers_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
							from .pipelines import (
							    FlaxStableDiffusionControlNetPipeline,
							    FlaxStableDiffusionImgaImgPipeline,
							    FlaxStableDiffusionInpaintPipeline,
							    FlaxStableDiffusionPipeline,
							)

try:
							if not (is_note_seq_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_note_seq_objects import *  # noqa F403
else:
							from .pipelines import MidiProcessor



import unittest

import numpy as np
import requests

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

							from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
							snake_case_						:			Any													=							False

if is_vision_available():
							from PIL import Image

							from transformers import PixaStructImageProcessor

class 						A__							(		unittest.TestCase  ):




						def __init__(       self					:      Tuple				,    _a					:      str				,    _a					:      List[str]=7				,    _a					:      Union[str, Any]=3				,    _a					:      List[str]=18				,    _a					:      List[Any]=30				,    _a					:      Optional[Any]=400				,    _a					:      Dict=None				,    _a					:      Union[str, Any]=True				,    _a					:      List[str]=True				,    _a					:      Optional[Any]=None				,    )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =size if size is not None else {'''height''': 20, '''width''': 20}
										_SCREAMING_SNAKE_CASE			  =parent
										_SCREAMING_SNAKE_CASE			  =batch_size
										_SCREAMING_SNAKE_CASE			  =num_channels
										_SCREAMING_SNAKE_CASE			  =image_size
										_SCREAMING_SNAKE_CASE			  =min_resolution
										_SCREAMING_SNAKE_CASE			  =max_resolution
										_SCREAMING_SNAKE_CASE			  =size
										_SCREAMING_SNAKE_CASE			  =do_normalize
										_SCREAMING_SNAKE_CASE			  =do_convert_rgb
										_SCREAMING_SNAKE_CASE			  =[512, 1024, 2048, 4096]
										_SCREAMING_SNAKE_CASE			  =patch_size if patch_size is not None else {'''height''': 16, '''width''': 16}




						def 							__UpperCamelCase				(       self					:      int  )							->     Any:


										"""simple docstring"""





										return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}




						def 							__UpperCamelCase				(       self					:      str  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg'''
										_SCREAMING_SNAKE_CASE			  =Image.open(requests.get(_a				,    stream=_a  ).raw  ).convert('''RGB'''  )
										return raw_image

@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11   ,     reason="`Pix2StructImageProcessor` requires `torch>=1.11.0`."   ,     )
@require_torch
@require_vision
class 						A__							(		UpperCamelCase__   ,     unittest.TestCase  ):
						UpperCAmelCase             =						PixaStructImageProcessor if is_vision_available() else None




						def 							__UpperCamelCase				(       self					:      int  )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =PixaStructImageProcessingTester(self  )




						@property
						def 							__UpperCamelCase				(       self					:      int  )							->     Any:


										"""simple docstring"""





										return self.image_processor_tester.prepare_image_processor_dict()




						def 							__UpperCamelCase				(       self					:      str  )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										self.assertTrue(hasattr(_a				,    '''do_normalize'''  )  )
										self.assertTrue(hasattr(_a				,    '''do_convert_rgb'''  )  )




						def 							__UpperCamelCase				(       self					:      int  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processor_tester.prepare_dummy_image()

										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										_SCREAMING_SNAKE_CASE			  =2048

										_SCREAMING_SNAKE_CASE			  =image_processor(_a				,    return_tensors='''pt'''				,    max_patches=_a  )
										self.assertTrue(torch.allclose(inputs.flattened_patches.mean()				,    torch.tensor(0.06_06  )				,    atol=1E-3				,    rtol=1E-3  )  )




						def 							__UpperCamelCase				(       self					:      Tuple  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										# create random PIL images
										_SCREAMING_SNAKE_CASE			  =prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_a  )
										for image in image_inputs:
														self.assertIsInstance(_a				,    Image.Image  )

										# Test not batched input
										_SCREAMING_SNAKE_CASE			  =(
										    (self.image_processor_tester.patch_size['''height'''] * self.image_processor_tester.patch_size['''width'''])
										    * self.image_processor_tester.num_channels
										) + 2

										for max_patch in self.image_processor_tester.max_patches:
														# Test not batched input
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    image_inputs[0]				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (1, max_patch, expected_hidden_dim)				,    )

														# Test batched
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    _a				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,    )




						def 							__UpperCamelCase				(       self					:      Dict  )							->     List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										# create random PIL images
										_SCREAMING_SNAKE_CASE			  =prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_a  )
										for image in image_inputs:
														self.assertIsInstance(_a				,    Image.Image  )

										# Test not batched input
										_SCREAMING_SNAKE_CASE			  =(
										    (self.image_processor_tester.patch_size['''height'''] * self.image_processor_tester.patch_size['''width'''])
										    * self.image_processor_tester.num_channels
										) + 2

										_SCREAMING_SNAKE_CASE			  =True

										for max_patch in self.image_processor_tester.max_patches:
														# Test not batched input
														with self.assertRaises(_a  ):
																		_SCREAMING_SNAKE_CASE			  =image_processor(
																		    image_inputs[0]				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches

														_SCREAMING_SNAKE_CASE			  ='''Hello'''

														_SCREAMING_SNAKE_CASE			  =image_processor(
														    image_inputs[0]				,    return_tensors='''pt'''				,    max_patches=_a				,    header_text=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (1, max_patch, expected_hidden_dim)				,    )

														# Test batched
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    _a				,    return_tensors='''pt'''				,    max_patches=_a				,    header_text=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,    )




						def 							__UpperCamelCase				(       self					:      List[Any]  )							->     List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										# create random numpy tensors
										_SCREAMING_SNAKE_CASE			  =prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_a				,    numpify=_a  )
										for image in image_inputs:
														self.assertIsInstance(_a				,    np.ndarray  )

										_SCREAMING_SNAKE_CASE			  =(
										    (self.image_processor_tester.patch_size['''height'''] * self.image_processor_tester.patch_size['''width'''])
										    * self.image_processor_tester.num_channels
										) + 2

										for max_patch in self.image_processor_tester.max_patches:
														# Test not batched input
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    image_inputs[0]				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (1, max_patch, expected_hidden_dim)				,    )

														# Test batched
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    _a				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,    )




						def 							__UpperCamelCase				(       self					:      Union[str, Any]  )							->     List[str]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										# create random PyTorch tensors
										_SCREAMING_SNAKE_CASE			  =prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_a				,    torchify=_a  )
										for image in image_inputs:
														self.assertIsInstance(_a				,    torch.Tensor  )

										# Test not batched input
										_SCREAMING_SNAKE_CASE			  =(
										    (self.image_processor_tester.patch_size['''height'''] * self.image_processor_tester.patch_size['''width'''])
										    * self.image_processor_tester.num_channels
										) + 2

										for max_patch in self.image_processor_tester.max_patches:
														# Test not batched input
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    image_inputs[0]				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (1, max_patch, expected_hidden_dim)				,    )

														# Test batched
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    _a				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,    )

@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11   ,     reason="`Pix2StructImageProcessor` requires `torch>=1.11.0`."   ,     )
@require_torch
@require_vision
class 						A__							(		UpperCamelCase__   ,     unittest.TestCase  ):
						UpperCAmelCase             =						PixaStructImageProcessor if is_vision_available() else None




						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =PixaStructImageProcessingTester(self				,    num_channels=4  )
										_SCREAMING_SNAKE_CASE			  =3




						@property
						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     List[str]:


										"""simple docstring"""





										return self.image_processor_tester.prepare_image_processor_dict()




						def 							__UpperCamelCase				(       self					:      Dict  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										self.assertTrue(hasattr(_a				,    '''do_normalize'''  )  )
										self.assertTrue(hasattr(_a				,    '''do_convert_rgb'''  )  )




						def 							__UpperCamelCase				(       self					:      Dict  )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.image_processing_class(**self.image_processor_dict  )
										# create random PIL images
										_SCREAMING_SNAKE_CASE			  =prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_a  )
										for image in image_inputs:
														self.assertIsInstance(_a				,    Image.Image  )

										# Test not batched input
										_SCREAMING_SNAKE_CASE			  =(
										    (self.image_processor_tester.patch_size['''height'''] * self.image_processor_tester.patch_size['''width'''])
										    * (self.image_processor_tester.num_channels - 1)
										) + 2

										for max_patch in self.image_processor_tester.max_patches:
														# Test not batched input
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    image_inputs[0]				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (1, max_patch, expected_hidden_dim)				,    )

														# Test batched
														_SCREAMING_SNAKE_CASE			  =image_processor(
														    _a				,    return_tensors='''pt'''				,    max_patches=_a  ).flattened_patches
														self.assertEqual(
														    encoded_images.shape				,    (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)				,    )