Skip to content

Commit

Permalink
Add gated models to diffusers CI tests (#1690)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Socek <[email protected]>
  • Loading branch information
dsocek authored Jan 30, 2025
1 parent b579501 commit 9d23136
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/slow_tests_gaudi2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
--net=host \
--ipc=host \
vault.habana.ai/gaudi-docker/1.19.0/ubuntu22.04/habanalabs/pytorch-installer-2.5.1:latest \
/bin/bash tests/ci/slow_tests_diffusers.sh
/bin/bash tests/ci/slow_tests_diffusers.sh ${{ secrets.TEXT_GENERATION_CI_HUB_TOKEN }}
deepspeed:
name: Test DeepSpeed models
if: ${{ !cancelled() && (success() || failure()) }}
Expand Down
1 change: 1 addition & 0 deletions tests/ci/slow_tests_diffusers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

python -m pip install --upgrade pip
export RUN_SLOW=true
huggingface-cli login --token $1
make test_installs
CUSTOM_BF16_OPS=1 python -m pytest tests/test_diffusers.py -v -s -k "test_no_throughput_regression_autocast"
make slow_tests_diffusers
80 changes: 79 additions & 1 deletion tests/test_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import diffusers
import habana_frameworks.torch.hpu as hthpu
import numpy as np
import PIL
import pytest
import requests
import safetensors
Expand Down Expand Up @@ -69,7 +70,8 @@
require_torch,
)
from diffusers.utils.torch_utils import randn_tensor
from huggingface_hub import snapshot_download
from huggingface_hub import HfApi, hf_hub_download, snapshot_download
from huggingface_hub.utils import HfHubHTTPError
from parameterized import parameterized
from PIL import Image
from transformers import (
Expand Down Expand Up @@ -140,7 +142,9 @@
THROUGHPUT_UNCONDITIONAL_IMAGE_BASELINE_BF16 = 0.145
SDXL_THROUGHPUT = 0.301
SVD_THROUGHPUT = 0.012
SD3_THROUGHPUT = 0.006
FLUX_THROUGHPUT = 0.03
FLUX_DEV_I2I_THROUGHPUT = 0.12
else:
THROUGHPUT_BASELINE_BF16 = 0.275
THROUGHPUT_BASELINE_AUTOCAST = 0.114
Expand Down Expand Up @@ -171,6 +175,21 @@ def custom_bf16_ops(test_case):
return skipUnless(_run_custom_bf16_ops_test_, "test requires custom bf16 ops")(test_case)


def check_gated_model_access(model):
"""
Skip test for a gated model if access is not granted; this occurs when an account
with the required permissions is not logged into the HF Hub.
"""
try:
hf_hub_download(repo_id=model, filename=HfApi().model_info(model).siblings[0].rfilename)
gated = False

except HfHubHTTPError:
gated = True

return pytest.mark.skipif(gated, reason=f"{model} is gated, please log in with approved HF access token")


class GaudiPipelineUtilsTester(TestCase):
"""
Tests the features added on top of diffusers/pipeline_utils.py.
Expand Down Expand Up @@ -1515,6 +1534,32 @@ def test_fused_qkv_projections(self):
"Original outputs should match when fused QKV projections are disabled."
)

@slow
@check_gated_model_access("stabilityai/stable-diffusion-3-medium-diffusers")
@pytest.mark.skipif(not IS_GAUDI2, reason="does not fit into Gaudi1 memory")
def test_sd3_inference(self):
repo_id = "stabilityai/stable-diffusion-3-medium-diffusers"

pipe = self.pipeline_class.from_pretrained(
repo_id,
use_habana=True,
use_hpu_graphs=True,
gaudi_config="Habana/stable-diffusion",
torch_dtype=torch.bfloat16,
sdp_on_bf16=True,
)

outputs = pipe(
prompt="Sailing ship painting by Van Gogh",
num_inference_steps=28,
batch_size=1,
num_images_per_prompt=10,
output_type="np",
)

# Check expected performance of FLUX.1 dev img-to-img model
self.assertGreaterEqual(outputs.throughput, 0.95 * SD3_THROUGHPUT)


class GaudiStableDiffusionControlNetPipelineTester(TestCase):
"""
Expand Down Expand Up @@ -5947,3 +5992,36 @@ def test_flux_prompt_embeds(self):

max_diff = np.abs(output_with_prompt - output_with_embeds).max()
assert max_diff < 1e-4

@slow
@check_gated_model_access("black-forest-labs/FLUX.1-dev")
@pytest.mark.skipif(not IS_GAUDI2, reason="does not fit into Gaudi1 memory")
def test_flux_img2img_inference(self):
repo_id = "black-forest-labs/FLUX.1-dev"
image_path = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png"
image = PIL.Image.open(requests.get(image_path, stream=True).raw)
image = PIL.ImageOps.exif_transpose(image)
image = image.convert("RGB")

pipe = self.pipeline_class.from_pretrained(
repo_id,
torch_dtype=torch.bfloat16,
use_habana=True,
use_hpu_graphs=True,
gaudi_config="Habana/stable-diffusion",
sdp_on_bf16=True,
)

outputs = pipe(
image=image,
prompt="cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k",
num_inference_steps=30,
guidance_scale=3.5,
strength=0.9,
batch_size=1,
num_images_per_prompt=10,
output_type="np",
)

# Check expected performance of FLUX.1 dev img-to-img model
self.assertGreaterEqual(outputs.throughput, 0.95 * FLUX_DEV_I2I_THROUGHPUT)

0 comments on commit 9d23136

Please sign in to comment.