Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Apply single-head LoRAs to MiniMax-H3 PDD head banks (#17239)

Jukka Seppänen1045d48eb4cc
diff --git a/comfy/lora.py b/comfy/lora.py
index a7224ce90..384ca91b6 100644
--- a/comfy/lora.py
+++ b/comfy/lora.py
@@ -34,6 +34,10 @@ LORA_CLIP_MAP = {
}
+def bias_key(to): # a weight sliced along dim 0 slices its bias the same way
+ return (bias_key(to[0]), to[1]) if isinstance(to, tuple) else to[:-len(".weight")] + ".bias"
+
+
def load_lora(lora, to_load, log_missing=True):
patch_dict = {}
loaded_keys = set()
@@ -67,7 +71,7 @@ def load_lora(lora, to_load, log_missing=True):
patch_dict[to_load[x]] = ("diff", (w_norm,))
if b_norm is not None:
loaded_keys.add(b_norm_name)
- patch_dict["{}.bias".format(to_load[x][:-len(".weight")])] = ("diff", (b_norm,))
+ patch_dict[bias_key(to_load[x])] = ("diff", (b_norm,))
diff_name = "{}.diff".format(x)
diff_weight = lora.get(diff_name, None)
@@ -78,7 +82,7 @@ def load_lora(lora, to_load, log_missing=True):
diff_bias_name = "{}.diff_b".format(x)
diff_bias = lora.get(diff_bias_name, None)
if diff_bias is not None:
- patch_dict["{}.bias".format(to_load[x][:-len(".weight")])] = ("diff", (diff_bias,))
+ patch_dict[bias_key(to_load[x])] = ("diff", (diff_bias,))
loaded_keys.add(diff_bias_name)
set_weight_name = "{}.set_weight".format(x)
@@ -414,6 +418,10 @@ def model_lora_keys_unet(model, key_map={}):
if k.startswith("diffusion_model.") and k.endswith(".weight"):
key_lora = k[len("diffusion_model."):-len(".weight")]
key_map[key_lora] = k
+ pdd_steps = model.model_config.unet_config.get("pdd_steps", 1)
+ if pdd_steps > 1: # baked PDD bank: single-head LoRAs patch head 0, the base of every interval head
+ heads = {k: (k, (0, 0, sd[k].shape[0] // pdd_steps)) for k in ("diffusion_model.final_layer.video_out.weight", "diffusion_model.final_layer.audio_out.weight")}
+ key_map.update({key_lora: heads[k] for key_lora, k in key_map.items() if k in heads})
return key_map