Update app.py
Browse files158 unmodified lines15916016116216316416516616716816917061 unmodified lines2322332342292302312352362372382392402 unmodified lines2432442452402412422462472482492502517 unmodified lines25926026125626226326426535 unmodified lines301302303298304305306307105 unmodified lines413414415410416417418419158 unmodified lines
MiniMaxH3ModularPipeline.min_duration = property(lambda self: float(seconds))
# `load_lora_adapter` requires every key (weights and `network_alphas` alike) to share a `prefix` whenever# `network_alphas` is passed — `prefix=None` with a non-empty `network_alphas` is a hard error. This string is# arbitrary (it's stripped off immediately, and the transformer itself has no `transformer.`-prefixed attribute)# but has to match InstantX's own convention since it's just a filtering key, not a real path.LORA_KEY_PREFIX = "transformer"
def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool) -> tuple[dict, dict]: """Rename a `diffusion_model.blocks.*` (original-checkpoint) LoRA state dict onto `MiniMaxH3Transformer3DModel`'s (`transformer_blocks.*`) naming, so `load_lora_adapter` can attach it.61 unmodified lines prefix = rename_base(raw_base[: -len("attn.qkv_proj")]) if ab == "lora_A": # Shared low-rank input side — identical for q, k, v. out[f"{prefix}attn.to_q.{ab}.weight"] = tensor out[f"{prefix}attn.to_k.{ab}.weight"] = tensor out[f"{prefix}attn.to_v.{ab}.weight"] = tensor out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_q.{ab}.weight"] = tensor out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_k.{ab}.weight"] = tensor out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_v.{ab}.weight"] = tensor else: q_out = base_shapes[f"{prefix}attn.to_q.weight"][0] k_out = base_shapes[f"{prefix}attn.to_k.weight"][0]2 unmodified lines f"{raw_base}.{ab}: expected {q_out + k_out + v_out} rows " f"(q{q_out}+k{k_out}+v{v_out}), got {tensor.shape[0]}" ) out[f"{prefix}attn.to_q.{ab}.weight"] = tensor[:q_out].clone() out[f"{prefix}attn.to_k.{ab}.weight"] = tensor[q_out:q_out + k_out].clone() out[f"{prefix}attn.to_v.{ab}.weight"] = tensor[q_out + k_out:].clone() out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_q.{ab}.weight"] = tensor[:q_out].clone() out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_k.{ab}.weight"] = tensor[q_out:q_out + k_out].clone() out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_v.{ab}.weight"] = tensor[q_out + k_out:].clone() return
if raw_base.endswith(".mlp.fc1") and ab == "lora_B" and swap_fc1:7 unmodified lines # checks against a fixed whitelist of known `kind`s the way the old anchored regex did. print(f"[lora-convert] '{raw_base}' renamed to '{key_base}', which isn't a real target — skipping", flush=True) return out[f"{key_base}.{ab}.weight"] = tensor out[f"{LORA_KEY_PREFIX}.{key_base}.{ab}.weight"] = tensor
for key, raw_tensor in raw.items(): # Some files (fp16-labeled ones especially) don't match the bf16 transformer's dtype; PEFT expects the35 unmodified lines network_alphas[f"{base}.alpha"] = float(out_tensor.shape[1]) for raw_base, alpha in raw_alphas.items(): for base in target_bases(raw_base): network_alphas[f"{base}.alpha"] = alpha network_alphas[f"{LORA_KEY_PREFIX}.{base}.alpha"] = alpha
return out, network_alphas
105 unmodified lines raw, base_shapes, swap_fc1=name in SWAP_FC1_NAMES ) pipe.transformer.load_lora_adapter( converted, adapter_name=name, prefix=None, network_alphas=network_alphas converted, adapter_name=name, prefix=LORA_KEY_PREFIX, network_alphas=network_alphas ) # `load_lora_adapter` warns-and-continues on a zero-key match instead of raising, so count # matched layers ourselves and fail loudly if a file attached nothing.app.py+15-9