huggingface / huggingface/diffusers

AttentionModuleMixin.set_attention_slice references two attributes that do not exist

Ouverte
#14,729 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug models needs-env-info
Langage dominant
Python
Étoiles
34.5k
Forks
7.3k
Merge moyen
3 j 3 h
PR mergées (30 j)
91

Description

### 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:

```python
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:

```python
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:

```python
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

```shell
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

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez dans src/diffusers/models/attention.py et reproduisez l’échec avec AnimaTextConditionerAttention en utilisant l’exemple de l’issue. Examinez _available_processors du mixin et les implémentations associées des processeurs d’attention, puis clarifiez avec les maintainers ce que devrait signifier un processeur sliced compatible. Le travail sera terminé lorsque slice_size=None et un appel avec slicing fonctionneront tous deux sans AttributeError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python, pytorch
Domaine
machine-learning
Type d'issue
Bug
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.