Skip to content

[CI] Nightly Test Updates #9380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions tests/lora/test_lora_layers_sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download
from huggingface_hub.repocard import RepoCard
from safetensors.torch import load_file
from transformers import CLIPTextModel, CLIPTokenizer

Expand Down Expand Up @@ -103,7 +102,7 @@ def tearDown(self):
@slow
@require_torch_gpu
def test_integration_move_lora_cpu(self):
path = "runwayml/stable-diffusion-v1-5"
path = "Jiali/stable-diffusion-1.5"
lora_id = "takuma104/lora-test-text-encoder-lora-target"

pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
Expand Down Expand Up @@ -162,7 +161,7 @@ def test_integration_move_lora_cpu(self):
def test_integration_move_lora_dora_cpu(self):
from peft import LoraConfig

path = "Lykon/dreamshaper-8"
path = "Jiali/stable-diffusion-1.5"
unet_lora_config = LoraConfig(
init_lora_weights="gaussian",
target_modules=["to_k", "to_q", "to_v", "to_out.0"],
Expand Down Expand Up @@ -222,7 +221,7 @@ def tearDown(self):
torch.cuda.empty_cache()

def test_integration_logits_with_scale(self):
path = "runwayml/stable-diffusion-v1-5"
path = "Jiali/stable-diffusion-1.5"
lora_id = "takuma104/lora-test-text-encoder-lora-target"

pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float32)
Expand Down Expand Up @@ -254,7 +253,7 @@ def test_integration_logits_with_scale(self):
release_memory(pipe)

def test_integration_logits_no_scale(self):
path = "runwayml/stable-diffusion-v1-5"
path = "Jiali/stable-diffusion-1.5"
lora_id = "takuma104/lora-test-text-encoder-lora-target"

pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float32)
Expand Down Expand Up @@ -284,8 +283,8 @@ def test_dreambooth_old_format(self):
generator = torch.Generator("cpu").manual_seed(0)

lora_model_id = "hf-internal-testing/lora_dreambooth_dog_example"
card = RepoCard.load(lora_model_id)
base_model_id = card.data.to_dict()["base_model"]

base_model_id = "Jiali/stable-diffusion-1.5"

pipe = StableDiffusionPipeline.from_pretrained(base_model_id, safety_checker=None)
pipe = pipe.to(torch_device)
Expand All @@ -308,8 +307,8 @@ def test_dreambooth_text_encoder_new_format(self):
generator = torch.Generator().manual_seed(0)

lora_model_id = "hf-internal-testing/lora-trained"
card = RepoCard.load(lora_model_id)
base_model_id = card.data.to_dict()["base_model"]

base_model_id = "Jiali/stable-diffusion-1.5"

pipe = StableDiffusionPipeline.from_pretrained(base_model_id, safety_checker=None)
pipe = pipe.to(torch_device)
Expand Down Expand Up @@ -420,7 +419,7 @@ def test_a1111_with_sequential_cpu_offload(self):
def test_kohya_sd_v15_with_higher_dimensions(self):
generator = torch.Generator().manual_seed(0)

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", safety_checker=None).to(
pipe = StableDiffusionPipeline.from_pretrained("Jiali/stable-diffusion-1.5", safety_checker=None).to(
torch_device
)
lora_model_id = "hf-internal-testing/urushisato-lora"
Expand All @@ -444,8 +443,8 @@ def test_vanilla_funetuning(self):
generator = torch.Generator().manual_seed(0)

lora_model_id = "hf-internal-testing/sd-model-finetuned-lora-t4"
card = RepoCard.load(lora_model_id)
base_model_id = card.data.to_dict()["base_model"]

base_model_id = "Jiali/stable-diffusion-1.5"

