diff --git a/.github/workflows/pr_tests_gpu.yml b/.github/workflows/pr_tests_gpu.yml index 575eeb597c8e..4337c2800a6d 100644 --- a/.github/workflows/pr_tests_gpu.yml +++ b/.github/workflows/pr_tests_gpu.yml @@ -5,13 +5,16 @@ 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/**/*lora*.py" + - "src/diffusers/**/*peft*.py" + - "tests/lora/**" + - "tests/**/*lora*.py" + - "tests/**/*peft*.py" - "tests/pipelines/testing_utils/**.py" - "tests/models/test_modeling_common.py" - "tests/models/testing_utils/**.py" @@ -234,6 +237,7 @@ jobs: - name: Extract tests id: extract_tests + if: matrix.module != 'lora' run: | pattern=$(python utils/extract_tests_from_mixin.py --type ${{ matrix.module }}) echo "$pattern" > /tmp/test_pattern.txt @@ -245,13 +249,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 }}) - 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 diff --git a/tests/lora/test_lora_loader_utils.py b/tests/lora/test_lora_loader_utils.py index 8c3d3037e897..f3037548643f 100644 --- a/tests/lora/test_lora_loader_utils.py +++ b/tests/lora/test_lora_loader_utils.py @@ -37,6 +37,7 @@ from peft.tuners.tuners_utils import BaseTunerLayer +pytestmark = pytest.mark.lora LORA_KEY = "unet.test.lora_A.weight" diff --git a/tests/lora/test_peft_utils.py b/tests/lora/test_peft_utils.py index 262c4fa41f93..707b3c050952 100644 --- a/tests/lora/test_peft_utils.py +++ b/tests/lora/test_peft_utils.py @@ -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()} diff --git a/tests/models/testing_utils/quantization.py b/tests/models/testing_utils/quantization.py index dc4681f23ecc..f2f4d92fd913 100644 --- a/tests/models/testing_utils/quantization.py +++ b/tests/models/testing_utils/quantization.py @@ -49,6 +49,7 @@ is_bfl, is_bitsandbytes, is_gguf, + is_lora, is_modelopt, is_quantization, is_sdnq, @@ -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]) @@ -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]) @@ -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}) @@ -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]) @@ -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]) diff --git a/tests/others/test_cli_commands.py b/tests/others/test_cli_commands.py index d05d2ff97f2e..e6eac0b67982 100644 --- a/tests/others/test_cli_commands.py +++ b/tests/others/test_cli_commands.py @@ -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. diff --git a/tests/pipelines/flux/test_pipeline_flux.py b/tests/pipelines/flux/test_pipeline_flux.py index 70cd88a48c9b..86212df97286 100644 --- a/tests/pipelines/flux/test_pipeline_flux.py +++ b/tests/pipelines/flux/test_pipeline_flux.py @@ -21,6 +21,7 @@ Expectations, assert_tensors_close, backend_empty_cache, + is_lora, nightly, numpy_cosine_similarity_distance, require_big_accelerator, @@ -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 diff --git a/tests/pipelines/flux/test_pipeline_flux_control.py b/tests/pipelines/flux/test_pipeline_flux_control.py index 1925628c6764..6d7f2eccf5dd 100644 --- a/tests/pipelines/flux/test_pipeline_flux_control.py +++ b/tests/pipelines/flux/test_pipeline_flux_control.py @@ -20,6 +20,7 @@ CaptureLogger, assert_tensors_close, backend_empty_cache, + is_lora, nightly, numpy_cosine_similarity_distance, require_big_accelerator, @@ -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 diff --git a/tests/pipelines/hunyuan_video/test_hunyuan_video.py b/tests/pipelines/hunyuan_video/test_hunyuan_video.py index 6b857eecea3b..92bd0bae8cfb 100644 --- a/tests/pipelines/hunyuan_video/test_hunyuan_video.py +++ b/tests/pipelines/hunyuan_video/test_hunyuan_video.py @@ -31,6 +31,7 @@ assert_tensors_close, backend_empty_cache, enable_full_determinism, + is_lora, nightly, numpy_cosine_similarity_distance, require_big_accelerator, @@ -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 diff --git a/tests/pipelines/stable_diffusion/test_stable_diffusion.py b/tests/pipelines/stable_diffusion/test_stable_diffusion.py index 1fa17d53ef0b..31b747d615c8 100644 --- a/tests/pipelines/stable_diffusion/test_stable_diffusion.py +++ b/tests/pipelines/stable_diffusion/test_stable_diffusion.py @@ -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, @@ -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 @@ -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 diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py index 334a6874786f..cd94d59a43df 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl.py @@ -47,6 +47,7 @@ assert_tensors_close, backend_empty_cache, backend_synchronize, + is_lora, load_image, nightly, numpy_cosine_similarity_distance, @@ -1008,6 +1009,7 @@ def test_stable_diffusion_lcm(self): assert max_diff < 1e-2 +@is_lora @slow @nightly @require_torch_accelerator diff --git a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py index 94d6937d3d8a..7345cbabe5d7 100644 --- a/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py +++ b/tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py @@ -35,6 +35,7 @@ assert_tensors_close, backend_empty_cache, floats_tensor, + is_lora, load_image, nightly, numpy_cosine_similarity_distance, @@ -552,6 +553,7 @@ class TestStableDiffusionXLMultiAdapterPipelineIPAdapter( """IP-Adapter tests for the SDXL pipeline driven by a `MultiAdapter`.""" +@is_lora @slow @nightly @require_torch_accelerator diff --git a/tests/pipelines/test_pipelines.py b/tests/pipelines/test_pipelines.py index 70c06428da31..5bbd95b16bb1 100644 --- a/tests/pipelines/test_pipelines.py +++ b/tests/pipelines/test_pipelines.py @@ -72,6 +72,7 @@ floats_tensor, get_python_version, get_tests_dir, + is_lora, is_torch_compile, load_numpy, nightly, @@ -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