Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,8 +41,10 @@ LORA_REPO = os.environ.get("H3_LORA_REPO", "dagloop5/LoRA")
|
|
| 41 |
# A finetuned transformer, as a single monolithic safetensors file rather than MODEL_REPO's own sharded
|
| 42 |
# `transformer/` subfolder — everything else (VAE, schedulers, config) still comes from MODEL_REPO. Empty by
|
| 43 |
# default, which reproduces the official weights exactly.
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
# Each entry is (repo, filename) so a LoRA can come from any repo, not just LORA_REPO — the two Lightx2v files
|
| 47 |
# live in lightx2v/Minimax-h3-Turbo, not dagloop5/LoRA.
|
| 48 |
LORA_FILES = {
|
|
@@ -395,31 +397,19 @@ def load_models() -> str | None:
|
|
| 395 |
pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")
|
| 396 |
|
| 397 |
if CUSTOM_TRANSFORMER_REPO:
|
| 398 |
-
#
|
| 399 |
-
#
|
| 400 |
-
# the architecture exists with no real memory behind it yet, then `load_state_dict(assign=True)`
|
| 401 |
-
# materializes real tensors directly from the finetune's own state dict — the only real allocation
|
| 402 |
-
# in this path, and it happens exactly once, for the weights actually being kept.
|
| 403 |
#
|
| 404 |
# Setting `pipe.transformer` here, before `load_components()` runs, is what makes `load_components()`
|
| 405 |
-
# skip fetching
|
| 406 |
-
# `getattr(self, name, None) is None`.
|
| 407 |
-
from huggingface_hub import hf_hub_download
|
| 408 |
-
from safetensors.torch import load_file
|
| 409 |
-
|
| 410 |
from diffusers.models import MiniMaxH3Transformer3DModel
|
| 411 |
|
| 412 |
-
|
| 413 |
-
|
| 414 |
)
|
| 415 |
-
with torch.device("meta"):
|
| 416 |
-
custom_transformer = MiniMaxH3Transformer3DModel.from_config(config)
|
| 417 |
-
custom_path = hf_hub_download(CUSTOM_TRANSFORMER_REPO, CUSTOM_TRANSFORMER_FILE)
|
| 418 |
-
# `strict=True`: a finetune with a genuinely different key set is a real architecture mismatch, not
|
| 419 |
-
# something to load partially and hope for the best on.
|
| 420 |
-
custom_transformer.load_state_dict(load_file(custom_path), strict=True, assign=True)
|
| 421 |
pipe.update_components(transformer=custom_transformer)
|
| 422 |
-
print(f"[gen] transformer replaced with {CUSTOM_TRANSFORMER_REPO}
|
| 423 |
|
| 424 |
pipe.load_components(dtype=torch.bfloat16)
|
| 425 |
pipe.transformer.set_attention_backend(ATTENTION)
|
|
|
|
| 41 |
# A finetuned transformer, as a single monolithic safetensors file rather than MODEL_REPO's own sharded
|
| 42 |
# `transformer/` subfolder — everything else (VAE, schedulers, config) still comes from MODEL_REPO. Empty by
|
| 43 |
# default, which reproduces the official weights exactly.
|
| 44 |
+
# A proper diffusers-native, sharded transformer checkpoint (its own `config.json` +
|
| 45 |
+
# `diffusion_pytorch_model-*-of-*.safetensors` + index, at the repo root) — everything else (VAE, schedulers,
|
| 46 |
+
# config) still comes from MODEL_REPO. Empty by default, which reproduces the official weights exactly.
|
| 47 |
+
CUSTOM_TRANSFORMER_REPO = os.environ.get("H3_CUSTOM_TRANSFORMER_REPO", "ibyteohdear/10Eros-Max-Transformer")
|
| 48 |
# Each entry is (repo, filename) so a LoRA can come from any repo, not just LORA_REPO — the two Lightx2v files
|
| 49 |
# live in lightx2v/Minimax-h3-Turbo, not dagloop5/LoRA.
|
| 50 |
LORA_FILES = {
|
|
|
|
| 397 |
pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")
|
| 398 |
|
| 399 |
if CUSTOM_TRANSFORMER_REPO:
|
| 400 |
+
# A real sharded diffusers repo, not a single file — `from_pretrained` handles shard resolution and
|
| 401 |
+
# low-memory (meta-device-backed) loading itself, so nothing manual is needed here.
|
|
|
|
|
|
|
|
|
|
| 402 |
#
|
| 403 |
# Setting `pipe.transformer` here, before `load_components()` runs, is what makes `load_components()`
|
| 404 |
+
# skip fetching the official transformer entirely: its own `names=None` branch only loads components
|
| 405 |
+
# where `getattr(self, name, None) is None`.
|
|
|
|
|
|
|
|
|
|
| 406 |
from diffusers.models import MiniMaxH3Transformer3DModel
|
| 407 |
|
| 408 |
+
custom_transformer = MiniMaxH3Transformer3DModel.from_pretrained(
|
| 409 |
+
CUSTOM_TRANSFORMER_REPO, torch_dtype=torch.bfloat16
|
| 410 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
pipe.update_components(transformer=custom_transformer)
|
| 412 |
+
print(f"[gen] transformer replaced with {CUSTOM_TRANSFORMER_REPO}", flush=True)
|
| 413 |
|
| 414 |
pipe.load_components(dtype=torch.bfloat16)
|
| 415 |
pipe.transformer.set_attention_backend(ATTENTION)
|