Skip to content

Commit 4974b84

Browse files
authored
Update Cascade Tests (#7324)
* update * update * update
1 parent 83062fb commit 4974b84

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

tests/models/unets/test_models_unet_stable_cascade.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def test_stable_cascade_unet_prior_single_file_components(self):
5050
gc.collect()
5151
torch.cuda.empty_cache()
5252

53-
unet = StableCascadeUNet.from_pretrained(
54-
"stabilityai/stable-cascade-prior", subfolder="prior", revision="refs/pr/2", variant="bf16"
55-
)
53+
unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade-prior", subfolder="prior", variant="bf16")
5654
unet_config = unet.config
5755
del unet
5856
gc.collect()
@@ -74,9 +72,7 @@ def test_stable_cascade_unet_decoder_single_file_components(self):
7472
gc.collect()
7573
torch.cuda.empty_cache()
7674

77-
unet = StableCascadeUNet.from_pretrained(
78-
"stabilityai/stable-cascade", subfolder="decoder", revision="refs/pr/44", variant="bf16"
79-
)
75+
unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade", subfolder="decoder", variant="bf16")
8076
unet_config = unet.config
8177
del unet
8278
gc.collect()

tests/pipelines/stable_cascade/test_stable_cascade_decoder.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokenizer
2222

2323
from diffusers import DDPMWuerstchenScheduler, StableCascadeDecoderPipeline
24-
from diffusers.image_processor import VaeImageProcessor
2524
from diffusers.models import StableCascadeUNet
2625
from diffusers.pipelines.wuerstchen import PaellaVQModel
2726
from diffusers.utils.testing_utils import (
2827
enable_full_determinism,
29-
load_image,
28+
load_numpy,
3029
load_pt,
30+
numpy_cosine_similarity_distance,
3131
require_torch_gpu,
3232
skip_mps,
3333
slow,
@@ -258,7 +258,7 @@ def tearDown(self):
258258

259259
def test_stable_cascade_decoder(self):
260260
pipe = StableCascadeDecoderPipeline.from_pretrained(
261-
"diffusers/StableCascade-decoder", torch_dtype=torch.bfloat16
261+
"stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.bfloat16
262262
)
263263
pipe.enable_model_cpu_offload()
264264
pipe.set_progress_bar_config(disable=None)
@@ -271,18 +271,16 @@ def test_stable_cascade_decoder(self):
271271
)
272272

273273
image = pipe(
274-
prompt=prompt, image_embeddings=image_embedding, num_inference_steps=10, generator=generator
274+
prompt=prompt,
275+
image_embeddings=image_embedding,
276+
output_type="np",
277+
num_inference_steps=2,
278+
generator=generator,
275279
).images[0]
276280

277-
assert image.size == (1024, 1024)
278-
279-
expected_image = load_image(
280-
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/t2i.png"
281+
assert image.shape == (1024, 1024, 3)
282+
expected_image = load_numpy(
283+
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/stable_cascade_decoder_image.npy"
281284
)
282-
283-
image_processor = VaeImageProcessor()
284-
285-
image_np = image_processor.pil_to_numpy(image)
286-
expected_image_np = image_processor.pil_to_numpy(expected_image)
287-
288-
self.assertTrue(np.allclose(image_np, expected_image_np, atol=53e-2))
285+
max_diff = numpy_cosine_similarity_distance(image.flatten(), expected_image.flatten())
286+
assert max_diff < 1e-4

tests/pipelines/stable_cascade/test_stable_cascade_prior.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from diffusers.utils.import_utils import is_peft_available
3030
from diffusers.utils.testing_utils import (
3131
enable_full_determinism,
32-
load_pt,
32+
load_numpy,
33+
numpy_cosine_similarity_distance,
3334
require_peft_backend,
3435
require_torch_gpu,
3536
skip_mps,
@@ -319,25 +320,22 @@ def tearDown(self):
319320
torch.cuda.empty_cache()
320321

321322
def test_stable_cascade_prior(self):
322-
pipe = StableCascadePriorPipeline.from_pretrained("diffusers/StableCascade-prior", torch_dtype=torch.bfloat16)
323+
pipe = StableCascadePriorPipeline.from_pretrained(
324+
"stabilityai/stable-cascade-prior", variant="bf16", torch_dtype=torch.bfloat16
325+
)
323326
pipe.enable_model_cpu_offload()
324327
pipe.set_progress_bar_config(disable=None)
325328

326329
prompt = "A photograph of the inside of a subway train. There are raccoons sitting on the seats. One of them is reading a newspaper. The window shows the city in the background."
327330

328331
generator = torch.Generator(device="cpu").manual_seed(0)
329332

330-
output = pipe(prompt, num_inference_steps=10, generator=generator)
333+
output = pipe(prompt, num_inference_steps=2, output_type="np", generator=generator)
331334
image_embedding = output.image_embeddings
332-
333-
expected_image_embedding = load_pt(
334-
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/image_embedding.pt"
335+
expected_image_embedding = load_numpy(
336+
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/stable_cascade_prior_image_embeddings.npy"
335337
)
336-
337338
assert image_embedding.shape == (1, 16, 24, 24)
338339

339-
self.assertTrue(
340-
np.allclose(
341-
image_embedding.cpu().float().numpy(), expected_image_embedding.cpu().float().numpy(), atol=5e-2
342-
)
343-
)
340+
max_diff = numpy_cosine_similarity_distance(image_embedding.flatten(), expected_image_embedding.flatten())
341+
assert max_diff < 1e-4

0 commit comments

Comments
 (0)