






import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()



@slow
@require_torch_gpu
class 							SCREAMING_SNAKE_CASE__		(       unittest.TestCase		):





					"""simple docstring"""






					def  _lowercase  (      self  :						str ):
						# clean up the VRAM after each test
						super().tearDown()
						gc.collect()
						torch.cuda.empty_cache()



					def  _lowercase  (      self  :						Optional[int] ):
						snake_case__				:   Any     =						StableDiffusionKDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4" )
						snake_case__				:   int     =						sd_pipe.to(__A )
						sd_pipe.set_progress_bar_config(disable=__A )

						sd_pipe.set_scheduler("sample_euler" )

						snake_case__				:   Optional[int]     =						"A painting of a squirrel eating a burger"
						snake_case__				:   int     =						torch.manual_seed(0 )
						snake_case__				:   Dict     =						sd_pipe([prompt]							,	generator=__A							,	guidance_scale=9.0							,	num_inference_steps=2_0							,	output_type="np" )

						snake_case__				:   str     =						output.images

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

						assert image.shape == (1, 5_1_2, 5_1_2, 3)
						snake_case__				:   Union[str, Any]     =						np.array([0.0_4_4_7, 0.0_4_9_2, 0.0_4_6_8, 0.0_4_0_8, 0.0_3_8_3, 0.0_4_0_8, 0.0_3_5_4, 0.0_3_8_0, 0.0_3_3_9] )

						assert np.abs(image_slice.flatten() - expected_slice ).max() < 1e-2



					def  _lowercase  (      self  :						Any ):
						snake_case__				:   Tuple     =						StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base" )
						snake_case__				:   str     =						sd_pipe.to(__A )
						sd_pipe.set_progress_bar_config(disable=__A )

						sd_pipe.set_scheduler("sample_euler" )

						snake_case__				:   Dict     =						"A painting of a squirrel eating a burger"
						snake_case__				:   Tuple     =						torch.manual_seed(0 )
						snake_case__				:   int     =						sd_pipe([prompt]							,	generator=__A							,	guidance_scale=9.0							,	num_inference_steps=2_0							,	output_type="np" )

						snake_case__				:   Any     =						output.images

						snake_case__				:   Dict     =						image[0, -3:, -3:, -1]

						assert image.shape == (1, 5_1_2, 5_1_2, 3)
						snake_case__				:   Any     =						np.array([0.1_2_3_7, 0.1_3_2_0, 0.1_4_3_8, 0.1_3_5_9, 0.1_3_9_0, 0.1_1_3_2, 0.1_2_7_7, 0.1_1_7_5, 0.1_1_1_2] )

						assert np.abs(image_slice.flatten() - expected_slice ).max() < 5e-1






					def  _lowercase  (      self  :						Dict ):
						snake_case__				:   Optional[int]     =						StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base" )
						snake_case__				:   List[Any]     =						sd_pipe.to(__A )
						sd_pipe.set_progress_bar_config(disable=__A )

						sd_pipe.set_scheduler("sample_dpmpp_2m" )

						snake_case__				:   int     =						"A painting of a squirrel eating a burger"
						snake_case__				:   str     =						torch.manual_seed(0 )
						snake_case__				:   Optional[Any]     =						sd_pipe(
						    [prompt]							,	generator=__A							,	guidance_scale=7.5							,	num_inference_steps=1_5							,	output_type="np"							,	use_karras_sigmas=__A							,	)

						snake_case__				:   Dict     =						output.images

						snake_case__				:   List[str]     =						image[0, -3:, -3:, -1]

						assert image.shape == (1, 5_1_2, 5_1_2, 3)
						snake_case__				:   Any     =						np.array(
						    [0.1_1_3_8_1_6_8_9, 0.1_2_1_1_2_9_2_1, 0.1_3_8_9_4_5_7, 0.1_2_5_4_9_6_0_6, 0.1_2_4_4_9_6_4, 0.1_0_8_3_1_5_1_7, 0.1_1_5_6_2_8_6_6, 0.1_0_8_6_7_8_1_6, 0.1_0_4_9_9_0_4_8] )

						assert np.abs(image_slice.flatten() - expected_slice ).max() < 1e-2











# Lint as: python3
# pylint: enable=line-too-long
# pylint: disable=g-import-not-at-top,g-bad-import-order,wrong-import-position

__lowerCamelCase      :    Union[str, Any]   		=   """2.13.1"""

import platform

import pyarrow
from packaging import version


if version.parse(platform.python_version()) < version.parse("""3.7"""):
	raise ImportWarning(
	    """To use `datasets`, Python>=3.7 is required, and the current version of Python doesn't match this condition."""
	)

if version.parse(pyarrow.__version__).major < 8:
	raise ImportWarning(
	    """To use `datasets`, the module `pyarrow>=8.0.0` is required, and the current version of `pyarrow` doesn't match this condition.\n"""
	    """If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of `pyarrow`."""
	)

del platform
del pyarrow
del version

from .arrow_dataset import Dataset
from .arrow_reader import ReadInstruction
from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder
from .combine import concatenate_datasets, interleave_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .download import *
from .features import *
from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
from .info import DatasetInfo, MetricInfo
from .inspect import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
    list_datasets,
    list_metrics,
)
from .iterable_dataset import IterableDataset
from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric
from .metric import Metric
from .splits import (
    NamedSplit,
    NamedSplitAll,
    Split,
    SplitBase,
    SplitDict,
    SplitGenerator,
    SplitInfo,
    SubSplitInfo,
    percent,
)
from .tasks import *
from .utils import *
from .utils import logging


# deprecated modules
from datasets import arrow_dataset as _arrow_dataset  # isort:skip
from datasets import utils as _utils  # isort:skip
from datasets.utils import download_manager as _deprecated_download_manager  # isort:skip

__lowerCamelCase      :    List[Any]   		=   concatenate_datasets
__lowerCamelCase      :    List[str]   		=   DownloadConfig
__lowerCamelCase      :    Union[str, Any]   		=   DownloadManager
__lowerCamelCase      :    str   		=   DownloadMode
__lowerCamelCase      :    Union[str, Any]   		=   DownloadConfig
__lowerCamelCase      :    List[str]   		=   DownloadMode
__lowerCamelCase      :    Dict   		=   DownloadManager

del _arrow_dataset, _utils, _deprecated_download_manager



