Skip to content
Open
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
30 changes: 19 additions & 11 deletions .github/workflows/pr_tests_gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ on:
pull_request:
branches: main
paths:
- ".github/workflows/pr_tests_gpu.yml"
- "src/diffusers/models/modeling_utils.py"
- "src/diffusers/models/model_loading_utils.py"
- "src/diffusers/pipelines/pipeline_utils.py"
- "src/diffusers/pipeline_loading_utils.py"
- "src/diffusers/loaders/lora_base.py"
- "src/diffusers/loaders/lora_pipeline.py"
- "src/diffusers/loaders/peft.py"
- "src/diffusers/pipelines/pipeline_loading_utils.py"
- "src/diffusers/modular_pipelines/modular_pipeline.py"
- "src/diffusers/modular_pipelines/modular_pipeline_utils.py"
- "src/diffusers/**/*lora*.py"
- "src/diffusers/**/*peft*.py"
- "tests/lora/**"
- "tests/**/*lora*.py"
- "tests/**/*peft*.py"
- "tests/pipelines/testing_utils/**.py"
- "tests/modular_pipelines/testing_utils/**.py"
- "tests/models/test_modeling_common.py"
- "tests/models/testing_utils/**.py"
- "examples/**/*.py"
Expand Down Expand Up @@ -152,6 +158,7 @@ jobs:
run: |
printf 'torch==2.10.0\ntorchvision==0.25.0\ntorchaudio==2.10.0\n' > "$UV_OVERRIDE"
uv pip install -e ".[quality]"
uv pip install peft@git+https://github.com/huggingface/peft.git
uv pip uninstall accelerate && uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git
uv pip uninstall transformers huggingface_hub && UV_PRERELEASE=allow uv pip install -U transformers@git+https://github.com/huggingface/transformers.git

Expand Down Expand Up @@ -213,7 +220,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
module: [models, schedulers, lora, others]
module: [models, modular_pipelines, schedulers, hooks, lora, others]
steps:
- name: Checkout diffusers
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -234,6 +241,7 @@ jobs:

- name: Extract tests
id: extract_tests
if: matrix.module != 'lora'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So that it skips test-pattern extraction for the lora matrix entry because the next step selects those tests with pytest -m lora tests/. Simplifies things a bit.

run: |
pattern=$(python utils/extract_tests_from_mixin.py --type ${{ matrix.module }})
echo "$pattern" > /tmp/test_pattern.txt
Expand All @@ -245,13 +253,13 @@ jobs:
# https://pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms
CUBLAS_WORKSPACE_CONFIG: :16:8
run: |
pattern=$(cat ${{ steps.extract_tests.outputs.pattern_file }})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

schedulers and others can yield empty patterns. So, their -k "$pattern" will be nullified by pytest.

if [ -z "$pattern" ]; then
pytest -n 1 --max-worker-restart=0 --dist=loadfile tests/${{ matrix.module }} \
--make-reports=tests_torch_cuda_${{ matrix.module }}
if [ "${{ matrix.module }}" = "lora" ]; then
pytest -n 1 --max-worker-restart=0 --dist=loadfile -m lora tests/ \
--make-reports=tests_torch_cuda_lora
else
pytest -n 1 --max-worker-restart=0 --dist=loadfile -k "$pattern" tests/${{ matrix.module }} \
--make-reports=tests_torch_cuda_${{ matrix.module }}
pattern=$(cat "${{ steps.extract_tests.outputs.pattern_file }}")
pytest -n 1 --max-worker-restart=0 --dist=loadfile -k "$pattern" tests/${{ matrix.module }} \
--make-reports=tests_torch_cuda_${{ matrix.module }}
fi

- name: Failure short reports
Expand Down
1 change: 1 addition & 0 deletions tests/lora/test_lora_loader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from peft.tuners.tuners_utils import BaseTunerLayer


pytestmark = pytest.mark.lora
LORA_KEY = "unet.test.lora_A.weight"


Expand Down
5 changes: 5 additions & 0 deletions tests/lora/test_peft_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from diffusers.utils.peft_utils import get_peft_kwargs


pytestmark = pytest.mark.lora


def _rank_dict(module_ranks):
return {f"{module}.lora_B.weight": rank for module, rank in module_ranks.items()}

Expand Down
6 changes: 6 additions & 0 deletions tests/models/testing_utils/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
is_bfl,
is_bitsandbytes,
is_gguf,
is_lora,
is_modelopt,
is_quantization,
is_sdnq,
Expand Down Expand Up @@ -684,6 +685,7 @@ def test_bnb_device_assignment(self):
assert model.device.type == torch.device(torch_device).type
assert model.get_memory_footprint() == pytest.approx(mem_before)

