
"""simple docstring"""







import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


_SCREAMING_SNAKE_CASE	       =False







class 							__magic_name__     (		unittest.TestCase   ):
					pass







@nightly
@require_torch_gpu
class 							__magic_name__     (		unittest.TestCase   ):





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





					def 							lowerCAmelCase      (				self   :							int    ):
												__snake_case     			=       VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"    )
												# remove text_unet
												pipe.remove_unused_weights()
												pipe.to(lowerCAmelCase_    )
												pipe.set_progress_bar_config(disable=lowerCAmelCase_    )

												__snake_case     			=       "A painting of a squirrel eating a burger "
												__snake_case     			=       torch.manual_seed(0    )
												__snake_case     			=       pipe(
												    prompt=lowerCAmelCase_							,						generator=lowerCAmelCase_							,						guidance_scale=7.5							,						num_inference_steps=2							,						output_type="numpy"    ).images

												with tempfile.TemporaryDirectory() as tmpdirname:
																			pipe.save_pretrained(lowerCAmelCase_    )
																			__snake_case     			=       VersatileDiffusionTextToImagePipeline.from_pretrained(lowerCAmelCase_    )
												pipe.to(lowerCAmelCase_    )
												pipe.set_progress_bar_config(disable=lowerCAmelCase_    )

												__snake_case     			=       generator.manual_seed(0    )
												__snake_case     			=       pipe(
												    prompt=lowerCAmelCase_							,						generator=lowerCAmelCase_							,						guidance_scale=7.5							,						num_inference_steps=2							,						output_type="numpy"    ).images

												assert np.abs(image - new_image    ).sum() < 1e-5, "Models don't have the same forward pass"





					def 							lowerCAmelCase      (				self   :							Tuple    ):
												__snake_case     			=       VersatileDiffusionTextToImagePipeline.from_pretrained(
												    "shi-labs/versatile-diffusion"							,						torch_dtype=torch.floataa    )
												pipe.to(lowerCAmelCase_    )
												pipe.set_progress_bar_config(disable=lowerCAmelCase_    )

												__snake_case     			=       "A painting of a squirrel eating a burger "
												__snake_case     			=       torch.manual_seed(0    )
												__snake_case     			=       pipe(
												    prompt=lowerCAmelCase_							,						generator=lowerCAmelCase_							,						guidance_scale=7.5							,						num_inference_steps=50							,						output_type="numpy"    ).images

												__snake_case     			=       image[0, 253:256, 253:256, -1]

												assert image.shape == (1, 512, 512, 3)
												__snake_case     			=       np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]    )

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


"""simple docstring"""







import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE )  ->     str:







							"""simple docstring"""


							__snake_case     			=       []
							for line in lines:
														__snake_case     			=       re.sub(r"#.*"							,    ""							,    SCREAMING_SNAKE_CASE )  # remove comments
														if line:
																					filtered_lines.append(SCREAMING_SNAKE_CASE )
							__snake_case     			=       "\n".join(SCREAMING_SNAKE_CASE )

							# Make a hash from all this code
							__snake_case     			=       full_str.encode("utf-8" )
							return shaaaa(SCREAMING_SNAKE_CASE ).hexdigest()


# get importable module names and hash for caching
_SCREAMING_SNAKE_CASE	       =      {
    """csv""": (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    """json""": (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    """pandas""": (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    """parquet""": (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    """arrow""": (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    """text""": (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    """imagefolder""": (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    """audiofolder""": (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
_SCREAMING_SNAKE_CASE	       =      {
    """.csv""": ("""csv""", {}),
    """.tsv""": ("""csv""", {"""sep""": """\t"""}),
    """.json""": ("""json""", {}),
    """.jsonl""": ("""json""", {}),
    """.parquet""": ("""parquet""", {}),
    """.arrow""": ("""arrow""", {}),
    """.txt""": ("""text""", {}),
}
_EXTENSION_TO_MODULE.update({ext: ("""imagefolder""", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("""imagefolder""", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ("""audiofolder""", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("""audiofolder""", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_SCREAMING_SNAKE_CASE	       =      {"""imagefolder""", """audiofolder"""}

# Used to filter data files based on extensions given a module name
_SCREAMING_SNAKE_CASE	       =      {}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
		_MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append(""".zip""")



_MODULE_TO_EXTENSIONS["audiofolder"].append(""".zip""")
