Skip to content

AttentionModuleMixin.set_attention_slice references two attributes that do not exist #14729

Description

@yupengtang

Describe the bug

AttentionModuleMixin.set_attention_slice in src/diffusers/models/attention.py refers to two attributes that do not exist anywhere in the codebase, so it raises AttributeError for every argument:

if slice_size is not None:
    processor = self._get_compatible_processor("sliced")   # no such method anywhere in src/

if processor is None:
    processor = self.default_processor_cls()               # the attribute is `_default_processor_cls`

grep -rn "_get_compatible_processor" src/ returns only that one call site, and default_processor_cls (without the underscore) is likewise only that one use. The class attribute defined on the mixin at line 122 is _default_processor_cls. Thirty-six files under models/transformers, models/autoencoders and models/condition_embedders define AttentionModuleMixin subclasses, so they all inherit this method.

I could not find a public entry point that routes into this method today. The models that recurse into submodule set_attention_slice (unet_2d_condition, unet_3d_condition, the three controlnets, audioldm2, versatile_diffusion) all hold attention_processor.Attention modules, which have their own working set_attention_slice. So this looks latent rather than something users are hitting. It stops being latent as soon as a model built on AttentionModuleMixin gets wired into that recursion, which the # TODO: the following will not be required when everything is refactored to AttentionModuleMixin comment in modeling_utils.py suggests is the direction.

I am reporting rather than sending a patch because only half of it is a typo. Renaming default_processor_cls to _default_processor_cls fixes the slice_size=None path, but the other branch needs _get_compatible_processor to exist, and what "a compatible sliced processor" should mean under the new mixin is a design call. None of the _available_processors lists in the tree contain a sliced processor, so there is nothing for it to return yet. Happy to send a PR for whichever shape you want.

Reproduction

Since nothing routes into the method, the smallest failing thing is the method itself on a real attention module. AnimaTextConditionerAttention is one of the AttentionModuleMixin subclasses and is cheap to build:

from diffusers.models.condition_embedders.condition_embedder_anima import AnimaTextConditionerAttention

attn = AnimaTextConditionerAttention(
    query_dim=64, context_dim=64, num_attention_heads=4, attention_head_dim=16
)
print(attn._default_processor_cls.__name__)   # AnimaTextConditionerAttnProcessor

for slice_size in (None, 1):
    try:
        attn.set_attention_slice(slice_size)
        print(slice_size, "->", type(attn.processor).__name__)
    except AttributeError as e:
        print(slice_size, "->", e)

Any of the other subclasses behaves the same way, since both names are missing from the mixin itself:

from diffusers.models.attention import AttentionModuleMixin

hasattr(AttentionModuleMixin, "_default_processor_cls")   # True
hasattr(AttentionModuleMixin, "default_processor_cls")    # False
hasattr(AttentionModuleMixin, "_get_compatible_processor")  # False

Logs

AnimaTextConditionerAttnProcessor
None -> 'AnimaTextConditionerAttention' object has no attribute 'default_processor_cls'
1 -> 'AnimaTextConditionerAttention' object has no attribute '_get_compatible_processor'

System Info

  • diffusers: 0.41.0.dev0, main at c5469b7
  • PyTorch: 2.11.0+cu130
  • Python: 3.13.15
  • Platform: Linux, CPU

The reproduction constructs a module directly and downloads nothing.

Who can help?

@DN6 @yiyixuxu

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions