Skip to content

Commit

Permalink
[CI] Update Single file Nightly Tests (huggingface#9357)
Browse files Browse the repository at this point in the history
* update

* update
  • Loading branch information
DN6 authored Sep 5, 2024
1 parent 3000551 commit 53051cf
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 58 deletions.
25 changes: 13 additions & 12 deletions tests/single_file/single_file_testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torch
from huggingface_hub import hf_hub_download, snapshot_download

from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.models.attention_processor import AttnProcessor
from diffusers.utils.testing_utils import (
numpy_cosine_similarity_distance,
Expand Down Expand Up @@ -98,8 +99,8 @@ def test_single_file_components_local_files_only(self, pipe=None, single_file_pi
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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)

single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
local_ckpt_path, safety_checker=None, local_files_only=True
Expand Down Expand Up @@ -138,8 +139,8 @@ def test_single_file_components_with_original_config_local_files_only(
upcast_attention = pipe.unet.config.upcast_attention

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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)

single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
Expand Down Expand Up @@ -191,8 +192,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)

single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
Expand Down Expand Up @@ -286,8 +287,8 @@ def test_single_file_components_local_files_only(
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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)

single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
local_ckpt_path, safety_checker=None, local_files_only=True
Expand Down Expand Up @@ -327,8 +328,8 @@ def test_single_file_components_with_original_config_local_files_only(
upcast_attention = pipe.unet.config.upcast_attention

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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)

single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
Expand Down Expand Up @@ -364,8 +365,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(
pipe = pipe or self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)

single_file_pipe = single_file_pipe or self.pipeline_class.from_single_file(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torch

from diffusers import ControlNetModel, StableDiffusionControlNetPipeline
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
enable_full_determinism,
Expand All @@ -29,11 +30,11 @@
@require_torch_gpu
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionControlNetPipeline
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
original_config = (
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
)
repo_id = "runwayml/stable-diffusion-v1-5"
repo_id = "Lykon/dreamshaper-8"

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -108,8 +109,8 @@ def test_single_file_components_local_files_only(self):
pipe = self.pipeline_class.from_pretrained(self.repo_id, controlnet=controlnet)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
repo_id, weights_name = _extract_repo_id_and_weights_name(self.ckpt_path)
local_ckpt_path = download_single_file_checkpoint(repo_id, weights_name, tmpdir)

pipe_single_file = self.pipeline_class.from_single_file(
local_ckpt_path, controlnet=controlnet, safety_checker=None, local_files_only=True
Expand All @@ -136,8 +137,9 @@ def test_single_file_components_with_original_config_local_files_only(self):
)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
repo_id, weights_name = _extract_repo_id_and_weights_name(self.ckpt_path)
local_ckpt_path = download_single_file_checkpoint(repo_id, weights_name, tmpdir)

local_original_config = download_original_config(self.original_config, tmpdir)

pipe_single_file = self.pipeline_class.from_single_file(
Expand Down Expand Up @@ -168,8 +170,9 @@ def test_single_file_components_with_diffusers_config_local_files_only(self):
)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, tmpdir)
repo_id, weights_name = _extract_repo_id_and_weights_name(self.ckpt_path)
local_ckpt_path = download_single_file_checkpoint(repo_id, weights_name, tmpdir)

local_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)

pipe_single_file = self.pipeline_class.from_single_file(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torch

from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
enable_full_determinism,
Expand All @@ -28,9 +29,9 @@
@require_torch_gpu
class StableDiffusionControlNetInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionControlNetInpaintPipeline
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_INPAINTING.inpainting.safetensors"
original_config = "https://raw.githubusercontent.com/runwayml/stable-diffusion/main/configs/stable-diffusion/v1-inpainting-inference.yaml"
repo_id = "runwayml/stable-diffusion-inpainting"
repo_id = "Lykon/dreamshaper-8-inpainting"

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -83,7 +84,7 @@ def test_single_file_format_inference_is_same_as_pretrained(self):
output_sf = pipe_sf(**inputs).images[0]

max_diff = numpy_cosine_similarity_distance(output_sf.flatten(), output.flatten())
assert max_diff < 1e-3
assert max_diff < 2e-3

def test_single_file_components(self):
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny")
Expand All @@ -103,15 +104,16 @@ def test_single_file_components_local_files_only(self):
pipe = self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None, controlnet=controlnet)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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)

pipe_single_file = self.pipeline_class.from_single_file(
local_ckpt_path, controlnet=controlnet, safety_checker=None, local_files_only=True
)

super()._compare_component_configs(pipe, pipe_single_file)

