Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,6 +37,16 @@ PLACEMENT = os.environ.get("H3_PLACEMENT", "pack").lower()
|
|
| 37 |
ATTENTION = os.environ.get("H3_ATTENTION", "_native_cudnn").lower()
|
| 38 |
GPU_SIZE = os.environ.get("H3_GPU_SIZE", "xlarge")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
LORA_REPO = os.environ.get("H3_LORA_REPO", "dagloop5/LoRA")
|
| 41 |
# Each entry is (repo, filename) so a LoRA can come from any repo, not just LORA_REPO — the two Lightx2v files
|
| 42 |
# live in lightx2v/Minimax-h3-Turbo, not dagloop5/LoRA.
|
|
@@ -423,6 +433,27 @@ def load_models() -> str | None:
|
|
| 423 |
blocks = MiniMaxH3GeneratorBlocks()
|
| 424 |
print(f"[gen] loading {[c.name for c in blocks.expected_components]} from {MODEL_REPO} ...", flush=True)
|
| 425 |
pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
pipe.load_components(dtype=torch.bfloat16)
|
| 427 |
pipe.transformer.set_attention_backend(ATTENTION)
|
| 428 |
|
|
|
|
| 37 |
ATTENTION = os.environ.get("H3_ATTENTION", "_native_cudnn").lower()
|
| 38 |
GPU_SIZE = os.environ.get("H3_GPU_SIZE", "xlarge")
|
| 39 |
|
| 40 |
+
# A finetuned transformer, as a single monolithic safetensors file rather than MODEL_REPO's own sharded
|
| 41 |
+
# `transformer/` subfolder — everything else (VAE, schedulers, config) still comes from MODEL_REPO. Empty by
|
| 42 |
+
# default, which reproduces the official weights exactly. Confirmed diffusers-native key naming (not ComfyUI,
|
| 43 |
+
# not pruned-AdaLN) via `xal2077/PinkCherry_MiniMax-H3-Demo`'s own working `load_state_dict(strict=True)` call
|
| 44 |
+
# against an earlier release of the same lineage.
|
| 45 |
+
CUSTOM_TRANSFORMER_REPO = os.environ.get("H3_CUSTOM_TRANSFORMER_REPO", "coeboy/PinkCherry_MiniMax-H3")
|
| 46 |
+
CUSTOM_TRANSFORMER_FILE = os.environ.get(
|
| 47 |
+
"H3_CUSTOM_TRANSFORMER_FILE", "v1-final-fl2va/PinkCherry_v1_bf16_fla2va_H3.safetensors"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
LORA_REPO = os.environ.get("H3_LORA_REPO", "dagloop5/LoRA")
|
| 51 |
# Each entry is (repo, filename) so a LoRA can come from any repo, not just LORA_REPO — the two Lightx2v files
|
| 52 |
# live in lightx2v/Minimax-h3-Turbo, not dagloop5/LoRA.
|
|
|
|
| 433 |
blocks = MiniMaxH3GeneratorBlocks()
|
| 434 |
print(f"[gen] loading {[c.name for c in blocks.expected_components]} from {MODEL_REPO} ...", flush=True)
|
| 435 |
pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")
|
| 436 |
+
|
| 437 |
+
if CUSTOM_TRANSFORMER_REPO:
|
| 438 |
+
# `load_config` fetches only `transformer/config.json` (a few KB) — not the 61.7 GiB of weights
|
| 439 |
+
# `load_components` would otherwise pull from MODEL_REPO. Constructed on `torch.device("meta")` so
|
| 440 |
+
# the architecture exists with no real memory behind it, then `load_state_dict(assign=True)`
|
| 441 |
+
# materializes real tensors straight from the finetune's own file — the only real allocation here.
|
| 442 |
+
from huggingface_hub import hf_hub_download
|
| 443 |
+
from safetensors.torch import load_file
|
| 444 |
+
|
| 445 |
+
from diffusers.models import MiniMaxH3Transformer3DModel
|
| 446 |
+
|
| 447 |
+
config, _ = MiniMaxH3Transformer3DModel.load_config(
|
| 448 |
+
MODEL_REPO, subfolder="transformer", return_unused_kwargs=True
|
| 449 |
+
)
|
| 450 |
+
with torch.device("meta"):
|
| 451 |
+
custom_transformer = MiniMaxH3Transformer3DModel.from_config(config)
|
| 452 |
+
custom_path = hf_hub_download(CUSTOM_TRANSFORMER_REPO, CUSTOM_TRANSFORMER_FILE)
|
| 453 |
+
custom_transformer.load_state_dict(load_file(custom_path), strict=True, assign=True)
|
| 454 |
+
pipe.update_components(transformer=custom_transformer)
|
| 455 |
+
print(f"[gen] transformer replaced with {CUSTOM_TRANSFORMER_REPO}/{CUSTOM_TRANSFORMER_FILE}", flush=True)
|
| 456 |
+
|
| 457 |
pipe.load_components(dtype=torch.bfloat16)
|
| 458 |
pipe.transformer.set_attention_backend(ATTENTION)
|
| 459 |
|