pipe = StableDiffusionPipeline.from_pretrained(base_model_id, safety_checker=None)
pipe = pipe.to(torch_device)
Expand All @@ -468,7 +467,7 @@ def test_unload_kohya_lora(self):
prompt = "masterpiece, best quality, mountain"
num_inference_steps = 2

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", safety_checker=None).to(
pipe = StableDiffusionPipeline.from_pretrained("Jiali/stable-diffusion-1.5", safety_checker=None).to(
torch_device
)
initial_images = pipe(
Expand Down Expand Up @@ -506,7 +505,7 @@ def test_load_unload_load_kohya_lora(self):
prompt = "masterpiece, best quality, mountain"
num_inference_steps = 2

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", safety_checker=None).to(
pipe = StableDiffusionPipeline.from_pretrained("Jiali/stable-diffusion-1.5", safety_checker=None).to(
torch_device
)
initial_images = pipe(
Expand Down Expand Up @@ -548,9 +547,9 @@ def test_load_unload_load_kohya_lora(self):

def test_not_empty_state_dict(self):
# Makes sure https://github.com/huggingface/diffusers/issues/7054 does not happen again
pipe = AutoPipelineForText2Image.from_pretrained(
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16
).to(torch_device)
pipe = AutoPipelineForText2Image.from_pretrained("Jiali/stable-diffusion-1.5", torch_dtype=torch.float16).to(
torch_device
)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

cached_file = hf_hub_download("hf-internal-testing/lcm-lora-test-sd-v1-5", "test_lora.safetensors")
Expand All @@ -562,9 +561,9 @@ def test_not_empty_state_dict(self):

def test_load_unload_load_state_dict(self):
# Makes sure https://github.com/huggingface/diffusers/issues/7054 does not happen again
pipe = AutoPipelineForText2Image.from_pretrained(
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16
).to(torch_device)
pipe = AutoPipelineForText2Image.from_pretrained("Jiali/stable-diffusion-1.5", torch_dtype=torch.float16).to(
torch_device
)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

cached_file = hf_hub_download("hf-internal-testing/lcm-lora-test-sd-v1-5", "test_lora.safetensors")
Expand All @@ -581,7 +580,7 @@ def test_load_unload_load_state_dict(self):
release_memory(pipe)

def test_sdv1_5_lcm_lora(self):
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe = DiffusionPipeline.from_pretrained("Jiali/stable-diffusion-1.5", torch_dtype=torch.float16)
pipe.to(torch_device)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

Expand Down Expand Up @@ -609,7 +608,7 @@ def test_sdv1_5_lcm_lora(self):
release_memory(pipe)

def test_sdv1_5_lcm_lora_img2img(self):
pipe = AutoPipelineForImage2Image.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe = AutoPipelineForImage2Image.from_pretrained("Jiali/stable-diffusion-1.5", torch_dtype=torch.float16)
pipe.to(torch_device)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

Expand Down Expand Up @@ -650,7 +649,7 @@ def test_sd_load_civitai_empty_network_alpha(self):
This test simply checks that loading a LoRA with an empty network alpha works fine
See: https://github.com/huggingface/diffusers/issues/5606
"""
pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipeline = StableDiffusionPipeline.from_pretrained("Jiali/stable-diffusion-1.5")
pipeline.enable_sequential_cpu_offload()
civitai_path = hf_hub_download("ybelkada/test-ahi-civitai", "ahi_lora_weights.safetensors")
pipeline.load_lora_weights(civitai_path, adapter_name="ahri")
Expand Down
6 changes: 3 additions & 3 deletions tests/models/autoencoders/test_models_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ def test_encode_decode(self):

def test_sd(self):
vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder") # TODO - update
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", vae=vae, safety_checker=None)
pipe = StableDiffusionPipeline.from_pretrained("Jiali/stable-diffusion-1.5", vae=vae, safety_checker=None)
pipe.to(torch_device)

out = pipe(
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def test_sd_f16(self):
"openai/consistency-decoder", torch_dtype=torch.float16
) # TODO - update
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
"Jiali/stable-diffusion-1.5",
torch_dtype=torch.float16,
vae=vae,
safety_checker=None,
Expand All @@ -1124,7 +1124,7 @@ def test_sd_f16(self):
def test_vae_tiling(self):
vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder", torch_dtype=torch.float16)
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", vae=vae, safety_checker=None, torch_dtype=torch.float16
"Jiali/stable-diffusion-1.5", vae=vae, safety_checker=None, torch_dtype=torch.float16
)
pipe.to(torch_device)
pipe.set_progress_bar_config(disable=None)
Expand Down
8 changes: 4 additions & 4 deletions tests/models/unets/test_models_unet_2d_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ def test_compvis_sd_v1_4_fp16(self, seed, timestep, expected_slice):
@require_torch_accelerator
@skip_mps
def test_compvis_sd_v1_5(self, seed, timestep, expected_slice):
model = self.get_unet_model(model_id="runwayml/stable-diffusion-v1-5")
model = self.get_unet_model(model_id="Jiali/stable-diffusion-1.5")
latents = self.get_latents(seed)
encoder_hidden_states = self.get_encoder_hidden_states(seed)

Expand Down Expand Up @@ -1404,7 +1404,7 @@ def test_compvis_sd_v1_5(self, seed, timestep, expected_slice):
)
@require_torch_accelerator_with_fp16
def test_compvis_sd_v1_5_fp16(self, seed, timestep, expected_slice):
model = self.get_unet_model(model_id="runwayml/stable-diffusion-v1-5", fp16=True)
model = self.get_unet_model(model_id="Jiali/stable-diffusion-1.5", fp16=True)
latents = self.get_latents(seed, fp16=True)
encoder_hidden_states = self.get_encoder_hidden_states(seed, fp16=True)

Expand Down Expand Up @@ -1433,7 +1433,7 @@ def test_compvis_sd_v1_5_fp16(self, seed, timestep, expected_slice):
@require_torch_accelerator
@skip_mps
def test_compvis_sd_inpaint(self, seed, timestep, expected_slice):
model = self.get_unet_model(model_id="runwayml/stable-diffusion-inpainting")
model = self.get_unet_model(model_id="botp/stable-diffusion-v1-5-inpainting")
latents = self.get_latents(seed, shape=(4, 9, 64, 64))
encoder_hidden_states = self.get_encoder_hidden_states(seed)

Expand Down Expand Up @@ -1461,7 +1461,7 @@ def test_compvis_sd_inpaint(self, seed, timestep, expected_slice):
)
@require_torch_accelerator_with_fp16
def test_compvis_sd_inpaint_fp16(self, seed, timestep, expected_slice):
model = self.get_unet_model(model_id="runwayml/stable-diffusion-inpainting", fp16=True)
model = self.get_unet_model(model_id="botp/stable-diffusion-v1-5-inpainting", fp16=True)
latents = self.get_latents(seed, shape=(4, 9, 64, 64), fp16=True)
encoder_hidden_states = self.get_encoder_hidden_states(seed, fp16=True)

Expand Down
41 changes: 15 additions & 26 deletions tests/pipelines/amused/test_amused.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokenizer

from diffusers import AmusedPipeline, AmusedScheduler, UVit2DModel, VQModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, slow, torch_device
from diffusers.utils.testing_utils import (
enable_full_determinism,
require_torch_gpu,
slow,
torch_device,
)

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
Expand Down Expand Up @@ -65,19 +69,15 @@ def get_dummy_components(self):
vqvae = VQModel(
act_fn="silu",
block_out_channels=[8],
down_block_types=[
"DownEncoderBlock2D",
],
down_block_types=["DownEncoderBlock2D"],
in_channels=3,
latent_channels=8,
layers_per_block=1,
norm_num_groups=8,
num_vq_embeddings=8,
out_channels=3,
sample_size=8,
up_block_types=[
"UpDecoderBlock2D",
],
up_block_types=["UpDecoderBlock2D"],
mid_block_add_attention=False,
lookup_from_codebook=True,
)
Expand All @@ -96,7 +96,6 @@ def get_dummy_components(self):
)
text_encoder = CLIPTextModelWithProjection(text_encoder_config)
tokenizer = CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip")

components = {
"transformer": transformer,
"scheduler": scheduler,
Expand Down Expand Up @@ -135,47 +134,37 @@ class AmusedPipelineSlowTests(unittest.TestCase):
def test_amused_256(self):
pipe = AmusedPipeline.from_pretrained("amused/amused-256")
pipe.to(torch_device)

image = pipe("dog", generator=torch.Generator().manual_seed(0), num_inference_steps=2, output_type="np").images

image_slice = image[0, -3:, -3:, -1].flatten()

assert image.shape == (1, 256, 256, 3)
expected_slice = np.array([0.4011, 0.3992, 0.3790, 0.3856, 0.3772, 0.3711, 0.3919, 0.3850, 0.3625])
assert np.abs(image_slice - expected_slice).max() < 3e-3
expected_slice = np.array([0.4011, 0.3992, 0.379, 0.3856, 0.3772, 0.3711, 0.3919, 0.385, 0.3625])
assert np.abs(image_slice - expected_slice).max() < 0.003

def test_amused_256_fp16(self):
pipe = AmusedPipeline.from_pretrained("amused/amused-256", variant="fp16", torch_dtype=torch.float16)
pipe.to(torch_device)

image = pipe("dog", generator=torch.Generator().manual_seed(0), num_inference_steps=2, output_type="np").images

image_slice = image[0, -3:, -3:, -1].flatten()

assert image.shape == (1, 256, 256, 3)
expected_slice = np.array([0.0554, 0.05129, 0.0344, 0.0452, 0.0476, 0.0271, 0.0495, 0.0527, 0.0158])
assert np.abs(image_slice - expected_slice).max() < 7e-3
assert np.abs(image_slice - expected_slice).max() < 0.007

def test_amused_512(self):
pipe = AmusedPipeline.from_pretrained("amused/amused-512")
pipe.to(torch_device)

image = pipe("dog", generator=torch.Generator().manual_seed(0), num_inference_steps=2, output_type="np").images

image_slice = image[0, -3:, -3:, -1].flatten()

assert image.shape == (1, 512, 512, 3)
expected_slice = np.array([0.9960, 0.9960, 0.9946, 0.9980, 0.9947, 0.9932, 0.9960, 0.9961, 0.9947])
assert np.abs(image_slice - expected_slice).max() < 3e-3
expected_slice = np.array([0.1199, 0.1171, 0.1229, 0.1188, 0.1210, 0.1147, 0.1260, 0.1346, 0.1152])
assert np.abs(image_slice - expected_slice).max() < 0.003
Comment on lines +159 to +160
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because of the runner change?


def test_amused_512_fp16(self):
pipe = AmusedPipeline.from_pretrained("amused/amused-512", variant="fp16", torch_dtype=torch.float16)
pipe.to(torch_device)

image = pipe("dog", generator=torch.Generator().manual_seed(0), num_inference_steps=2, output_type="np").images

image_slice = image[0, -3:, -3:, -1].flatten()

assert image.shape == (1, 512, 512, 3)
expected_slice = np.array([0.9983, 1.0, 1.0, 1.0, 1.0, 0.9989, 0.9994, 0.9976, 0.9977])
assert np.abs(image_slice - expected_slice).max() < 3e-3
expected_slice = np.array([0.1509, 0.1492, 0.1531, 0.1485, 0.1501, 0.1465, 0.1581, 0.1690, 0.1499])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same (runner change effects)?

assert np.abs(image_slice - expected_slice).max() < 0.003
Loading
Loading