






'''simple docstring'''

from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset







class 	SCREAMING_SNAKE_CASE	(      lowerCAmelCase_  ):




       def 					a_					(					self      : Any					):


            """simple docstring"""







            return [
                {"col_1": 3, "col_2": "a"},
                {"col_1": 2, "col_2": "b"},
                {"col_1": 1, "col_2": "c"},
                {"col_1": 0, "col_2": "d"},
            ]




       def 					a_					(					self      : Optional[Any]					):


            """simple docstring"""







            __lowerCamelCase						:       int				   =				{"""col_1""": [3, 2, 1, 0], """col_2""": ["""a""", """b""", """c""", """d"""]}
            return Dataset.from_dict(A__					)




       def 					a_					(					self      : Any					):


            """simple docstring"""







            __lowerCamelCase						:       Optional[Any]				   =				self._create_example_records()
            __lowerCamelCase						:       Optional[int]				   =				Dataset.from_list(A__					)
            self.assertListEqual(dset.column_names	,    ["""col_1""", """col_2"""]					)
            for i, r in enumerate(A__					):
                 self.assertDictEqual(A__	,    example_records[i]					)




       def 					a_					(					self      : Tuple					):


            """simple docstring"""







            __lowerCamelCase						:       List[Any]				   =				self._create_example_records()
            __lowerCamelCase						:       List[str]				   =				Dataset.from_list(A__					)
            __lowerCamelCase						:       List[Any]				   =				Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]}					)
            self.assertEqual(dset.info	,    dset_from_dict.info					)




       def 					a_					(					self      : List[str]					):  # checks what happens with missing columns


            """simple docstring"""







            __lowerCamelCase						:       Dict				   =				[{"""col_1""": 1}, {"""col_2""": """x"""}]
            __lowerCamelCase						:       Dict				   =				Dataset.from_list(A__					)
            self.assertDictEqual(dset[0]	,    {"""col_1""": 1}					)
            self.assertDictEqual(dset[1]	,    {"""col_1""": None}					)  # NB: first record is used for columns




       def 					a_					(					self      : Tuple					):  # checks if the type can be inferred from the second record


            """simple docstring"""







            __lowerCamelCase						:       Optional[Any]				   =				[{"""col_1""": []}, {"""col_1""": [1, 2]}]
            __lowerCamelCase						:       Dict				   =				Dataset.from_list(A__					)
            self.assertEqual(dset.info.features["""col_1"""]	,    Sequence(Value("""int64"""					)					)					)




       def 					a_					(					self      : List[str]					):


            """simple docstring"""







            __lowerCamelCase						:       Union[str, Any]				   =				Dataset.from_list([]					)
            self.assertEqual(len(A__					)	,    0					)
            self.assertListEqual(dset.column_names	,    []					)











'''simple docstring'''

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  ):




       def 					a_					(					self      : Union[str, Any]					):


            """simple docstring"""







            super().tearDown()
            gc.collect()
            torch.cuda.empty_cache()




       def 					a_					(					self      : Optional[int]					):


            """simple docstring"""







            __lowerCamelCase						:       Dict				   =				StableDiffusionKDiffusionPipeline.from_pretrained("""CompVis/stable-diffusion-v1-4"""					)
            __lowerCamelCase						:       Tuple				   =				sd_pipe.to(A__					)
            sd_pipe.set_progress_bar_config(disable=A__					)

            sd_pipe.set_scheduler("""sample_euler"""					)

            __lowerCamelCase						:       Any				   =				"""A painting of a squirrel eating a burger"""
            __lowerCamelCase						:       List[Any]				   =				torch.manual_seed(0					)
            __lowerCamelCase						:       Dict				   =				sd_pipe([prompt]	,    generator=A__	,    guidance_scale=9.0	,    num_inference_steps=20	,    output_type="""np"""					)

            __lowerCamelCase						:       Tuple				   =				output.images

            __lowerCamelCase						:       int				   =				image[0, -3:, -3:, -1]

            assert image.shape == (1, 512, 512, 3)
            __lowerCamelCase						:       List[str]				   =				np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]					)

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




       def 					a_					(					self      : Dict					):


            """simple docstring"""







            __lowerCamelCase						:       Any				   =				StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""					)
            __lowerCamelCase						:       int				   =				sd_pipe.to(A__					)
            sd_pipe.set_progress_bar_config(disable=A__					)

            sd_pipe.set_scheduler("""sample_euler"""					)

            __lowerCamelCase						:       List[Any]				   =				"""A painting of a squirrel eating a burger"""
            __lowerCamelCase						:       Union[str, Any]				   =				torch.manual_seed(0					)
            __lowerCamelCase						:       int				   =				sd_pipe([prompt]	,    generator=A__	,    guidance_scale=9.0	,    num_inference_steps=20	,    output_type="""np"""					)

            __lowerCamelCase						:       List[str]				   =				output.images

            __lowerCamelCase						:       Optional[int]				   =				image[0, -3:, -3:, -1]

            assert image.shape == (1, 512, 512, 3)
            __lowerCamelCase						:       Optional[int]				   =				np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]					)

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




       def 					a_					(					self      : str					):


            """simple docstring"""







            __lowerCamelCase						:       List[str]				   =				StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""					)
            __lowerCamelCase						:       List[str]				   =				sd_pipe.to(A__					)
            sd_pipe.set_progress_bar_config(disable=A__					)

            sd_pipe.set_scheduler("""sample_dpmpp_2m"""					)

            __lowerCamelCase						:       int				   =				"""A painting of a squirrel eating a burger"""
            __lowerCamelCase						:       Tuple				   =				torch.manual_seed(0					)
            __lowerCamelCase						:       Union[str, Any]				   =				sd_pipe(
                [prompt]	,    generator=A__	,    guidance_scale=7.5	,    num_inference_steps=15	,    output_type="""np"""	,    use_karras_sigmas=A__	,    )

            __lowerCamelCase						:       int				   =				output.images

            __lowerCamelCase						:       Any				   =				image[0, -3:, -3:, -1]

            assert image.shape == (1, 512, 512, 3)
            __lowerCamelCase						:       int				   =				np.array(
                [0.1138_1689, 0.1211_2921, 0.138_9457, 0.1254_9606, 0.124_4964, 0.1083_1517, 0.1156_2866, 0.1086_7816, 0.1049_9048]					)

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



