Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -159,6 +159,12 @@ def lower_duration_floor(seconds: float = MIN_UI_DURATION) -> None:
|
|
| 159 |
|
| 160 |
MiniMaxH3ModularPipeline.min_duration = property(lambda self: float(seconds))
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool) -> tuple[dict, dict]:
|
| 163 |
"""Rename a `diffusion_model.blocks.*` (original-checkpoint) LoRA state dict onto
|
| 164 |
`MiniMaxH3Transformer3DModel`'s (`transformer_blocks.*`) naming, so `load_lora_adapter` can attach it.
|
|
@@ -226,9 +232,9 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 226 |
prefix = rename_base(raw_base[: -len("attn.qkv_proj")])
|
| 227 |
if ab == "lora_A":
|
| 228 |
# Shared low-rank input side — identical for q, k, v.
|
| 229 |
-
out[f"{prefix}attn.to_q.{ab}.weight"] = tensor
|
| 230 |
-
out[f"{prefix}attn.to_k.{ab}.weight"] = tensor
|
| 231 |
-
out[f"{prefix}attn.to_v.{ab}.weight"] = tensor
|
| 232 |
else:
|
| 233 |
q_out = base_shapes[f"{prefix}attn.to_q.weight"][0]
|
| 234 |
k_out = base_shapes[f"{prefix}attn.to_k.weight"][0]
|
|
@@ -237,9 +243,9 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 237 |
f"{raw_base}.{ab}: expected {q_out + k_out + v_out} rows "
|
| 238 |
f"(q{q_out}+k{k_out}+v{v_out}), got {tensor.shape[0]}"
|
| 239 |
)
|
| 240 |
-
out[f"{prefix}attn.to_q.{ab}.weight"] = tensor[:q_out].clone()
|
| 241 |
-
out[f"{prefix}attn.to_k.{ab}.weight"] = tensor[q_out:q_out + k_out].clone()
|
| 242 |
-
out[f"{prefix}attn.to_v.{ab}.weight"] = tensor[q_out + k_out:].clone()
|
| 243 |
return
|
| 244 |
|
| 245 |
if raw_base.endswith(".mlp.fc1") and ab == "lora_B" and swap_fc1:
|
|
@@ -253,7 +259,7 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 253 |
# checks against a fixed whitelist of known `kind`s the way the old anchored regex did.
|
| 254 |
print(f"[lora-convert] '{raw_base}' renamed to '{key_base}', which isn't a real target — skipping", flush=True)
|
| 255 |
return
|
| 256 |
-
out[f"{key_base}.{ab}.weight"] = tensor
|
| 257 |
|
| 258 |
for key, raw_tensor in raw.items():
|
| 259 |
# Some files (fp16-labeled ones especially) don't match the bf16 transformer's dtype; PEFT expects the
|
|
@@ -295,7 +301,7 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 295 |
network_alphas[f"{base}.alpha"] = float(out_tensor.shape[1])
|
| 296 |
for raw_base, alpha in raw_alphas.items():
|
| 297 |
for base in target_bases(raw_base):
|
| 298 |
-
network_alphas[f"{base}.alpha"] = alpha
|
| 299 |
|
| 300 |
return out, network_alphas
|
| 301 |
|
|
@@ -407,7 +413,7 @@ def load_models() -> str | None:
|
|
| 407 |
raw, base_shapes, swap_fc1=name in SWAP_FC1_NAMES
|
| 408 |
)
|
| 409 |
pipe.transformer.load_lora_adapter(
|
| 410 |
-
converted, adapter_name=name, prefix=
|
| 411 |
)
|
| 412 |
# `load_lora_adapter` warns-and-continues on a zero-key match instead of raising, so count
|
| 413 |
# matched layers ourselves and fail loudly if a file attached nothing.
|
|
|
|
| 159 |
|
| 160 |
MiniMaxH3ModularPipeline.min_duration = property(lambda self: float(seconds))
|
| 161 |
|
| 162 |
+
# `load_lora_adapter` requires every key (weights and `network_alphas` alike) to share a `prefix` whenever
|
| 163 |
+
# `network_alphas` is passed — `prefix=None` with a non-empty `network_alphas` is a hard error. This string is
|
| 164 |
+
# arbitrary (it's stripped off immediately, and the transformer itself has no `transformer.`-prefixed attribute)
|
| 165 |
+
# but has to match InstantX's own convention since it's just a filtering key, not a real path.
|
| 166 |
+
LORA_KEY_PREFIX = "transformer"
|
| 167 |
+
|
| 168 |
def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool) -> tuple[dict, dict]:
|
| 169 |
"""Rename a `diffusion_model.blocks.*` (original-checkpoint) LoRA state dict onto
|
| 170 |
`MiniMaxH3Transformer3DModel`'s (`transformer_blocks.*`) naming, so `load_lora_adapter` can attach it.
|
|
|
|
| 232 |
prefix = rename_base(raw_base[: -len("attn.qkv_proj")])
|
| 233 |
if ab == "lora_A":
|
| 234 |
# Shared low-rank input side — identical for q, k, v.
|
| 235 |
+
out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_q.{ab}.weight"] = tensor
|
| 236 |
+
out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_k.{ab}.weight"] = tensor
|
| 237 |
+
out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_v.{ab}.weight"] = tensor
|
| 238 |
else:
|
| 239 |
q_out = base_shapes[f"{prefix}attn.to_q.weight"][0]
|
| 240 |
k_out = base_shapes[f"{prefix}attn.to_k.weight"][0]
|
|
|
|
| 243 |
f"{raw_base}.{ab}: expected {q_out + k_out + v_out} rows "
|
| 244 |
f"(q{q_out}+k{k_out}+v{v_out}), got {tensor.shape[0]}"
|
| 245 |
)
|
| 246 |
+
out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_q.{ab}.weight"] = tensor[:q_out].clone()
|
| 247 |
+
out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_k.{ab}.weight"] = tensor[q_out:q_out + k_out].clone()
|
| 248 |
+
out[f"{LORA_KEY_PREFIX}.{prefix}attn.to_v.{ab}.weight"] = tensor[q_out + k_out:].clone()
|
| 249 |
return
|
| 250 |
|
| 251 |
if raw_base.endswith(".mlp.fc1") and ab == "lora_B" and swap_fc1:
|
|
|
|
| 259 |
# checks against a fixed whitelist of known `kind`s the way the old anchored regex did.
|
| 260 |
print(f"[lora-convert] '{raw_base}' renamed to '{key_base}', which isn't a real target — skipping", flush=True)
|
| 261 |
return
|
| 262 |
+
out[f"{LORA_KEY_PREFIX}.{key_base}.{ab}.weight"] = tensor
|
| 263 |
|
| 264 |
for key, raw_tensor in raw.items():
|
| 265 |
# Some files (fp16-labeled ones especially) don't match the bf16 transformer's dtype; PEFT expects the
|
|
|
|
| 301 |
network_alphas[f"{base}.alpha"] = float(out_tensor.shape[1])
|
| 302 |
for raw_base, alpha in raw_alphas.items():
|
| 303 |
for base in target_bases(raw_base):
|
| 304 |
+
network_alphas[f"{LORA_KEY_PREFIX}.{base}.alpha"] = alpha
|
| 305 |
|
| 306 |
return out, network_alphas
|
| 307 |
|
|
|
|
| 413 |
raw, base_shapes, swap_fc1=name in SWAP_FC1_NAMES
|
| 414 |
)
|
| 415 |
pipe.transformer.load_lora_adapter(
|
| 416 |
+
converted, adapter_name=name, prefix=LORA_KEY_PREFIX, network_alphas=network_alphas
|
| 417 |
)
|
| 418 |
# `load_lora_adapter` warns-and-continues on a zero-key match instead of raising, so count
|
| 419 |
# matched layers ourselves and fail loudly if a file attached nothing.
|