huggingface / huggingface/diffusers

`UNet2DConditionModel` : `qk_norm` setting in `config.json` is ignored

Open
#12,050 5 comments 0 reactions 0 assignees View on GitHub
bug stale
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

### Describe the bug

Adding eg `"qk_norm": "rms_norm"` to config.json for a `UNet2DConditionModel` has no effect.

This is because the value is not propagated by the `UNet2DContionalModel` initialization logic through to `Attention.__init__` in `src/diffusers/models/attention_processor.py`.

### Reproduction

Default behaviour with empty config dict:
```
from diffusers import UNet2DConditionModel
config_minimal = {}
model = UNet2DConditionModel.from_config(config_minimal)
print([n for n, _ in model.named_modules()
if 'attn1.norm_' in n])
# output: []
```

For supported models, QK norm modules show up as eg `... .attn1.norm_q` and `... .attn1.norm_k`. If we add `"qk_norm" : "rms_norm"` to the config then we should expect modules with these names to appear, but they don't:

```
config_minimal['qk_norm'] = 'rms_norm'
model = UNet2DConditionModel.from_config(config_minimal)
print([n for n, _ in model.named_modules()
if 'attn1.norm_' in n])
# expected output: ['down_blocks.0.attentions.0.transformer_blocks.0.attn1.norm_q', 'down_blocks.0.attentions.0.transformer_blocks.0.attn1.norm_k', ...]
# actual output: []
```

### System Info

diffusers main branch commit 0c71189abeaa8ab4b28dd7e5a309ac75c64968a2, macOS

### Who can help?

@DN6 @yiyixuxu @sayakpaul

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.