Update app.py
Browse files158 unmodified lines15916016116216316461 unmodified lines2262272282292302312322332342 unmodified lines2372382392402412422432442457 unmodified lines25325425525625725825935 unmodified lines295296297298299300301105 unmodified lines407408409410411412413158 unmodified linesMiniMaxH3ModularPipeline.min_duration = property(lambda self: float(seconds))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 linesprefix = 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"] = tensorout[f"{prefix}attn.to_k.{ab}.weight"] = tensorout[f"{prefix}attn.to_v.{ab}.weight"] = tensorelse:q_out = base_shapes[f"{prefix}attn.to_q.weight"][0]k_out = base_shapes[f"{prefix}attn.to_k.weight"][0]2 unmodified linesf"{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()returnif 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)returnout[f"{key_base}.{ab}.weight"] = tensorfor key, raw_tensor in raw.items():# Some files (fp16-labeled ones especially) don't match the bf16 transformer's dtype; PEFT expects the35 unmodified linesnetwork_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"] = alphareturn out, network_alphas105 unmodified linesraw, base_shapes, swap_fc1=name in SWAP_FC1_NAMES)pipe.transformer.load_lora_adapter(converted, adapter_name=name, prefix=None, 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.158 unmodified lines15916016116216316416516616716816917061 unmodified lines2322332342352362372382392402 unmodified lines2432442452462472482492502517 unmodified lines25926026126226326426535 unmodified lines301302303304305306307105 unmodified lines413414415416417418419158 unmodified linesMiniMaxH3ModularPipeline.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 linesprefix = rename_base(raw_base[: -len("attn.qkv_proj")])if ab == "lora_A":# Shared low-rank input side — identical for q, k, v.out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_q.{ab}.weight"] = tensorout[f"{LORA_KEY_PREFIX}.{prefix}attn.to_k.{ab}.weight"] = tensorout[f"{LORA_KEY_PREFIX}.{prefix}attn.to_v.{ab}.weight"] = tensorelse:q_out = base_shapes[f"{prefix}attn.to_q.weight"][0]k_out = base_shapes[f"{prefix}attn.to_k.weight"][0]2 unmodified linesf"{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"{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()returnif 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)returnout[f"{LORA_KEY_PREFIX}.{key_base}.{ab}.weight"] = tensorfor key, raw_tensor in raw.items():# Some files (fp16-labeled ones especially) don't match the bf16 transformer's dtype; PEFT expects the35 unmodified linesnetwork_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"{LORA_KEY_PREFIX}.{base}.alpha"] = alphareturn out, network_alphas105 unmodified linesraw, base_shapes, swap_fc1=name in SWAP_FC1_NAMES)pipe.transformer.load_lora_adapter(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