Skip to content

UNet2DConditionModel : qk_norm setting in config.json is ignored #12050

@damian0815

Description

@damian0815

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 0c71189, macOS

Who can help?

@DN6 @yiyixuxu @sayakpaul

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions