Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ def test_natten_processor_decodes(self):

# One shared instance swaps every attention module: the decoder's attention is homogeneous, with
# per-stage differences (the kernel size) living on the module rather than the processor.
model.set_attn_processor(LTX2VideoVaeNeighborhoodNattenProcessor())
try:
processor = LTX2VideoVaeNeighborhoodNattenProcessor()
except FileNotFoundError as e:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it FileNotFoundError? :o

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's what kernels raises from get_kernel when no build variant matches the environment.

pytest.skip(f"`shi-labs/natten` kernel unavailable in this environment: {e}")
model.set_attn_processor(processor)
processors = model.attn_processors
assert processors and all(
isinstance(processor, LTX2VideoVaeNeighborhoodNattenProcessor) for processor in processors.values()
Expand Down
22 changes: 22 additions & 0 deletions tests/models/testing_utils/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from diffusers.models.attention_dispatch import AttentionBackendName, _AttentionBackendRegistry, attention_backend
from diffusers.models.attention_processor import Attention, AttnProcessor
from diffusers.utils import is_kernels_available, is_torch_version
from diffusers.utils.constants import DIFFUSERS_TRUST_REMOTE_KERNELS

from ...testing_utils import assert_tensors_close, backend_empty_cache, is_attention, is_torch_compile, torch_device
from .utils import _maybe_cast_to_bf16
Expand All @@ -37,6 +38,7 @@
# ---------------------------------------------------------------------------

_CUDA_AVAILABLE = torch.cuda.is_available()
_IS_SM80_OR_NEWER = _CUDA_AVAILABLE and torch.cuda.get_device_capability() >= (8, 0)
# Every build variant of `kernels-community/sage-blackwell` declares `archs: ["12.0a"]`, so the
# kernel only loads on SM120 (consumer/workstation Blackwell). `a` targets are architecture
# specific, so neither SM100 nor SM121 is covered.
Expand All @@ -62,6 +64,9 @@
id="flash_hub",
marks=[
pytest.mark.skipif(not _CUDA_AVAILABLE, reason="CUDA is required for flash_hub backend."),
pytest.mark.skipif(
not _IS_SM80_OR_NEWER, reason="An SM80 or newer GPU is required for the flash_hub backend."
),
pytest.mark.skipif(
not is_kernels_available(),
reason="`kernels` package is required for flash_hub backend. Install with `pip install kernels`.",
Expand All @@ -74,6 +79,9 @@
id="flash_3_hub",
marks=[
pytest.mark.skipif(not _CUDA_AVAILABLE, reason="CUDA is required for _flash_3_hub backend."),
pytest.mark.skipif(
not _IS_SM80_OR_NEWER, reason="An SM80 or newer GPU is required for the _flash_3_hub backend."
),
pytest.mark.skipif(
not is_kernels_available(),
reason="`kernels` package is required for _flash_3_hub backend. Install with `pip install kernels`.",
Expand All @@ -86,6 +94,9 @@
id="flash_varlen_hub",
marks=[
pytest.mark.skipif(not _CUDA_AVAILABLE, reason="CUDA is required for flash_varlen_hub backend."),
pytest.mark.skipif(
not _IS_SM80_OR_NEWER, reason="An SM80 or newer GPU is required for the flash_varlen_hub backend."
),
pytest.mark.skipif(
not is_kernels_available(),
reason="`kernels` package is required for flash_varlen_hub backend. Install with `pip install kernels`.",
Expand All @@ -98,6 +109,9 @@
id="flash_3_varlen_hub",
marks=[
pytest.mark.skipif(not _CUDA_AVAILABLE, reason="CUDA is required for _flash_3_varlen_hub backend."),
pytest.mark.skipif(
not _IS_SM80_OR_NEWER, reason="An SM80 or newer GPU is required for the _flash_3_varlen_hub backend."
),
pytest.mark.skipif(
not is_kernels_available(),
reason="`kernels` package is required for _flash_3_varlen_hub backend. Install with `pip install kernels`.",
Expand All @@ -114,6 +128,10 @@
not is_kernels_available(),
reason="`kernels` package is required for sage_hub backend. Install with `pip install kernels`.",
),
pytest.mark.skipif(
not DIFFUSERS_TRUST_REMOTE_KERNELS,
reason="`DIFFUSERS_TRUST_REMOTE_KERNELS=true` is required for the sage_hub backend.",
),
],
)

Expand All @@ -128,6 +146,10 @@
not is_kernels_available(),
reason="`kernels` package is required for sage_blackwell_hub backend. Install with `pip install kernels`.",
),
pytest.mark.skipif(
not DIFFUSERS_TRUST_REMOTE_KERNELS,
reason="`DIFFUSERS_TRUST_REMOTE_KERNELS=true` is required for the sage_blackwell_hub backend.",
),
],
)

Expand Down
4 changes: 4 additions & 0 deletions tests/others/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def test_compile_arg(self):
@require_torch
# `--attention-backend` only exposes Hub-hosted kernels, all of which need `kernels>=0.12`.
@require_kernels_version_greater_or_equal("0.12")
@pytest.mark.skipif(
torch.cuda.is_available() and torch.cuda.get_device_capability() < (8, 0),
reason="An SM80 or newer GPU is required for the flash_hub backend.",
)
def test_attention_backend_arg(self):
from diffusers.models.attention_dispatch import AttentionBackendName

Expand Down