linoyts HF Staff commited on
Commit
51b541a
·
verified ·
1 Parent(s): f66e612

README: verified usage (cross-repo transformer load, turbo prefix, device move)

Browse files
Files changed (1) hide show
  1. README.md +29 -9
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 diffusers import ComponentsManager
 
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
- # optional: lightx2v 4-step Ref2V Turbo LoRA (on the transformer; independent of the VAE)
60
- pipe.load_lora_weights(
61
- hf_hub_download("lightx2v/Minimax-h3-Turbo", "minimax_h3_ref2v_turbo_4step_v0.1_bf16.safetensors"),
62
- adapter_name="turbo",
63
- )
64
- pipe.set_adapters(["turbo"], [1.0])
 
 
 
 
 
65
 
66
  state = pipe(
67
  prompt="a red fox walking through snow, cinematic",
68
  references=[MiniMaxH3VideoReference.from_file("reference.mp4")],
69
- height=448,
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