Instructions to use diffusers-modular/MiniMax-H3-LightVAE with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use diffusers-modular/MiniMax-H3-LightVAE with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image, export_to_video # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("diffusers-modular/MiniMax-H3-LightVAE", dtype=torch.bfloat16, device_map="cuda") pipe.to("cuda") prompt = "A man with short gray hair plays a red electric guitar." image = load_image( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png" ) output = pipe(image=image, prompt=prompt).frames[0] export_to_video(output, "output.mp4") - Notebooks
- Google Colab
- Kaggle
README: verified usage (cross-repo transformer load, turbo prefix, device move)
Browse files
README.md
CHANGED
|
@@ -36,10 +36,17 @@ vae/ # AutoencoderKLMiniMaxH3, decoder_num_layers=12 (st
|
|
| 36 |
|
| 37 |
Requires `diffusers` with the MiniMax-H3 integration.
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
```python
|
| 40 |
import torch
|
| 41 |
from huggingface_hub import hf_hub_download
|
| 42 |
-
from
|
|
|
|
| 43 |
from diffusers.modular_pipelines.minimax_h3 import MiniMaxH3Blocks
|
| 44 |
from diffusers.modular_pipelines.minimax_h3.references import MiniMaxH3VideoReference
|
| 45 |
|
|
@@ -50,23 +57,36 @@ pipe = blocks.init_pipeline(
|
|
| 50 |
components_manager=ComponentsManager(),
|
| 51 |
collection="h3",
|
| 52 |
)
|
| 53 |
-
pipe.load_components(dtype=torch.bfloat16, trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# both autoencoders stay fp32 on the native attention backend
|
| 56 |
pipe.vae.set_attention_backend("native")
|
| 57 |
pipe.audio_vae.set_attention_backend("native")
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
)
|
| 64 |
-
pipe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
state = pipe(
|
| 67 |
prompt="a red fox walking through snow, cinematic",
|
| 68 |
references=[MiniMaxH3VideoReference.from_file("reference.mp4")],
|
| 69 |
-
height=
|
| 70 |
width=768,
|
| 71 |
num_frames=124, # must be 17*n + 5
|
| 72 |
num_inference_steps=4, # 4 with the Turbo LoRA; ~20 without
|
|
|
|
| 36 |
|
| 37 |
Requires `diffusers` with the MiniMax-H3 integration.
|
| 38 |
|
| 39 |
+
Two things to know up front, both inherent to a stand-alone modular index (verified on a live Space):
|
| 40 |
+
1. The LightVAE `vae` loads automatically from this repo. The **pruned transformer is remote code in a different
|
| 41 |
+
repo**, and `trust_remote_code` is only forwarded to components that live in this index's own repo, so
|
| 42 |
+
`transformer_ref` has to be loaded explicitly and injected with `update_components`.
|
| 43 |
+
2. Components load on CPU; move the model components to the GPU before calling the pipeline.
|
| 44 |
+
|
| 45 |
```python
|
| 46 |
import torch
|
| 47 |
from huggingface_hub import hf_hub_download
|
| 48 |
+
from safetensors.torch import load_file
|
| 49 |
+
from diffusers import ComponentsManager, AutoModel
|
| 50 |
from diffusers.modular_pipelines.minimax_h3 import MiniMaxH3Blocks
|
| 51 |
from diffusers.modular_pipelines.minimax_h3.references import MiniMaxH3VideoReference
|
| 52 |
|
|
|
|
| 57 |
components_manager=ComponentsManager(),
|
| 58 |
collection="h3",
|
| 59 |
)
|
| 60 |
+
pipe.load_components(dtype=torch.bfloat16, trust_remote_code=True) # LightVAE `vae` loads here
|
| 61 |
+
|
| 62 |
+
# the remote-code pruned transformer lives in a different repo, so load + inject it explicitly
|
| 63 |
+
if getattr(pipe, "transformer_ref", None) is None:
|
| 64 |
+
transformer_ref = AutoModel.from_pretrained(
|
| 65 |
+
"multimodalart/MiniMax-H3-Pruned", subfolder="transformer_ref",
|
| 66 |
+
trust_remote_code=True, torch_dtype=torch.bfloat16,
|
| 67 |
+
)
|
| 68 |
+
pipe.update_components(transformer_ref=transformer_ref)
|
| 69 |
|
| 70 |
# both autoencoders stay fp32 on the native attention backend
|
| 71 |
pipe.vae.set_attention_backend("native")
|
| 72 |
pipe.audio_vae.set_attention_backend("native")
|
| 73 |
|
| 74 |
+
# lightx2v 4-step Ref2V Turbo LoRA. Its keys target the transformer submodules with no `transformer.` prefix,
|
| 75 |
+
# so load it onto the component with prefix=None (and drop the PEFT `.default.` adapter segment from the keys).
|
| 76 |
+
turbo = load_file(hf_hub_download("lightx2v/Minimax-h3-Turbo", "minimax_h3_ref2v_turbo_4step_v0.1_bf16.safetensors"))
|
| 77 |
+
turbo = {k.replace(".lora_A.default.weight", ".lora_A.weight").replace(".lora_B.default.weight", ".lora_B.weight"): v
|
| 78 |
+
for k, v in turbo.items()}
|
| 79 |
+
pipe.transformer_ref.load_lora_adapter(turbo, prefix=None, adapter_name="turbo")
|
| 80 |
+
pipe.transformer_ref.set_adapters(["turbo"], [1.0])
|
| 81 |
+
|
| 82 |
+
# components load on CPU; move the models to the GPU (VAEs keep fp32)
|
| 83 |
+
for name in ("transformer_ref", "vae", "audio_vae"):
|
| 84 |
+
getattr(pipe, name).to("cuda")
|
| 85 |
|
| 86 |
state = pipe(
|
| 87 |
prompt="a red fox walking through snow, cinematic",
|
| 88 |
references=[MiniMaxH3VideoReference.from_file("reference.mp4")],
|
| 89 |
+
height=768,
|
| 90 |
width=768,
|
| 91 |
num_frames=124, # must be 17*n + 5
|
| 92 |
num_inference_steps=4, # 4 with the Turbo LoRA; ~20 without
|