@is_lora
@pytest.mark.parametrize("config_name", ["4bit_nf4"], ids=["4bit_nf4"])
def test_bnb_quantization_lora_inference(self, config_name):
self._test_quantization_lora_inference(BitsAndBytesConfigMixin.BNB_CONFIGS[config_name])
Expand Down Expand Up @@ -914,6 +916,7 @@ def test_torchao_quantization_inference(self, quant_type):
def test_torchao_quantized_layers(self, quant_type):
self._test_quantized_layers(TorchAoConfigMixin.TORCHAO_QUANT_TYPES[quant_type])

@is_lora
@pytest.mark.parametrize("quant_type", ["int8wo"], ids=["int8wo"])
def test_torchao_quantization_lora_inference(self, quant_type):
self._test_quantization_lora_inference(TorchAoConfigMixin.TORCHAO_QUANT_TYPES[quant_type])
Expand Down Expand Up @@ -1157,6 +1160,7 @@ def test_gguf_keep_modules_in_fp32(self):
def test_gguf_quantization_dtype_assignment(self):
self._test_quantization_dtype_assignment({"compute_dtype": torch.bfloat16})

@is_lora
def test_gguf_quantization_lora_inference(self):
self._test_quantization_lora_inference({"compute_dtype": torch.bfloat16})

Expand Down Expand Up @@ -1254,6 +1258,7 @@ def test_modelopt_quantization_inference(self, config_name):
def test_modelopt_quantization_dtype_assignment(self, config_name):
self._test_quantization_dtype_assignment(ModelOptConfigMixin.MODELOPT_CONFIGS[config_name])

@is_lora
@pytest.mark.parametrize("config_name", ["fp8"], ids=["fp8"])
def test_modelopt_quantization_lora_inference(self, config_name):
self._test_quantization_lora_inference(ModelOptConfigMixin.MODELOPT_CONFIGS[config_name])
Expand Down Expand Up @@ -2040,6 +2045,7 @@ def test_bfl_quantization_matches_unquantized(self, config_name):
def test_bfl_quantization_dtype_assignment(self, config_name):
self._test_quantization_dtype_assignment(BFLConfigMixin.BFL_CONFIGS[config_name])

@is_lora
@pytest.mark.parametrize("config_name", ["fp8r"], ids=["fp8r"])
def test_bfl_quantization_lora_inference(self, config_name):
self._test_quantization_lora_inference(BFLConfigMixin.BFL_CONFIGS[config_name])
Expand Down
1 change: 1 addition & 0 deletions tests/others/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def test_save_output_video_saves_mp4_and_frames(self, tmp_path, monkeypatch):
assert frame_rel == sorted(f"{v:04d}-frames/{i:04d}.png" for v in range(2) for i in range(4))
assert all((tmp_path / rel).exists() for rel in frame_rel)

@pytest.mark.lora
def test_lora_spec_passes_weight_name(self):
# A LoRA repo can ship several weight files (e.g. a ComfyUI variant next to the diffusers
# one), so `weight_name` has to reach `load_lora_weights` to disambiguate.
Expand Down
2 changes: 2 additions & 0 deletions tests/pipelines/flux/test_pipeline_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Expectations,
assert_tensors_close,
backend_empty_cache,
is_lora,
nightly,
numpy_cosine_similarity_distance,
require_big_accelerator,
Expand Down Expand Up @@ -492,6 +493,7 @@ def test_flux_ip_adapter_inference(self):
assert max_diff < 1e-4, f"Image slice is different from expected slice: {image_slice} != {expected_slice}"