@unittest.skip("runwayml original config repo does not exist")
def test_single_file_components_with_original_config(self):
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny", variant="fp16")
pipe = self.pipeline_class.from_pretrained(self.repo_id, controlnet=controlnet)
Expand All @@ -121,6 +123,7 @@ def test_single_file_components_with_original_config(self):

super()._compare_component_configs(pipe, pipe_single_file)

@unittest.skip("runwayml original config repo does not exist")
def test_single_file_components_with_original_config_local_files_only(self):
controlnet = ControlNetModel.from_pretrained(
"lllyasviel/control_v11p_sd15_canny", torch_dtype=torch.float16, variant="fp16"
Expand All @@ -132,8 +135,8 @@ def test_single_file_components_with_original_config_local_files_only(self):
)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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_single_file = self.pipeline_class.from_single_file(
Expand Down Expand Up @@ -169,8 +172,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(self):
)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)

pipe_single_file = self.pipeline_class.from_single_file(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import torch

from diffusers import ControlNetModel, StableDiffusionControlNetPipeline
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
enable_full_determinism,
Expand All @@ -28,11 +29,11 @@
@require_torch_gpu
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionControlNetPipeline
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
original_config = (
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
)
repo_id = "runwayml/stable-diffusion-v1-5"
repo_id = "Lykon/dreamshaper-8"

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -98,8 +99,8 @@ def test_single_file_components_local_files_only(self):
pipe = self.pipeline_class.from_pretrained(self.repo_id, controlnet=controlnet)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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)

pipe_single_file = self.pipeline_class.from_single_file(
local_ckpt_path, controlnet=controlnet, local_files_only=True
Expand All @@ -126,8 +127,8 @@ def test_single_file_components_with_original_config_local_files_only(self):
)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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_single_file = self.pipeline_class.from_single_file(
Expand Down Expand Up @@ -157,8 +158,8 @@ def test_single_file_components_with_diffusers_config_local_files_only(self):
)

with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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_diffusers_config = download_diffusers_config(self.repo_id, tmpdir)

pipe_single_file = self.pipeline_class.from_single_file(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
@require_torch_gpu
class StableDiffusionImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionImg2ImgPipeline
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
original_config = (
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
)
repo_id = "runwayml/stable-diffusion-v1-5"
repo_id = "Lykon/dreamshaper-8"

def setUp(self):
super().setUp()
Expand Down
14 changes: 11 additions & 3 deletions tests/single_file/test_stable_diffusion_inpaint_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
@require_torch_gpu
class StableDiffusionInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionInpaintPipeline
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_INPAINTING.inpainting.safetensors"
original_config = "https://raw.githubusercontent.com/runwayml/stable-diffusion/main/configs/stable-diffusion/v1-inpainting-inference.yaml"
repo_id = "runwayml/stable-diffusion-inpainting"
repo_id = "Lykon/dreamshaper-8-inpainting"

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -63,11 +63,19 @@ def test_single_file_format_inference_is_same_as_pretrained(self):

def test_single_file_loading_4_channel_unet(self):
# Test loading single file inpaint with a 4 channel UNet
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
pipe = self.pipeline_class.from_single_file(ckpt_path)

assert pipe.unet.config.in_channels == 4

@unittest.skip("runwayml original config has been removed")
def test_single_file_components_with_original_config(self):
return

@unittest.skip("runwayml original config has been removed")
def test_single_file_components_with_original_config_local_files_only(self):
return


@slow
@require_torch_gpu
Expand Down
9 changes: 5 additions & 4 deletions tests/single_file/test_stable_diffusion_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 (
enable_full_determinism,
require_torch_gpu,
Expand All @@ -25,11 +26,11 @@
@require_torch_gpu
class StableDiffusionPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionPipeline
ckpt_path = "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors"
ckpt_path = "https://huggingface.co/Lykon/DreamShaper/blob/main/DreamShaper_8_pruned.safetensors"
original_config = (
"https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
)
repo_id = "runwayml/stable-diffusion-v1-5"
repo_id = "Lykon/dreamshaper-8"

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -58,8 +59,8 @@ def test_single_file_format_inference_is_same_as_pretrained(self):

def test_single_file_legacy_scheduler_loading(self):
with tempfile.TemporaryDirectory() as tmpdir:
ckpt_filename = self.ckpt_path.split("/")[-1]
local_ckpt_path = download_single_file_checkpoint(self.repo_id, ckpt_filename, 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(
Expand Down
Loading

0 comments on commit 53051cf

Please sign in to comment.