diff --git a/.github/workflows/nightly_tests.yml b/.github/workflows/nightly_tests.yml index c8fa3a7ad93a..d8ee87da04f1 100644 --- a/.github/workflows/nightly_tests.yml +++ b/.github/workflows/nightly_tests.yml @@ -198,7 +198,7 @@ jobs: HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }} RUN_COMPILE: yes run: | - pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -k "compile" --make-reports=tests_torch_compile_cuda tests/ + pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -m "is_torch_compile" --make-reports=tests_torch_compile_cuda tests/ - name: Failure short reports if: ${{ failure() }} run: cat reports/tests_torch_compile_cuda_failures_short.txt diff --git a/.github/workflows/push_tests.yml b/.github/workflows/push_tests.yml index a1f5e121537d..a3952c68ce09 100644 --- a/.github/workflows/push_tests.yml +++ b/.github/workflows/push_tests.yml @@ -156,48 +156,6 @@ jobs: name: torch_cuda_test_reports_${{ matrix.module }} path: reports - run_torch_compile_tests: - name: PyTorch Compile CUDA tests - - runs-on: - group: aws-g4dn-2xlarge - - container: - image: diffusers/diffusers-pytorch-cuda - options: --gpus all --shm-size "16gb" --ipc host - - steps: - - name: Checkout diffusers - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - - name: NVIDIA-SMI - run: | - nvidia-smi - - name: Install dependencies - run: | - uv pip install -e ".[quality,training]" - - name: Environment - run: | - python utils/print_env.py - - name: Run example tests on GPU - env: - HF_TOKEN: ${{ secrets.DIFFUSERS_HF_HUB_READ_TOKEN }} - RUN_COMPILE: yes - run: | - pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v -k "compile" --make-reports=tests_torch_compile_cuda tests/ - - name: Failure short reports - if: ${{ failure() }} - run: cat reports/tests_torch_compile_cuda_failures_short.txt - - - name: Test suite reports artifacts - if: ${{ always() }} - uses: actions/upload-artifact@v4 - with: - name: torch_compile_test_reports - path: reports - run_xformers_tests: name: PyTorch xformers CUDA tests diff --git a/.github/workflows/push_tests_fast.yml b/.github/workflows/push_tests_fast.yml deleted file mode 100644 index 6b1dd0b2d006..000000000000 --- a/.github/workflows/push_tests_fast.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Fast tests on main - -on: - push: - branches: - - main - paths: - - "src/diffusers/**.py" - - "examples/**.py" - - "tests/**.py" - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -env: - DIFFUSERS_IS_CI: yes - HF_HOME: /mnt/cache - OMP_NUM_THREADS: 8 - MKL_NUM_THREADS: 8 - HF_HUB_ENABLE_HF_TRANSFER: 1 - PYTEST_TIMEOUT: 600 - RUN_SLOW: no - -jobs: - run_fast_tests: - strategy: - fail-fast: false - matrix: - config: - - name: Fast PyTorch CPU tests on Ubuntu - framework: pytorch - runner: aws-general-8-plus - image: diffusers/diffusers-pytorch-cpu - report: torch_cpu - - name: PyTorch Example CPU tests on Ubuntu - framework: pytorch_examples - runner: aws-general-8-plus - image: diffusers/diffusers-pytorch-cpu - report: torch_example_cpu - - name: ${{ matrix.config.name }} - - runs-on: - group: ${{ matrix.config.runner }} - - container: - image: ${{ matrix.config.image }} - options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/ - - defaults: - run: - shell: bash - - steps: - - name: Checkout diffusers - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - - name: Install dependencies - run: | - uv pip install -e ".[quality]" - - - name: Environment - run: | - python utils/print_env.py - - - name: Run fast PyTorch CPU tests - if: ${{ matrix.config.framework == 'pytorch' }} - run: | - pytest -n 4 --max-worker-restart=0 --dist=loadfile \ - -s -v -k "not Flax and not Onnx" \ - --make-reports=tests_${{ matrix.config.report }} \ - tests/ - - - name: Run example PyTorch CPU tests - if: ${{ matrix.config.framework == 'pytorch_examples' }} - run: | - uv pip install ".[training]" - pytest -n 4 --max-worker-restart=0 --dist=loadfile \ - --make-reports=tests_${{ matrix.config.report }} \ - examples - - - name: Failure short reports - if: ${{ failure() }} - run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt - - - name: Test suite reports artifacts - if: ${{ always() }} - uses: actions/upload-artifact@v4 - with: - name: pr_${{ matrix.config.report }}_test_reports - path: reports diff --git a/tests/conftest.py b/tests/conftest.py index fd76d1c84ee7..9d384c281800 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -32,6 +32,7 @@ def pytest_configure(config): config.addinivalue_line("markers", "big_accelerator: marks tests as requiring big accelerator resources") + config.addinivalue_line("markers", "is_torch_compile: marks torch compilation tests") def pytest_addoption(parser): diff --git a/tests/models/test_modeling_common.py b/tests/models/test_modeling_common.py index 6f4c3d544b45..377133107bac 100644 --- a/tests/models/test_modeling_common.py +++ b/tests/models/test_modeling_common.py @@ -69,13 +69,12 @@ backend_synchronize, check_if_dicts_are_equal, get_python_version, - is_torch_compile, numpy_cosine_similarity_distance, require_peft_backend, - require_peft_version_greater, require_torch_2, require_torch_accelerator, require_torch_accelerator_with_training, + require_torch_compile, require_torch_multi_accelerator, require_torch_version_greater, run_test_in_subprocess, @@ -783,7 +782,7 @@ def test_from_save_pretrained_variant(self, expected_max_diff=5e-5): max_diff = (image - new_image).abs().max().item() self.assertLessEqual(max_diff, expected_max_diff, "Models give different forward passes") - @is_torch_compile + @require_torch_compile @require_torch_2 @unittest.skipIf( get_python_version == (3, 12), @@ -2038,7 +2037,7 @@ def test_push_to_hub_library_name(self): @require_torch_accelerator @require_torch_2 -@is_torch_compile +@require_torch_compile @slow @require_torch_version_greater("2.7.1") class TorchCompileTesterMixin: @@ -2160,9 +2159,8 @@ def test_compile_works_with_aot(self): @require_torch_2 @require_torch_accelerator @require_peft_backend -@require_peft_version_greater("0.14.0") @require_torch_version_greater("2.7.1") -@is_torch_compile +@require_torch_compile class LoraHotSwappingForModelTesterMixin: """Test that hotswapping does not result in recompilation on the model directly. diff --git a/tests/models/transformers/test_models_transformer_skyreels_v2.py b/tests/models/transformers/test_models_transformer_skyreels_v2.py index 8c36d8256ee9..75198d13cbb6 100644 --- a/tests/models/transformers/test_models_transformer_skyreels_v2.py +++ b/tests/models/transformers/test_models_transformer_skyreels_v2.py @@ -22,13 +22,13 @@ enable_full_determinism, torch_device, ) -from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin +from ..test_modeling_common import ModelTesterMixin enable_full_determinism() -class SkyReelsV2Transformer3DTests(ModelTesterMixin, TorchCompileTesterMixin, unittest.TestCase): +class SkyReelsV2Transformer3DTests(ModelTesterMixin, unittest.TestCase): model_class = SkyReelsV2Transformer3DModel main_input_name = "hidden_states" uses_custom_attn_processor = True diff --git a/tests/testing_utils.py b/tests/testing_utils.py index 7f849219c16f..c53ce0a0f079 100644 --- a/tests/testing_utils.py +++ b/tests/testing_utils.py @@ -447,6 +447,25 @@ def require_big_accelerator(test_case): )(test_case) +def require_torch_compile(test_case): + """ + Decorator marking compilation test. + """ + import pytest + + test_case = pytest.mark.is_torch_compile(test_case) + + if not is_torch_available(): + return unittest.skip("test requires PyTorch")(test_case) + + import torch + + if not (torch.cuda.is_available() or torch.xpu.is_available()): + return unittest.skip("test requires PyTorch CUDA")(test_case) + + return unittest.skipUnless(_run_compile_tests, "test is torch compile")(test_case) + + def require_torch_accelerator_with_training(test_case): """Decorator marking a test that requires an accelerator with support for training.""" return unittest.skipUnless(