@is_lora
@nightly
@require_big_accelerator
@require_peft_backend
Expand Down
2 changes: 2 additions & 0 deletions tests/pipelines/flux/test_pipeline_flux_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CaptureLogger,
assert_tensors_close,
backend_empty_cache,
is_lora,
nightly,
numpy_cosine_similarity_distance,
require_big_accelerator,
Expand Down Expand Up @@ -592,6 +593,7 @@ class TestFluxControlPipelineLoRAMemory(FluxControlPipelineTesterConfig, LoraMem
"""LoRA x memory-optimization tests (group offload, CPU offload) for the Flux Control pipeline."""


@is_lora
@nightly
@require_torch_accelerator
@require_peft_backend
Expand Down
2 changes: 2 additions & 0 deletions tests/pipelines/hunyuan_video/test_hunyuan_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
assert_tensors_close,
backend_empty_cache,
enable_full_determinism,
is_lora,
nightly,
numpy_cosine_similarity_distance,
require_big_accelerator,
Expand Down Expand Up @@ -276,6 +277,7 @@ class TestHunyuanVideoPipelineLoRAMemory(HunyuanVideoPipelineTesterConfig, LoraM
"""LoRA x memory-optimization tests (group offload, CPU offload) for the HunyuanVideo pipeline."""


@is_lora
@nightly
@require_torch_accelerator
@require_peft_backend
Expand Down
3 changes: 3 additions & 0 deletions tests/pipelines/stable_diffusion/test_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
backend_max_memory_allocated,
backend_reset_max_memory_allocated,
backend_reset_peak_memory_stats,
is_lora,
load_image,
load_numpy,
nightly,
Expand Down Expand Up @@ -1306,6 +1307,7 @@ def test_reset_device_map_enable_sequential_cpu_offload(self):
_ = sd_pipe_with_device_map("hello", num_inference_steps=2)


@is_lora
@slow
@require_torch_accelerator
@require_peft_backend
Expand Down Expand Up @@ -1453,6 +1455,7 @@ def test_integration_set_lora_device_different_target_layers(self):
assert module.weight.device != torch.device("cpu")


@is_lora
@slow
@nightly
@require_torch_accelerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
assert_tensors_close,
backend_empty_cache,
backend_synchronize,
is_lora,
load_image,
nightly,
numpy_cosine_similarity_distance,
Expand Down Expand Up @@ -1008,6 +1009,7 @@ def test_stable_diffusion_lcm(self):
assert max_diff < 1e-2


@is_lora
@slow
@nightly
@require_torch_accelerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
assert_tensors_close,
backend_empty_cache,
floats_tensor,
is_lora,
load_image,
nightly,
numpy_cosine_similarity_distance,
Expand Down Expand Up @@ -552,6 +553,7 @@ class TestStableDiffusionXLMultiAdapterPipelineIPAdapter(
"""IP-Adapter tests for the SDXL pipeline driven by a `MultiAdapter`."""


@is_lora
@slow
@nightly
@require_torch_accelerator
Expand Down
2 changes: 2 additions & 0 deletions tests/pipelines/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
floats_tensor,
get_python_version,
get_tests_dir,
is_lora,
is_torch_compile,
load_numpy,
nightly,
Expand Down Expand Up @@ -2281,6 +2282,7 @@ def test_ddpm_ddim_equality_batched(self):
assert np.abs(ddpm_images - ddim_images).max() < 1e-1


@is_lora
@slow
@require_torch_2
@require_torch_accelerator
Expand Down
42 changes: 35 additions & 7 deletions utils/extract_tests_from_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ def generate_pattern_for_mixins(mixin_classes: List[Type]) -> str:
with redirect_stdout(sys.stderr):
mixin_classes = []
if args.type == "pipeline":
# Preserve the old PipelineTesterMixin's scope: general pipeline and memory tests.
# Other feature mixins were not selected by the old script either.
from tests.pipelines.testing_utils import MemoryTesterMixin, PipelineTesterMixin
from tests.pipelines.testing_utils import (
LoraMemoryTesterMixin,
LoraTesterMixin,
MemoryTesterMixin,
PipelineTesterMixin,
UNetLoraTesterMixin,
)

mixin_classes = [PipelineTesterMixin, MemoryTesterMixin]
mixin_classes = [
PipelineTesterMixin,
MemoryTesterMixin,
LoraTesterMixin,
LoraMemoryTesterMixin,
UNetLoraTesterMixin,
]

elif args.type == "models":
# The model tester suite is split across several mixins under `tests/models/testing_utils`,
Expand All @@ -70,10 +80,28 @@ def generate_pattern_for_mixins(mixin_classes: List[Type]) -> str:
LoraTesterMixin,
]

elif args.type == "lora":
from tests.pipelines.testing_utils import LoraMemoryTesterMixin, LoraTesterMixin, UNetLoraTesterMixin
elif args.type == "modular_pipelines":
from tests.modular_pipelines.testing_utils import (
ModularAutoOffloadTesterMixin,
ModularGuiderTesterMixin,
ModularLoadingTesterMixin,
ModularLoraMemoryTesterMixin,
ModularLoraTesterMixin,
ModularMemoryTesterMixin,
ModularPipelineTesterMixin,
ModularWorkflowTesterMixin,
)

mixin_classes = [LoraTesterMixin, LoraMemoryTesterMixin, UNetLoraTesterMixin]
mixin_classes = [
ModularPipelineTesterMixin,
ModularWorkflowTesterMixin,
ModularLoadingTesterMixin,
ModularGuiderTesterMixin,
ModularMemoryTesterMixin,
ModularAutoOffloadTesterMixin,
ModularLoraTesterMixin,
ModularLoraMemoryTesterMixin,
]

pattern = generate_pattern_for_mixins(mixin_classes)
print(pattern)