



lowerCamelCase__			= """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 itertools
import os
import random
import tempfile
import unittest

import numpy as np

from transformers import TvltFeatureExtractor, is_datasets_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
						import torch

if is_datasets_available():
						from datasets import load_dataset

lowerCamelCase__			= random.Random()

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			List[str]				,     _SCREAMING_SNAKE_CASE       :			int=1.0				,     _SCREAMING_SNAKE_CASE       :			Any=None				,     _SCREAMING_SNAKE_CASE       :			Any=None    ):
				"""simple docstring"""







				if rng is None:
								__a       =		global_rng

				__a       =		[]
				for batch_idx in range(shape[0]    ):
								values.append([]    )
								for _ in range(shape[1]    ):
												values[-1].append(rng.random() * scale    )

				return values






class    SCREAMING_SNAKE_CASE			(							unittest.TestCase					):





							def __init__(   self		:		Dict      ,				__lowercase		:		Tuple      ,				__lowercase		:		Tuple=7      ,				__lowercase		:		Optional[int]=400      ,				__lowercase		:		int=2000      ,				__lowercase		:		List[Any]=2048      ,				__lowercase		:		List[str]=128      ,				__lowercase		:		Union[str, Any]=1      ,				__lowercase		:		str=512      ,				__lowercase		:		List[str]=30      ,				__lowercase		:		Tuple=44100      ,				):

											'''simple docstring'''
											__a       =		parent
											__a       =		batch_size
											__a       =		min_seq_length
											__a       =		max_seq_length
											__a       =		(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
											__a       =		spectrogram_length
											__a       =		feature_size
											__a       =		num_audio_channels
											__a       =		hop_length
											__a       =		chunk_length
											__a       =		sampling_rate





							def 						UpperCamelCase_					(   self		:		Optional[int]	):

											'''simple docstring'''
											return {
											    "spectrogram_length": self.spectrogram_length,
											    "feature_size": self.feature_size,
											    "num_audio_channels": self.num_audio_channels,
											    "hop_length": self.hop_length,
											    "chunk_length": self.chunk_length,
											    "sampling_rate": self.sampling_rate,
											}







							def 						UpperCamelCase_					(   self		:		Optional[int]      ,				__lowercase		:		Optional[int]=False      ,				__lowercase		:		Any=False	):

											'''simple docstring'''
											def _flatten(__lowercase		:		Tuple	):
															return list(itertools.chain(*__lowercase	)	)

											if equal_length:
															__a       =		[floats_list((self.max_seq_length, self.feature_size)	) for _ in range(self.batch_size	)]
											else:
															# make sure that inputs increase in size
															__a       =		[
															    floats_list((x, self.feature_size)	)
															    for x in range(self.min_seq_length      ,				self.max_seq_length      ,				self.seq_length_diff	)
															]
											if numpify:
															__a       =		[np.asarray(__lowercase	) for x in speech_inputs]
											return speech_inputs






@require_torch
@require_torchaudio
class    SCREAMING_SNAKE_CASE			(							lowerCamelCase__			,      unittest.TestCase					):
							__lowerCamelCase	:	Dict    =TvltFeatureExtractor





							def 						UpperCamelCase_					(   self		:		Any	):

											'''simple docstring'''
											__a       =		TvltFeatureExtractionTester(self	)





							def 						UpperCamelCase_					(   self		:		int	):

											'''simple docstring'''
											__a       =		self.feature_extraction_class(**self.feat_extract_dict	)
											self.assertTrue(hasattr(__lowercase      ,				"""spectrogram_length"""	)	)
											self.assertTrue(hasattr(__lowercase      ,				"""feature_size"""	)	)
											self.assertTrue(hasattr(__lowercase      ,				"""num_audio_channels"""	)	)
											self.assertTrue(hasattr(__lowercase      ,				"""hop_length"""	)	)
											self.assertTrue(hasattr(__lowercase      ,				"""chunk_length"""	)	)
											self.assertTrue(hasattr(__lowercase      ,				"""sampling_rate"""	)	)





							def 						UpperCamelCase_					(   self		:		List[str]	):

											'''simple docstring'''
											__a       =		self.feature_extraction_class(**self.feat_extract_dict	)

											with tempfile.TemporaryDirectory() as tmpdirname:
															__a       =		feat_extract_first.save_pretrained(__lowercase	)[0]
															check_json_file_has_correct_format(__lowercase	)
															__a       =		self.feature_extraction_class.from_pretrained(__lowercase	)

											__a       =		feat_extract_first.to_dict()
											__a       =		feat_extract_second.to_dict()
											__a       =		dict_first.pop("""mel_filters"""	)
											__a       =		dict_second.pop("""mel_filters"""	)
											self.assertTrue(np.allclose(__lowercase      ,				__lowercase	)	)
											self.assertEqual(__lowercase      ,				__lowercase	)





							def 						UpperCamelCase_					(   self		:		Optional[int]	):

											'''simple docstring'''
											__a       =		self.feature_extraction_class(**self.feat_extract_dict	)

											with tempfile.TemporaryDirectory() as tmpdirname:
															__a       =		os.path.join(__lowercase      ,				"""feat_extract.json"""	)
															feat_extract_first.to_json_file(__lowercase	)
															__a       =		self.feature_extraction_class.from_json_file(__lowercase	)

											__a       =		feat_extract_first.to_dict()
											__a       =		feat_extract_second.to_dict()
											__a       =		dict_first.pop("""mel_filters"""	)
											__a       =		dict_second.pop("""mel_filters"""	)
											self.assertTrue(np.allclose(__lowercase      ,				__lowercase	)	)
											self.assertEqual(__lowercase      ,				__lowercase	)





							def 						UpperCamelCase_					(   self		:		Dict	):

											'''simple docstring'''
											# Initialize feature_extractor
											__a       =		self.feature_extraction_class(**self.feat_extract_dict	)

											# create three inputs of length 800, 1000, and 1200
											__a       =		[floats_list((1, x)	)[0] for x in range(800      ,				1400      ,				200	)]
											__a       =		[np.asarray(__lowercase	) for speech_input in speech_inputs]

											# Test not batched input
											__a       =		feature_extractor(np_speech_inputs[0]      ,				return_tensors="""np"""      ,				sampling_rate=44100	).audio_values

											self.assertTrue(encoded_audios.ndim == 4	)
											self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size	)
											self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length	)
											self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels	)

											# Test batched
											__a       =		feature_extractor(__lowercase      ,				return_tensors="""np"""      ,				sampling_rate=44100	).audio_values

											self.assertTrue(encoded_audios.ndim == 4	)
											self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size	)
											self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length	)
											self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels	)

											# Test audio masking
											__a       =		feature_extractor(
											    __lowercase      ,				return_tensors="""np"""      ,				sampling_rate=44100      ,				mask_audio=__lowercase	).audio_values

											self.assertTrue(encoded_audios.ndim == 4	)
											self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size	)
											self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length	)
											self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels	)

											# Test 2-D numpy arrays are batched.
											__a       =		[floats_list((1, x)	)[0] for x in (800, 800, 800)]
											__a       =		np.asarray(__lowercase	)
											__a       =		feature_extractor(__lowercase      ,				return_tensors="""np"""      ,				sampling_rate=44100	).audio_values
											self.assertTrue(encoded_audios.ndim == 4	)
											self.assertTrue(encoded_audios.shape[-1] == feature_extractor.feature_size	)
											self.assertTrue(encoded_audios.shape[-2] <= feature_extractor.spectrogram_length	)
											self.assertTrue(encoded_audios.shape[-3] == feature_extractor.num_channels	)





							def 						UpperCamelCase_					(   self		:		Optional[int]      ,				__lowercase		:		str	):

											'''simple docstring'''
											__a       =		load_dataset("""hf-internal-testing/librispeech_asr_dummy"""      ,				"""clean"""      ,				split="""validation"""	)
											# automatic decoding with librispeech
											__a       =		ds.sort("""id"""	).select(range(__lowercase	)	)[:num_samples]["""audio"""]

											return [x["array"] for x in speech_samples]







							def 						UpperCamelCase_					(   self		:		str	):

											'''simple docstring'''
											__a       =		self._load_datasamples(1	)
											__a       =		TvltFeatureExtractor()
											__a       =		feature_extractor(__lowercase      ,				return_tensors="""pt"""	).audio_values

											self.assertEquals(audio_values.shape      ,				(1, 1, 192, 128)	)

											__a       =		torch.tensor([[-0.3032, -0.2708], [-0.4434, -0.4007]]	)
											self.assertTrue(torch.allclose(audio_values[0, 0, :2, :2]      ,				__lowercase      ,				atol=1E-4	)	)
