Skip to content

Commit 591010b

Browse files
Support diffusers text attention flux loras.
1 parent 08f92d5 commit 591010b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

comfy/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
"""
2+
This file is part of ComfyUI.
3+
Copyright (C) 2024 Comfy
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
"""
18+
19+
120
import torch
221
import math
322
import struct
@@ -432,6 +451,12 @@ def flux_to_diffusers(mmdit_config, output_prefix=""):
432451
key_map["{}to_k.{}".format(k, end)] = (qkv, (0, hidden_size, hidden_size))
433452
key_map["{}to_v.{}".format(k, end)] = (qkv, (0, hidden_size * 2, hidden_size))
434453

454+
k = "{}.attn.".format(prefix_from)
455+
qkv = "{}.txt_attn.qkv.{}".format(prefix_to, end)
456+
key_map["{}add_q_proj.{}".format(k, end)] = (qkv, (0, 0, hidden_size))
457+
key_map["{}add_k_proj.{}".format(k, end)] = (qkv, (0, hidden_size, hidden_size))
458+
key_map["{}add_v_proj.{}".format(k, end)] = (qkv, (0, hidden_size * 2, hidden_size))
459+
435460
block_map = {"attn.to_out.0.weight": "img_attn.proj.weight",
436461
"attn.to_out.0.bias": "img_attn.proj.bias",
437462
}

0 commit comments

Comments
 (0)