mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-29 07:22:12 +03:00
* enable on xpu * add 1 more * add one more * enable more * add 1 more * add more * enable 1 * enable more cases * enable * enable * update comment * one more * enable 1 * add more cases * enable xpu * add one more caswe * add more cases * add 1 * add more * add more cases * add case * enable * add more * add more * add more * enbale more * add more * update code * update test marker * add skip back * update comment * remove single files * remove * style * add * revert * reformat * enable * enable esingle g * add 2 more * update decorator * update * update * update * Update tests/pipelines/deepfloyd_if/test_if.py Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * Update src/diffusers/utils/testing_utils.py Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * Update tests/pipelines/animatediff/test_animatediff_controlnet.py Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * Update tests/pipelines/animatediff/test_animatediff.py Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * Update tests/pipelines/animatediff/test_animatediff_controlnet.py Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * update float16 * no unitest.skipt * update * apply style check * adapt style --------- Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
121 lines
4.3 KiB
Python
121 lines
4.3 KiB
Python
import gc
|
|
import tempfile
|
|
import unittest
|
|
|
|
import torch
|
|
|
|
from diffusers import EulerDiscreteScheduler, StableDiffusionPipeline
|
|
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
|
|
from diffusers.utils.testing_utils import (
|
|
backend_empty_cache,
|
|
enable_full_determinism,
|
|
require_torch_accelerator,
|
|
slow,
|
|
torch_device,
|
|
)
|
|
|
|
from .single_file_testing_utils import (
|
|
SDSingleFileTesterMixin,
|
|
download_original_config,
|
|
download_single_file_checkpoint,
|
|
)
|
|
|
|
|
|
enable_full_determinism()
|
|
|
|
|
|
@slow
|
|
@require_torch_accelerator
|
|
class StableDiffusionPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
|
|
pipeline_class = StableDiffusionPipeline
|
|
ckpt_path = (
|
|
"https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
|
|
)
|
|
original_config = (
|
|
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
|
|
)
|
|
repo_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
gc.collect()
|
|
backend_empty_cache(torch_device)
|
|
|
|
def tearDown(self):
|
|
super().tearDown()
|
|
gc.collect()
|
|
backend_empty_cache(torch_device)
|
|
|
|
def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
|
|
generator = torch.Generator(device=generator_device).manual_seed(seed)
|
|
inputs = {
|
|
"prompt": "a fantasy landscape, concept art, high resolution",
|
|
"generator": generator,
|
|
"num_inference_steps": 2,
|
|
"strength": 0.75,
|
|
"guidance_scale": 7.5,
|
|
"output_type": "np",
|
|
}
|
|
return inputs
|
|
|
|
def test_single_file_format_inference_is_same_as_pretrained(self):
|
|
super().test_single_file_format_inference_is_same_as_pretrained(expected_max_diff=1e-3)
|
|
|
|
def test_single_file_legacy_scheduler_loading(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
repo_id, weight_name = _extract_repo_id_and_weights_name(self.ckpt_path)
|
|
local_ckpt_path = download_single_file_checkpoint(repo_id, weight_name, tmpdir)
|
|
local_original_config = download_original_config(self.original_config, tmpdir)
|
|
|
|
pipe = self.pipeline_class.from_single_file(
|
|
local_ckpt_path,
|
|
original_config=local_original_config,
|
|
cache_dir=tmpdir,
|
|
local_files_only=True,
|
|
scheduler_type="euler",
|
|
)
|
|
|
|
# Default is PNDM for this checkpoint
|
|
assert isinstance(pipe.scheduler, EulerDiscreteScheduler)
|
|
|
|
def test_single_file_legacy_scaling_factor(self):
|
|
new_scaling_factor = 10.0
|
|
init_pipe = self.pipeline_class.from_single_file(self.ckpt_path)
|
|
pipe = self.pipeline_class.from_single_file(self.ckpt_path, scaling_factor=new_scaling_factor)
|
|
|
|
assert init_pipe.vae.config.scaling_factor != new_scaling_factor
|
|
assert pipe.vae.config.scaling_factor == new_scaling_factor
|
|
|
|
|
|
@slow
|
|
class StableDiffusion21PipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
|
|
pipeline_class = StableDiffusionPipeline
|
|
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.safetensors"
|
|
original_config = "https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml"
|
|
repo_id = "stabilityai/stable-diffusion-2-1"
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
gc.collect()
|
|
backend_empty_cache(torch_device)
|
|
|
|
def tearDown(self):
|
|
super().tearDown()
|
|
gc.collect()
|
|
backend_empty_cache(torch_device)
|
|
|
|
def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
|
|
generator = torch.Generator(device=generator_device).manual_seed(seed)
|
|
inputs = {
|
|
"prompt": "a fantasy landscape, concept art, high resolution",
|
|
"generator": generator,
|
|
"num_inference_steps": 2,
|
|
"strength": 0.75,
|
|
"guidance_scale": 7.5,
|
|
"output_type": "np",
|
|
}
|
|
return inputs
|
|
|
|
def test_single_file_format_inference_is_same_as_pretrained(self):
|
|
super().test_single_file_format_inference_is_same_as_pretrained(expected_max_diff=1e-3)
|